This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15559] Method call and calling convention


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

--- Comment #6 from asmwarrior <asmwarrior at gmail dot com> ---
OK, the tiny patch can fix this issue, note this is only for GCC under Windows,
the GCC version should be 4.7.x or later, comments are welcome.

See below:

 gdb/i386-tdep.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index b159b49..db160ba 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2408,6 +2408,20 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct
value *function,
   int i;
   int write_pass;
   int args_space = 0;
+  struct type *func_type = value_type (function);
+  int i386_windows_thiscall = 0;
+
+  if (func_type)
+    {
+      if( (TYPE_CODE (func_type) == TYPE_CODE_METHOD) && (nargs > 0))
+        {
+         /* a.f(5,6);
+            args[0] = this pointer;
+            args[1] = 5;
+            args[2] = 6; */
+         i386_windows_thiscall = 1;
+        }
+    }

   /* Determine the total space required for arguments and struct
      return address in a first pass (allowing for 16-byte-aligned
@@ -2430,7 +2444,7 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct
value *function,
         args_space += 4;
     }

-      for (i = 0; i < nargs; i++)
+      for (i = i386_windows_thiscall; i < nargs; i++)
     {
       int len = TYPE_LENGTH (value_enclosing_type (args[i]));

@@ -2482,6 +2496,12 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct
value *function,
   /* ...and fake a frame pointer.  */
   regcache_cooked_write (regcache, I386_EBP_REGNUM, buf);

+  if (i386_windows_thiscall)
+    {
+      /* args[0] refer to the last argument which is the this pointer */
+      regcache_cooked_write (regcache, I386_ECX_REGNUM,
value_contents_all(args[0]));
+    }
+
   /* MarkK wrote: This "+ 8" is all over the place:
      (i386_frame_this_id, i386_sigtramp_frame_this_id,
      i386_dummy_id).  It's there, since all frame unwinders for

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]