From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31446 invoked by alias); 1 Mar 2020 11:24:36 -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 31416 invoked by uid 89); 1 Mar 2020 11:24:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 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:5.0, H*x:Windows X-HELO: sonic308-17.consmr.mail.ir2.yahoo.com Received: from sonic308-17.consmr.mail.ir2.yahoo.com (HELO sonic308-17.consmr.mail.ir2.yahoo.com) (77.238.178.145) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Mar 2020 11:24:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1583061857; bh=KPn2NW+CNwWpXRQKHJAM8I9R3l9G+xEaAQDqD/IzKjE=; h=Date:From:To:Subject:References:From:Subject; b=Lj9uSNpMHdcy4Fl6JONwOhF1itA784i3qc8kJ7tZlgtTf9idQBo8bRS7oyVSujcLKKJIfTYfDcctDbCRoeYq0mVQkhUkgXBmOJ4Wh/ggoC83h7dYL0+DD2s44ArH4x05dOpWDnqq8BrG6BJttktiSFSO/mq/N3YllNCUQWn9hDLzoRgFQe+j9Sj/eGQFd9+9rxZ+afzN90Pkjaic/I0HAbPWlS3ng2MCrvcfKLUXziJGr9Z0CxQqkxr2WahRRxuqNe9nF+v8QchJxk9ItGji2/HKpt0lQNvbRP66lXTNbfrs4OJXeDZvKk7CM5I5fZbZw1JcvxWBoaMXcV6RYJgR3A== Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sun, 1 Mar 2020 11:24:17 +0000 Date: Sun, 01 Mar 2020 11:24:00 -0000 From: "Hannes Domani via gdb-patches" Reply-To: Hannes Domani To: gdb-patches@sourceware.org Message-ID: <135685003.4134876.1583061852642@mail.yahoo.com> Subject: [PING] [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 References: <135685003.4134876.1583061852642.ref@mail.yahoo.com> X-IsSubscribed: yes X-SW-Source: 2020-03/txt/msg00005.txt Ping. Am Donnerstag, 13. Februar 2020, 19:14:51 MEZ hat Hannes Domani Folgendes geschrieben: > 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. > --- > gdb/windows-tdep.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 49 insertions(+) > > 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 @@ > #include "solib.h" > #include "solib-target.h" > #include "gdbcore.h" > +#include "coff/internal.h" > +#include "libcoff.h" > +#include "solist.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 > @@ -812,6 +815,50 @@ windows_get_siginfo_type (struct gdbarch *gdbarch) >=C2=A0=C2=A0 return siginfo_type; > } > > +/* 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 T= IB.=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 } > +=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_offset,= 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_intege= r (buf, ptr_bytes, byte_order); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!target_read_memory (peb + base_offse= t, buf, ptr_bytes)) > +=C2=A0=C2=A0=C2=A0 exec_base =3D extract_unsigned_integer (buf, ptr_byte= s, 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 } > +} > + > /* 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 */ > > @@ -830,6 +877,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); > >=C2=A0=C2=A0 set_gdbarch_get_siginfo_type (gdbarch, windows_get_siginfo_ty= pe); > -- > 2.25.0