public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15559] New: Method call and calling convention
@ 2013-06-01 19:48 kifathegreat at gmail dot com
  2013-10-05 14:32 ` [Bug c++/15559] " asmwarrior at gmail dot com
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: kifathegreat at gmail dot com @ 2013-06-01 19:48 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=15559

            Bug ID: 15559
           Summary: Method call and calling convention
           Product: gdb
           Version: 7.6
            Status: NEW
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: kifathegreat at gmail dot com

Hello!
I have faced a problem using GDB(7.5, 7.6) with GCC 4.8.0 x86 on Ubuntu 12.04
and Windows XP. Here is the issue description.

GDB has commands to call function from the program being debugged.
They are print and call. But unfortunately the mentioned above commands work
incorrectly for class methods with __thiscall calling convention. Windows x86
targets are using the __thiscall calling convention for C++ class-member
functions by default from GCC 4.7.
Judging by command return values GDB does not set object address (this
pointer) to ECX registry before method call. So these commands trigger for some
object only if last executed line of the program being debugged contains method
call for the same object. In this case ECX registry will contain necessary
address (this pointer). For methods with __cdecl calling convention print
(call) works perfectly.

Thanks,
Kifa

C++ program Test:

01:#include <iostream>
02:class Test
03:{
04:    public:
05:        Test(int value) : _value(value) {}
06:        int value() const __attribute__((thiscall)) { return _value; }
07:    private:
08:        int _value;
09:};
10:int main()
11:{
12:    Test test1(123);
13:    Test test2(456);
14:    int value1 = test1.value();
15:    int value2 = test2.value();
16:    std::cout << value1 + value2 << std::endl;
17:    return 0;
18:}

GDB session:

GNU gdb (GDB) 7.5.1-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) file Test
Reading symbols from /home/kifa/QtCreator/_Test_gcc4.8/Debug/Test...done.
(gdb) break main
Breakpoint 1 at 0x80487fd: file /home/kifa/QtCreator/Test/main.cpp, line 12.
(gdb) run
Starting program: /home/kifa/QtCreator/_Test_gcc4.8/Debug/Test
Breakpoint 1, main () at /home/kifa/QtCreator/Test/main.cpp:12
12     Test test1(123);
(gdb) next
13     Test test2(456);
(gdb) print test1.value()
$1 = -11264
(gdb) next
14     int value1 = test1.value();
(gdb) print test1.value()
$2 = -11264
(gdb) next
15     int value2 = test2.value();
(gdb) print test1.value()
$3 = 123
(gdb) next
16     std::cout << value1 + value2 << std::endl;
(gdb) print test1.value()
$4 = 456
(gdb) next
579
17     return 0;
(gdb) print test1.value()
$5 = 0
(gdb) continue
Continuing.
[Inferior 1 (process 4180) exited normally]
(gdb)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2020-04-30 14:57 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-01 19:48 [Bug c++/15559] New: Method call and calling convention kifathegreat at gmail dot com
2013-10-05 14:32 ` [Bug c++/15559] " asmwarrior at gmail dot com
2013-10-05 14:55 ` asmwarrior at gmail dot com
2013-10-05 15:46 ` asmwarrior at gmail dot com
2013-10-08  4:01 ` asmwarrior at gmail dot com
2013-10-08  6:19 ` asmwarrior at gmail dot com
2013-10-08 11:13 ` asmwarrior at gmail dot com
2013-10-08 13:13 ` xunxun1982 at gmail dot com
2013-10-08 15:28 ` asmwarrior at gmail dot com
2013-10-09  6:59 ` asmwarrior at gmail dot com
2013-12-09 15:15 ` i.nixman at gmail dot com
2013-12-10  7:14 ` i.nixman at autistici dot org
2013-12-10  7:59 ` asmwarrior at gmail dot com
2014-02-25 11:20 ` ssbssa at yahoo dot de
2014-02-25 20:12 ` ssbssa at yahoo dot de
2014-02-26  4:28 ` asmwarrior at gmail dot com
2014-02-26 20:24 ` ssbssa at yahoo dot de
2014-02-27 15:22 ` asmwarrior at gmail dot com
2014-02-27 19:02 ` ssbssa at yahoo dot de
2014-03-01 14:23 ` asmwarrior at gmail dot com
2014-03-01 14:29 ` asmwarrior at gmail dot com
2014-03-26 14:32 ` julian at codesourcery dot com
2020-04-30 12:37 ` cvs-commit at gcc dot gnu.org
2020-04-30 12:38 ` ssbssa at sourceware dot org
2020-04-30 14:57 ` asmwarrior at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).