Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Hannes Domani via gdb-patches" <gdb-patches@sourceware.org>
To: Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH v2] Rebase executable to match relocated base address
Date: Fri, 14 Feb 2020 14:07:00 -0000	[thread overview]
Message-ID: <854900713.5159847.1581689224439@mail.yahoo.com> (raw)
In-Reply-To: <3df92ab1-e080-1cac-7500-9333714cbd58@linaro.org>

 Am Freitag, 14. Februar 2020, 14:50:07 MEZ hat Luis Machado <luis.machado@linaro.org> Folgendes geschrieben:

> On 2/14/20 9:32 AM, Hannes Domani via gdb-patches wrote:
> >  Am Freitag, 14. Februar 2020, 12:02:03 MEZ hat Luis Machado <luis.machado@linaro.org> 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.
> >>> ---
> >>>    gdb/windows-tdep.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++
> >>>    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 @@
> >>>    #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
> >>>        those and Cygwin.  The below enumeration was gleaned from the
> >>> @@ -812,6 +815,50 @@ windows_get_siginfo_type (struct gdbarch *gdbarch)
> >>>      return siginfo_type;
> >>>    }
> >>>
> >>> +/* Implement the "solib_create_inferior_hook" target_so_ops method.  */
> >>> +
> >>> +static void
> >>> +windows_solib_create_inferior_hook (int from_tty)
> >>> +{
> >>> +  CORE_ADDR exec_base = 0;
> >>> +
> >>> +  /* Find base address of main executable in
> >>> +    TIB->process_environment_block->image_base_address.  */
> >>> +  struct gdbarch *gdbarch = target_gdbarch ();
> >>> +  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> >>> +  int ptr_bytes;
> >>> +  int peb_offset;  /* Offset of process_environment_block in TIB.  */
> >>> +  int base_offset; /* Offset of image_base_address in PEB.  */
> >>> +  if (gdbarch_ptr_bit (gdbarch) == 32)
> >>> +    {
> >>> +      ptr_bytes = 4;
> >>> +      peb_offset = 48;
> >>> +      base_offset = 8;
> >>> +    }
> >>> +  else
> >>> +    {
> >>> +      ptr_bytes = 8;
> >>> +      peb_offset = 96;
> >>> +      base_offset = 16;
> >>> +    }
> >>
> >> 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.
> >
> >
>
> Fair enough. I don't have a strong opinion on this, but i usually try to
> avoid having these magic numbers in the code without some pointers to
> where those came from. Folks dealing with this code in the future may
> try to understand what it is doing and how they came to be.
>
> Having them at a single place, with some explanation, helps with that.
> That's my take on it, at least.

Then I guess I need to make better comments than this:
  /* Find base address of main executable in
     TIB->process_environment_block->image_base_address.  */

  int peb_offset;  /* Offset of process_environment_block in TIB.  */
  int base_offset; /* Offset of image_base_address in PEB.  */


  reply	other threads:[~2020-02-14 14:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200213181430.11259-1-ssbssa.ref@yahoo.de>
2020-02-13 18:14 ` Hannes Domani via gdb-patches
     [not found]   ` <4854af6a-e0c4-7714-6ed4-20697e0282c0@linaro.org>
2020-02-14 12:32     ` Hannes Domani via gdb-patches
2020-02-14 13:50       ` Luis Machado
2020-02-14 14:07         ` Hannes Domani via gdb-patches [this message]
2020-02-14 14:41           ` Luis Machado
2020-03-03  5:46   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=854900713.5159847.1581689224439@mail.yahoo.com \
    --to=gdb-patches@sourceware.org \
    --cc=ssbssa@yahoo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox