From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 39362 invoked by alias); 11 Feb 2020 11:34:53 -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 39337 invoked by uid 89); 11 Feb 2020 11:34:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.2 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=touching 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; Tue, 11 Feb 2020 11:34:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1581420887; bh=RVvr/HtAYCRauATiin6KoxNXeOqCSqGVRGgzLmP/w2U=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject; b=AJhX233d242buwElUnyMApbWYp4rEcjEuF61ZQaftEkal39gtFN0aLwBZ+7xjeJ9ZZIq2ba743e9jYY95IY7Mpsym3vLCCw5IJIFRY6C/uxLVWKivDgbJlafEtIlwxrxzEQaWZqYtrH+glTOUFahsWwcjhoaojBNgddPVrg4R8hTJirTZ0766aERu+JwaB5EyxAjOS8QR5RtZ0XDXVygiBMapHUKDEhE5XV8sL6pUO/TdzgTRFf0lJTlT7w3vYiaIZ0jBHq55bL2sS8BXnns6146oLq4lT76Hp3fSVUDkZK1Tdc2So2pwFhCMDbsfyE2CimKKCK7UlPh4jvFfcFJEQ== Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Tue, 11 Feb 2020 11:34:47 +0000 Date: Tue, 11 Feb 2020 11:34:00 -0000 From: "Hannes Domani via gdb-patches" Reply-To: Hannes Domani To: Gdb-patches Message-ID: <568325237.2257415.1581420878458@mail.yahoo.com> In-Reply-To: References: <691075103.286431.1581179823782.ref@mail.yahoo.com> <691075103.286431.1581179823782@mail.yahoo.com> Subject: Re: [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 X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00381.txt.bz2 Am Dienstag, 11. Februar 2020, 01:29:44 MEZ hat Luis Machado Folgendes geschrieben: > On 2/8/20 1:37 PM, Hannes Domani via gdb-patches wrote: > > Ping. > > > > Am Samstag, 25. Januar 2020, 17:47:19 MEZ hat Hannes Domani via gdb-pat= ches 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=C2=A0=C2=A0 * windows-nat.c (windows_nat_targe= t::get_windows_debug_event): > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Set current_exec_base. > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (windows_xfer_auxv): New function. > >>=C2=A0=C2=A0=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=C2=A0=C2=A0 * windows-tdep.c (windows_solib_cr= eate_inferior_hook): New function. > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (windows_init_abi): Use windows_so= lib_create_inferior_hook. > >> > >> gdb/gdbserver/ChangeLog: > >> > >> 2020-01-25=C2=A0 Hannes Domani=C2=A0 > >> > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * win32-low.c (get_child_debug_eve= nt): Set current_exec_base. > >>=C2=A0=C2=A0=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 b= ase address */ > > Set current_exec_base to 0 so it gets explicitly initialized? OK. > >> 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 = *ourstatus) > >> > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 current_process_handle= =3D current_event.u.CreateProcessInfo.hProcess; > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 main_thread_id =3D cur= rent_event.dwThreadId; > >> +=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.= lpBaseOfImage; > > Formatting of the second line looks funny. Should be moved forward. OK. > Has the lpBaseOfImage member variable always been there and was never > used? From what i looked at MSDN, it looks like it. Yes. > >> > >>=C2=A0=C2=A0=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=C2=A0=C2=A0 child_add_thread (curr= ent_event.dwProcessId, > >> @@ -1713,6 +1716,36 @@ win32_request_interrupt (void) > >>=C2=A0=C2=A0=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 in= t len) > >> +{ > >> +=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=C2=A0=C2=A0 win32_write_inferior_memory, > >>=C2=A0=C2=A0=C2=A0=C2=A0 NULL, /* lookup_symbols */ > >>=C2=A0=C2=A0=C2=A0=C2=A0 win32_request_interrupt, > >> -=C2=A0 NULL, /* read_auxv */ > >> +=C2=A0 win32_read_auxv, > >>=C2=A0=C2=A0=C2=A0=C2=A0 win32_supports_z_point_type, > >>=C2=A0=C2=A0=C2=A0=C2=A0 win32_insert_point, > >>=C2=A0=C2=A0=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=C2=A0=C2=A0= WaitForDebugEvent */ > >> static HANDLE current_process_handle;=C2=A0=C2=A0=C2=A0 /* Currently e= xecuting 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 b= ase address */ > >> > >> /* Counts of things.=C2=A0 */ > >> static int exception_count =3D 0; > >> @@ -1604,6 +1605,8 @@ windows_nat_target::get_windows_debug_event (int= pid, > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; > >> > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 current_process_handle= =3D current_event.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.= lpBaseOfImage; > >>=C2=A0=C2=A0=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=C2=A0=C2=A0 th =3D windows_add_thr= ead > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (ptid_t (c= urrent_event.dwProcessId, 0, > >> @@ -2996,6 +2999,38 @@ windows_xfer_shared_libraries (struct target_op= s *ops, > >>=C2=A0=C2=A0=C2=A0=C2=A0 return len !=3D 0 ? TARGET_XFER_OK : TARGET_XF= ER_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 *xfer= ed_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=C2=A0=C2=A0 const char *annex, gdb_= byte *readbuf, > >> @@ -3011,6 +3046,9 @@ windows_nat_target::xfer_partial (enum target_ob= ject object, > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return windows_xfer_sh= ared_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= =C2=A0=C2=A0 writebuf, 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, off= set, len, xfered_len); > >> + > >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 default: > >>=C2=A0=C2=A0=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=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=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 *gdb= arch, enum gdb_signal signal) > >>=C2=A0=C2=A0=C2=A0=C2=A0 return -1; > >> } > >> > >> +static void > >> +windows_solib_create_inferior_hook (int from_tty) > > > Missing documentation for this function. Right. > This function is needed, but the question is how it should get the base > address from the target. > > The auxv trickery works, but that may have other implications. I'm not > sure if GDB won't try to fetch more stuff given we now have an "auxv". > And it is also a bit misleading. I've used this approach for a while now, and never had any problem with it. Also, gnu-nat.c creates a fake auxv entry as well. > Is there some other way one can fetch this data? Registers? Memory? I'm not sure how that would work. > If not, then maybe we could create a new qxfer request to fetch this > data for Windows, say, TARGET_OBJECT_WINDOWS_LOADBASE. It would be > cleaner and would handle both gdbserver and gdb. > > In case we want to make the request more generic, maybe call it > TARGET_OBJECT_EXEC_LOADBASE or somesuch. I agree that this would be the cleanest solution, but I thought touching the gdbserver interface isn't the best idea when it can be avoided. Regards Hannes Domani