From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic313-20.consmr.mail.ir2.yahoo.com (sonic313-20.consmr.mail.ir2.yahoo.com [77.238.179.187]) by sourceware.org (Postfix) with ESMTPS id 36E7A3959C39 for ; Wed, 29 Apr 2020 13:48:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 36E7A3959C39 X-YMail-OSG: jAKPFbYVM1k8tALI3qg2vY11G7pa1HJTIn7pYwadyj2GTXImnadZK3AYRjRd3Zc FViBD8qbdAuJ1Y16KXKP42kE9Undm46SWLJtRve0r1ibUF_hquc_qbxtU6zVpQfSpmxslLC9g1Sf nWmRB.ajc6QEmvLbw0fsjWTPD.mI1CyeW8lVW9ruwje5vDpn31FcWurVpFhXZE.rjl033.TsiD0C k29ZOtftGg58NipLCn0Il1DWDEM.CCJVaOLW_gXtunUltLIDFpBaR1Rk.gs0TwnzITMuvyw1gNDF v6P5EnM6p.5Azsy5KxbancXjG225nIcPyUXMXi0TlJfKH4tfv4G27I0jnnpOB0P9rdh9cKOr6rio EpDM1u4OJFDPuk3Halq0xD9jE_jNh5T1p8kZznL5yCfLyNglcwOyVQG5fPEhtxd8pe6Kof_Ch59Z 5S6nzoVE4DYmtc4JndDXxHGnmdcsQAvMskiw4DE_4LHOd7XR3rlvb91s0fjR7oh2S3Jx1v_5Nbmt vidaqum1BiQqcG75VyaZ3W0FTBYmMwo6DZXAJXLOl06EJy7XQXJ60xESoN1QtM6FIJMpjW_Ewvs8 VcC0cO1HLSwnMihTvuqLxQbJhHtbNfkW0x.BxIX9onCz7s4Ws45nSGLfKzNgX4qGsU7tFX.OSYzv uc94tkbJK8I.SU9T5JLYQtAy2ref13BABXg9g9GRoQzRmR230u0o6vDLxG.NjRjeBre2OP40b1mV PtYWAC9DzYiAIR6QsCUeN8HDWM61U89clPzvR125bzuGfobDVey1.q033Q8.KJCL5w9dBhRrkWmB .bgevujVEBuhuIgiW9IyFvm3n9sLB4h2.2o_MDQKwWXOVwr9cq09UuWWwCcaBgxNJ8v9..3ynf4i 4oQOrm5.oXVORUGeIaT5ld9KrhG9.pGghCHQEXJzctYiCmIvItpK9uWAgzZN3s25mYJ_N.liTMXR ST5vHQnLuE1LEKYC96LOGmg2u5EjtPc.BbZjFUczt6FOjKnLZWaV81WGUbBNAF9jNfabEZ5i_pgM i0JBPtWNUKTFY3dGrxvGJTbjBtUMwO971oHhOlWHyU6Tw0.EmnUmsr_K_itZthDpqOgG5hK_2IWo mmpr.iNB4on91.Xj4klqtjHpbRUflhWyWbaVmwLN.tBKCfeBgKV3Vf64fFx0RLbt5usyiiKA7vIv OheOHja14uLMl9a_FED43129O4fgLX_vi0MQBtoR1IMeqm8kcQKlSBTzMT7TC80zuVhEy5H76m3W .nWdxY4AoVimRB6NziLQXkgyQnPPVdynKu5Dqad8ipiWupWhzYZKsskrBCpIegc26hHrK_47dKEv hPRqGBqaBivkiPnPMa27gZpSUvMfyXuuEcal4ScfTOq2bQt77OSIOstbBObC9aFZyd9HrTcrQkIQ YRfd48shQNzwEAIc9V_oEO5s- Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Wed, 29 Apr 2020 13:48:41 +0000 Received: by smtp409.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID df1b9e48a78b60f7a9718af437184986; Wed, 29 Apr 2020 13:48:39 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH v3][PR gdb/15559] Use thiscall calling convention for class members Date: Wed, 29 Apr 2020 15:48:08 +0200 Message-Id: <20200429134808.3642-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 200428-4, 04/28/2020), Outbound message X-Antivirus-Status: Clean References: <20200429134808.3642-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-18.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Apr 2020 13:48:44 -0000 Non-static member functions for Windows 32bit programs need the thiscall calling convention, so the 'this' pointer needs to be passed in ECX. gdb/ChangeLog: 2020-04-29 Hannes Domani PR gdb/15559 * i386-tdep.c (i386_push_dummy_call): Call i386_thiscall_push_dummy_call. (i386_thiscall_push_dummy_call): New function. * i386-tdep.h (i386_thiscall_push_dummy_call): Declare. * i386-windows-tdep.c (i386_windows_push_dummy_call): New function. (i386_windows_init_abi): Call set_gdbarch_push_dummy_call. --- v2: - Now only code by me is left. v3: - Refactored the OSABI_WINDOWS stuff into a i386-windows-tdep.c function, but I'm not 100% sure that I did it how Simon meant it. --- gdb/i386-tdep.c | 35 ++++++++++++++++++++++++++++------- gdb/i386-tdep.h | 13 +++++++++++++ gdb/i386-windows-tdep.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 84edb3649e..fc63635317 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -2668,12 +2668,15 @@ i386_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr, return sp - 16; } -static CORE_ADDR -i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function, - struct regcache *regcache, CORE_ADDR bp_addr, int nargs, - struct value **args, CORE_ADDR sp, - function_call_return_method return_method, - CORE_ADDR struct_addr) +/* The "push_dummy_call" gdbarch method, optionally with the thiscall + calling convention. */ + +CORE_ADDR +i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function, + struct regcache *regcache, CORE_ADDR bp_addr, + int nargs, struct value **args, CORE_ADDR sp, + function_call_return_method return_method, + CORE_ADDR struct_addr, bool thiscall) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); gdb_byte buf[4]; @@ -2709,7 +2712,7 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function, args_space += 4; } - for (i = 0; i < nargs; i++) + for (i = thiscall ? 1 : 0; i < nargs; i++) { int len = TYPE_LENGTH (value_enclosing_type (args[i])); @@ -2761,6 +2764,10 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* ...and fake a frame pointer. */ regcache->cooked_write (I386_EBP_REGNUM, buf); + /* The 'this' pointer needs to be in ECX. */ + if (thiscall) + regcache->cooked_write (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 @@ -2773,6 +2780,20 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function, return sp + 8; } +/* Implement the "push_dummy_call" gdbarch method. */ + +static CORE_ADDR +i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function, + struct regcache *regcache, CORE_ADDR bp_addr, int nargs, + struct value **args, CORE_ADDR sp, + function_call_return_method return_method, + CORE_ADDR struct_addr) +{ + return i386_thiscall_push_dummy_call (gdbarch, function, regcache, bp_addr, + nargs, args, sp, return_method, + struct_addr, false); +} + /* These registers are used for returning integers (and on some targets also for returning `struct' and `union' values when their size and alignment match an integer type). */ diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h index fa29e316a1..79b3b1f942 100644 --- a/gdb/i386-tdep.h +++ b/gdb/i386-tdep.h @@ -399,6 +399,19 @@ extern CORE_ADDR i386_pe_skip_trampoline_code (struct frame_info *frame, extern CORE_ADDR i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc); +/* The "push_dummy_call" gdbarch method, optionally with the thiscall + calling convention. */ +extern CORE_ADDR i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, + struct value *function, + struct regcache *regcache, + CORE_ADDR bp_addr, + int nargs, struct value **args, + CORE_ADDR sp, + function_call_return_method + return_method, + CORE_ADDR struct_addr, + bool thiscall); + /* Return whether the THIS_FRAME corresponds to a sigtramp routine. */ extern int i386_sigtramp_p (struct frame_info *this_frame); diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c index 3a07c862f2..4824a9e552 100644 --- a/gdb/i386-windows-tdep.c +++ b/gdb/i386-windows-tdep.c @@ -200,6 +200,36 @@ i386_windows_auto_wide_charset (void) return "UTF-16"; } +/* Implement the "push_dummy_call" gdbarch method. */ + +static CORE_ADDR +i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function, + struct regcache *regcache, CORE_ADDR bp_addr, + int nargs, struct value **args, CORE_ADDR sp, + function_call_return_method return_method, + CORE_ADDR struct_addr) +{ + /* For non-static member functions of 32bit Windows programs, the thiscall + calling convention is used, so the 'this' pointer is passed in ECX. */ + bool thiscall = false; + + struct type *type = check_typedef (value_type (function)); + if (TYPE_CODE (type) == TYPE_CODE_PTR) + type = check_typedef (TYPE_TARGET_TYPE (type)); + + /* read_subroutine_type sets for non-static member functions the + artificial flag of the first parameter ('this' pointer). */ + if (TYPE_CODE (type) == TYPE_CODE_METHOD + && TYPE_NFIELDS (type) > 0 + && TYPE_FIELD_ARTIFICIAL (type, 0) + && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR) + thiscall = 1; + + return i386_thiscall_push_dummy_call (gdbarch, function, regcache, bp_addr, + nargs, args, sp, return_method, + struct_addr, thiscall); +} + /* Common parts for gdbarch initialization for Windows and Cygwin on i386. */ static void @@ -234,6 +264,8 @@ i386_windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { i386_windows_init_abi_common (info, gdbarch); windows_init_abi (info, gdbarch); + + set_gdbarch_push_dummy_call (gdbarch, i386_windows_push_dummy_call); } /* gdbarch initialization for Cygwin on i386. */ -- 2.26.2