From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110896 invoked by alias); 8 Feb 2020 16:37:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 110887 invoked by uid 89); 8 Feb 2020 16:37:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*UA:1.1.15199, H*x:1.1.15199, H*x:5.0 X-HELO: sonic313-20.consmr.mail.ir2.yahoo.com Received: from sonic313-20.consmr.mail.ir2.yahoo.com (HELO sonic313-20.consmr.mail.ir2.yahoo.com) (77.238.179.187) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Feb 2020 16:37:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1581179827; bh=OF/EhPbZSRzbeSNcd9Zk4jDqrEoLzD1/iDnwENvxNPg=; h=Date:From:To:Subject:References:From:Subject; b=HKUuT1RlmuCbdiH7runkAYzavAsZjBhDG3ZGSOymhhtGWNo6i0X9HNMBQ/ryUP1IwVblPfkzUMtsCtPu2ZdXR3D2v/W97rhu8DYgxMhqlt3l03QJCcPp0DvbPC0YiIwL1SezWdhk7vkhWc7ZNynP6o7gXOwGyMCoB2o5ckpojwKZvqab7vqvEG/FoZRkSM6/0f5tp0U4Ea4cX5co7aA50bXkaVuqvKTDgFlnvFzfg0gv+N/4UYFilisvbFQicvYJB2samSKw31uyg/bv3rsZC97uck9u3kfIEpV8tJMtJZ8P6af/Et1Y99B6J8Nxn4Q29xXTbHaq/dGSe8zWC0vB6w== Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Sat, 8 Feb 2020 16:37:07 +0000 Date: Sat, 08 Feb 2020 16:37:00 -0000 From: "Hannes Domani via gdb-patches" Reply-To: Hannes Domani To: Gdb-patches Message-ID: <691075103.286431.1581179823782@mail.yahoo.com> Subject: [PING] [PATCH] Rebase executable to match relocated base address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable References: <691075103.286431.1581179823782.ref@mail.yahoo.com> X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00236.txt.bz2 Ping. Am Samstag, 25. Januar 2020, 17:47:19 MEZ hat Hannes Domani via gdb-patches= Folgendes geschrieben: > Compared to the [RFC], only Tom's noticed coding style problems were > fixed. > > binutils 2.34 will have an improved -dynamicbase (so far this only > worked with some workarounds for executables), so the rebasing problem > might get more relevant in the future. > > > Windows executables linked with -dynamicbase get a new base address > when loaded, which makes debugging impossible if the executable isn't > also rebased in gdb. > > The transfer of the new base address is done via a fake auxv entry, > so it's working with gdbserver as well. > > gdb/ChangeLog: > > 2020-01-25=C2=A0 Hannes Domani=C2=A0 > >=C2=A0=C2=A0=C2=A0=C2=A0 * windows-nat.c (windows_nat_target::get_windows_= debug_event): >=C2=A0=C2=A0=C2=A0=C2=A0 Set current_exec_base. >=C2=A0=C2=A0=C2=A0=C2=A0 (windows_xfer_auxv): New function. >=C2=A0=C2=A0=C2=A0=C2=A0 (windows_nat_target::xfer_partial): Call windows_= xfer_auxv. >=C2=A0=C2=A0=C2=A0=C2=A0 * windows-tdep.c (windows_solib_create_inferior_h= ook): New function. >=C2=A0=C2=A0=C2=A0=C2=A0 (windows_init_abi): Use windows_solib_create_infe= rior_hook. > > gdb/gdbserver/ChangeLog: > > 2020-01-25=C2=A0 Hannes Domani=C2=A0 > >=C2=A0=C2=A0=C2=A0=C2=A0 * win32-low.c (get_child_debug_event): Set curren= t_exec_base. >=C2=A0=C2=A0=C2=A0=C2=A0 (win32_read_auxv): New function. > --- > gdb/gdbserver/win32-low.c | 35 ++++++++++++++++++++++++++++++++++- > gdb/windows-nat.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 38 ++++++++= ++++++++++++++++++++++++++++++ > gdb/windows-tdep.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 20 +++++++= +++++++++++++ > 3 files changed, 92 insertions(+), 1 deletion(-) > > diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c > index 2c4a9b1074..2f6fe5785e 100644 > --- a/gdb/gdbserver/win32-low.c > +++ b/gdb/gdbserver/win32-low.c > @@ -75,6 +75,7 @@ static int attaching =3D 0; > static HANDLE current_process_handle =3D NULL; > static DWORD current_process_id =3D 0; > static DWORD main_thread_id =3D 0; > +static CORE_ADDR current_exec_base;=C2=A0=C2=A0=C2=A0 /* Executable base= address */ > static enum gdb_signal last_sig =3D GDB_SIGNAL_0; > > /* The current debug event from WaitForDebugEvent.=C2=A0 */ > @@ -1486,6 +1487,8 @@ get_child_debug_event (struct target_waitstatus *ou= rstatus) > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 current_process_handle =3D current_ev= ent.u.CreateProcessInfo.hProcess; >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 main_thread_id =3D current_event.dwTh= readId; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 current_exec_base > +=C2=A0=C2=A0=C2=A0 =3D (CORE_ADDR) current_event.u.CreateProcessInfo.lpB= aseOfImage; > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Add the main thread.=C2=A0 */ >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 child_add_thread (current_event.dwPro= cessId, > @@ -1713,6 +1716,36 @@ win32_request_interrupt (void) >=C2=A0=C2=A0 soft_interrupt_requested =3D 1; > } > > +/* Windows does not have auxv, but this creates a fake AT_ENTRY entry > +=C2=A0 which is the base address of the executable.=C2=A0 */ > + > +static int > +win32_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int l= en) > +{ > +=C2=A0 size_t buf[4]; > + > +=C2=A0 if (!myaddr) > +=C2=A0=C2=A0=C2=A0 return -1; > + > +=C2=A0 if (offset > sizeof (buf)) > +=C2=A0=C2=A0=C2=A0 return -1; > + > +=C2=A0 if (offset =3D=3D sizeof (buf)) > +=C2=A0=C2=A0=C2=A0 return 0; > + > +=C2=A0 if (offset + len > sizeof (buf)) > +=C2=A0=C2=A0=C2=A0 len =3D sizeof (buf) - offset; > + > +=C2=A0 buf[0] =3D 9; /* AT_ENTRY */ > +=C2=A0 buf[1] =3D current_exec_base; > +=C2=A0 buf[2] =3D 0; /* AT_NULL */ > +=C2=A0 buf[3] =3D 0; > + > +=C2=A0 memcpy (myaddr, (char *) buf + offset, len); > + > +=C2=A0 return len; > +} > + > #ifdef _WIN32_WCE > int > win32_error_to_fileio_error (DWORD err) > @@ -1814,7 +1847,7 @@ static process_stratum_target win32_target_ops =3D { >=C2=A0=C2=A0 win32_write_inferior_memory, >=C2=A0=C2=A0 NULL, /* lookup_symbols */ >=C2=A0=C2=A0 win32_request_interrupt, > -=C2=A0 NULL, /* read_auxv */ > +=C2=A0 win32_read_auxv, >=C2=A0=C2=A0 win32_supports_z_point_type, >=C2=A0=C2=A0 win32_insert_point, >=C2=A0=C2=A0 win32_remove_point, > diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c > index 366c98fbf3..459bb10fe9 100644 > --- a/gdb/windows-nat.c > +++ b/gdb/windows-nat.c > @@ -236,6 +236,7 @@ static DEBUG_EVENT current_event;=C2=A0=C2=A0=C2=A0 /= * The current debug event from >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 WaitForDebugEv= ent */ > static HANDLE current_process_handle;=C2=A0=C2=A0=C2=A0 /* Currently exec= uting process */ > static windows_thread_info *current_thread;=C2=A0=C2=A0=C2=A0 /* Info on = currently selected thread */ > +static CORE_ADDR current_exec_base;=C2=A0=C2=A0=C2=A0 /* Executable base= address */ > > /* Counts of things.=C2=A0 */ > static int exception_count =3D 0; > @@ -1604,6 +1605,8 @@ windows_nat_target::get_windows_debug_event (int pi= d, >=C2=A0=C2=A0=C2=A0=C2=A0 break; > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 current_process_handle =3D current_ev= ent.u.CreateProcessInfo.hProcess; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 current_exec_base > +=C2=A0=C2=A0=C2=A0 =3D (CORE_ADDR) current_event.u.CreateProcessInfo.lpB= aseOfImage; >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Add the main thread.=C2=A0 */ >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 th =3D windows_add_thread >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (ptid_t (current_event.dw= ProcessId, 0, > @@ -2996,6 +2999,38 @@ windows_xfer_shared_libraries (struct target_ops *= ops, >=C2=A0=C2=A0 return len !=3D 0 ? TARGET_XFER_OK : TARGET_XFER_EOF; > } > > +/* Windows does not have auxv, but this creates a fake AT_ENTRY entry > +=C2=A0 which is the base address of the executable.=C2=A0 */ > + > +static enum target_xfer_status > +windows_xfer_auxv (gdb_byte *readbuf, ULONGEST offset, ULONGEST len, > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ULONGEST *xfered_= len) > +{ > +=C2=A0 CORE_ADDR buf[4]; > + > +=C2=A0 if (!readbuf) > +=C2=A0=C2=A0=C2=A0 return TARGET_XFER_E_IO; > + > +=C2=A0 if (offset > sizeof (buf)) > +=C2=A0=C2=A0=C2=A0 return TARGET_XFER_E_IO; > + > +=C2=A0 if (offset =3D=3D sizeof (buf)) > +=C2=A0=C2=A0=C2=A0 return TARGET_XFER_EOF; > + > +=C2=A0 if (offset + len > sizeof (buf)) > +=C2=A0=C2=A0=C2=A0 len =3D sizeof (buf) - offset; > + > +=C2=A0 buf[0] =3D 9; /* AT_ENTRY */ > +=C2=A0 buf[1] =3D current_exec_base; > +=C2=A0 buf[2] =3D 0; /* AT_NULL */ > +=C2=A0 buf[3] =3D 0; > + > +=C2=A0 memcpy (readbuf, (char *) buf + offset, len); > +=C2=A0 *xfered_len =3D len; > + > +=C2=A0 return TARGET_XFER_OK; > +} > + > enum target_xfer_status > windows_nat_target::xfer_partial (enum target_object object, >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *annex, gdb_byte *readbuf, > @@ -3011,6 +3046,9 @@ windows_nat_target::xfer_partial (enum target_objec= t object, >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return windows_xfer_shared_libraries = (this, object, annex, readbuf, >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 wr= itebuf, offset, len, xfered_len); > > +=C2=A0=C2=A0=C2=A0 case TARGET_OBJECT_AUXV: > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return windows_xfer_auxv (readbuf, offset= , len, xfered_len); > + >=C2=A0=C2=A0=C2=A0=C2=A0 default: >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (beneath () =3D=3D NULL) >=C2=A0=C2=A0=C2=A0=C2=A0 { > diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c > index 6c9632d035..fd491e8e67 100644 > --- a/gdb/windows-tdep.c > +++ b/gdb/windows-tdep.c > @@ -34,6 +34,10 @@ > #include "solib.h" > #include "solib-target.h" > #include "gdbcore.h" > +#include "coff/internal.h" > +#include "libcoff.h" > +#include "solist.h" > +#include "auxv.h" > > /* Windows signal numbers differ between MinGW flavors and between >=C2=A0=C2=A0=C2=A0=C2=A0 those and Cygwin.=C2=A0 The below enumeration was= gleaned from the > @@ -656,6 +660,20 @@ windows_gdb_signal_to_target (struct gdbarch *gdbarc= h, enum gdb_signal signal) >=C2=A0=C2=A0 return -1; > } > > +static void > +windows_solib_create_inferior_hook (int from_tty) > +{ > +=C2=A0 CORE_ADDR exec_base; > +=C2=A0 /* 9 -> AT_ENTRY */ > +=C2=A0 if (target_auxv_search (current_top_target (), 9, &exec_base) =3D= =3D 1 > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && exec_base && symfile_objfile) > +=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CORE_ADDR vmaddr =3D pe_data (exec_bfd)->= pe_opthdr.ImageBase; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (vmaddr !=3D exec_base) > +=C2=A0=C2=A0=C2=A0 objfile_rebase (symfile_objfile, exec_base - vmaddr); > +=C2=A0=C2=A0=C2=A0 } > +} > + > /* To be called from the various GDB_OSABI_CYGWIN handlers for the >=C2=A0=C2=A0=C2=A0=C2=A0 various Windows architectures and machine types.= =C2=A0 */ > > @@ -674,6 +692,8 @@ windows_init_abi (struct gdbarch_info info, struct gd= barch *gdbarch) > >=C2=A0=C2=A0 set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal= _to_target); > > +=C2=A0 solib_target_so_ops.solib_create_inferior_hook > +=C2=A0=C2=A0=C2=A0 =3D windows_solib_create_inferior_hook; >=C2=A0=C2=A0 set_solib_ops (gdbarch, &solib_target_so_ops); > } > > -- > 2.25.0