Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Fwd: Method call and calling convention
       [not found] <CAB35Rs7t2fYrPunFA+Q_5tW1DxjxdgMLNxHoYNAOatxxwsc4dA@mail.gmail.com>
@ 2013-05-18 12:05 ` Kifa The Great
  2013-05-21 16:42   ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Kifa The Great @ 2013-05-18 12:05 UTC (permalink / raw)
  To: gdb, gcc-help

Hello!
I have faced a problem using GDB with GCC 4.8.0 x86 on Windows XP and
Ubuntu 12.04. 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.

Could you please tell me if this is a bug, feature or maybe I do
something wrong?

Thanks,
Petr

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/petr/QtCreator/_Test_gcc4.8/Debug/Test...done.
(gdb) break main
Breakpoint 1 at 0x80487fd: file /home/petr/QtCreator/Test/main.cpp, line 12.
(gdb) run
Starting program: /home/petr/QtCreator/_Test_gcc4.8/Debug/Test
Breakpoint 1, main () at /home/petr/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)


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

* Re: Fwd: Method call and calling convention
  2013-05-18 12:05 ` Fwd: Method call and calling convention Kifa The Great
@ 2013-05-21 16:42   ` Tom Tromey
  2013-05-21 18:31     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2013-05-21 16:42 UTC (permalink / raw)
  To: Kifa The Great; +Cc: gdb, gcc-help

>>>>> "Kifa" == Kifa The Great <kifathegreat@gmail.com> writes:

Kifa> Windows x86 targets are using the __thiscall calling
Kifa> convention for C++ class-member functions by default from GCC 4.7.

Kifa> Could you please tell me if this is a bug, feature or maybe I do
Kifa> something wrong?

It looks like a bug to me.
I have two suggestions --

Kifa> GNU gdb (GDB) 7.5.1-ubuntu

First, try a newer gdb.  Maybe the problem was already fixed.

Second, if that fails, please file a bug report in Bugzilla.

Tom


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

* Re: Fwd: Method call and calling convention
  2013-05-21 16:42   ` Tom Tromey
@ 2013-05-21 18:31     ` Tom Tromey
  2013-06-01 20:27       ` Kifa
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2013-05-21 18:31 UTC (permalink / raw)
  To: Kifa The Great; +Cc: gdb, gcc-help

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Kifa> Could you please tell me if this is a bug, feature or maybe I do
Kifa> something wrong?

Tom> It looks like a bug to me.

Kai pointed out that this wasn't totally clear.
What I meant was that the gdb behavior seems to be a bug.

Tom


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

* RE: Fwd: Method call and calling convention
  2013-05-21 18:31     ` Tom Tromey
@ 2013-06-01 20:27       ` Kifa
  0 siblings, 0 replies; 4+ messages in thread
From: Kifa @ 2013-06-01 20:27 UTC (permalink / raw)
  To: 'Tom Tromey'; +Cc: gdb, gcc-help

Thanks for helping!

Tom> First, try a newer gdb.  Maybe the problem was already fixed.
I have tried gdb 7.6 (latest release) and result is the same.

Tom> Second, if that fails, please file a bug report in Bugzilla.
Bug 15559

Kifa


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

end of thread, other threads:[~2013-06-01 20:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAB35Rs7t2fYrPunFA+Q_5tW1DxjxdgMLNxHoYNAOatxxwsc4dA@mail.gmail.com>
2013-05-18 12:05 ` Fwd: Method call and calling convention Kifa The Great
2013-05-21 16:42   ` Tom Tromey
2013-05-21 18:31     ` Tom Tromey
2013-06-01 20:27       ` Kifa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox