From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98195 invoked by alias); 14 Feb 2020 12:32:12 -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 98142 invoked by uid 89); 14 Feb 2020 12:32:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.3 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*x:Mozilla, H*x:Gecko, H*x:YMailNorrin, H*UA:YMailNorrin X-HELO: sonic305-20.consmr.mail.ir2.yahoo.com Received: from sonic305-20.consmr.mail.ir2.yahoo.com (HELO sonic305-20.consmr.mail.ir2.yahoo.com) (77.238.177.82) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Feb 2020 12:32:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1581683526; bh=I9MItd567SpV3tFNJVlIBGksTZiQLrm0T84lMX+f7NI=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject; b=X/hQ4NA7znQqttn+41fXi7xt5WP1ipW0Z8a81hDvMKubVRvqvvklh0sH2cbfPA5rFwVjkrRypbW/nHMNMsmBZahk5XHSlxkaDKs1KMQjVcQchJS4geZ3NzveoP3eC455m0p/7wxJqtwEfszg7CDifDrt3lAgK9QBUGP3HDSeIB+BTqfuS1Hu4LcrJDsXnfddQVd/Detq92a2Kv04iqoc2nK/ABP/Lpc+xAdd4rgKgc4lwbZj5Qy2gh+z6yJtylTjwaKU0Dq1/O/ZmhmdMr61WL6K/cKe+BvYNayr2/6lKHw+fRLKwbNmeTKMEkTvb3ubHP8M2P0etOzbpL9O+VopEg== Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Fri, 14 Feb 2020 12:32:06 +0000 Date: Fri, 14 Feb 2020 12:32:00 -0000 From: "Hannes Domani via gdb-patches" Reply-To: Hannes Domani To: Gdb-patches Message-ID: <578612266.5100822.1581683522459@mail.yahoo.com> In-Reply-To: <4854af6a-e0c4-7714-6ed4-20697e0282c0@linaro.org> References: <20200213181430.11259-1-ssbssa.ref@yahoo.de> <20200213181430.11259-1-ssbssa@yahoo.de> <4854af6a-e0c4-7714-6ed4-20697e0282c0@linaro.org> Subject: Re: [PATCH v2] 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/msg00560.txt.bz2 Am Freitag, 14. Februar 2020, 12:02:03 MEZ hat Luis Machado Folgendes geschrieben: > Hi, > > On 2/13/20 3:14 PM, Hannes Domani via gdb-patches wrote: > > 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 new base address is read from the Process Environment Block. > > --- > > v2: > > This version now no longer needs the fake auxv entry. > > --- > >=C2=A0 gdb/windows-tdep.c | 49 +++++++++++++++++++++++++++++++++++++++++= +++++ > >=C2=A0 1 file changed, 49 insertions(+) > > > > Thanks. This version looks better. > > > diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c > > index 6eef3fbd96..29c0a828a7 100644 > > --- a/gdb/windows-tdep.c > > +++ b/gdb/windows-tdep.c > > @@ -34,6 +34,9 @@ > >=C2=A0 #include "solib.h" > >=C2=A0 #include "solib-target.h" > >=C2=A0 #include "gdbcore.h" > > +#include "coff/internal.h" > > +#include "libcoff.h" > > +#include "solist.h" > > > >=C2=A0 /* Windows signal numbers differ between MinGW flavors and between > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 those and Cygwin.=C2=A0 The below enumera= tion was gleaned from the > > @@ -812,6 +815,50 @@ windows_get_siginfo_type (struct gdbarch *gdbarch) > >=C2=A0=C2=A0=C2=A0 return siginfo_type; > >=C2=A0 } > > > > +/* Implement the "solib_create_inferior_hook" target_so_ops method.=C2= =A0 */ > > + > > +static void > > +windows_solib_create_inferior_hook (int from_tty) > > +{ > > +=C2=A0 CORE_ADDR exec_base =3D 0; > > + > > +=C2=A0 /* Find base address of main executable in > > +=C2=A0=C2=A0=C2=A0 TIB->process_environment_block->image_base_address.= =C2=A0 */ > +=C2=A0 struct gdbarch *gdbarch =3D target_gdbarch (); > > +=C2=A0 enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); > > +=C2=A0 int ptr_bytes; > > +=C2=A0 int peb_offset;=C2=A0 /* Offset of process_environment_block in= TIB.=C2=A0 */ > > +=C2=A0 int base_offset; /* Offset of image_base_address in PEB.=C2=A0 = */ > > +=C2=A0 if (gdbarch_ptr_bit (gdbarch) =3D=3D 32) > > +=C2=A0=C2=A0=C2=A0 { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ptr_bytes =3D 4; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 peb_offset =3D 48; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 base_offset =3D 8; > > +=C2=A0=C2=A0=C2=A0 } > > +=C2=A0 else > > +=C2=A0=C2=A0=C2=A0 { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ptr_bytes =3D 8; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 peb_offset =3D 96; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 base_offset =3D 16; > > +=C2=A0=C2=A0=C2=A0 } > > How about stashing the above offsets in windows_gdbarch_data, and then > using them here? To be honest, that would seem a bit weird for me, since they are just these simple numbers, and aren't used anywhere else. > > +=C2=A0 CORE_ADDR tlb; > > +=C2=A0 gdb_byte buf[8]; > > +=C2=A0 if (target_get_tib_address (inferior_ptid, &tlb) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && !target_read_memory (tlb + peb_offse= t, buf, ptr_bytes)) > > +=C2=A0=C2=A0=C2=A0 { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CORE_ADDR peb =3D extract_unsigned_inte= ger (buf, ptr_bytes, byte_order); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!target_read_memory (peb + base_off= set, buf, ptr_bytes)) > > +=C2=A0=C2=A0=C2=A0 exec_base =3D extract_unsigned_integer (buf, ptr_by= tes, byte_order); > > +=C2=A0=C2=A0=C2=A0 } > > + > > +=C2=A0 if (symfile_objfile && exec_base) > > +=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 } > > I'd add a comment to the above conditional block on why we're doing this > relocation now, if you think it is worth mentioning. > > It seems to me the behavior has changed now, hence why it seems > worthwhile adding some information. Something like?: /* Rebase executable if the base address changed because of ASLR.=C2=A0 */ Regards Hannes Domani