RE: [RFC-v5] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)

Pierre Muller
2012-12-13T10:57:09Z

> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pedro Alves
> Envoyé : vendredi 7 décembre 2012 18:49
> Cc : Pierre Muller; 'asmwarrior'; 'Joel Brobecker'; 'Eli Zaretskii'; gdb-
> patches@sourceware.org
> Objet : Re: [RFC-v5] Fix .text section offset for windows DLL (was Calling
> __stdcall functions in the inferior)
>
> On 12/07/2012 05:09 PM, Pedro Alves wrote:
> > I haven't tried to grok the patch, but Kai tells me that a section name in
> PE headers
> > are stored in 8 character arrays, and are not necessarily zero-terminated.
> > He was wondering, and now I am too, if it wouldn't be possible to make use
> > of bfd routines to get at the necessary info, like the .text section
> offset.
> > E.g., bfd handles the long section name PE extension to coff (see
> coffcode.h in
> > bfd), though I'm not sure that needs to apply here.
>
> Hmm, looking at:
>
> > @@ -387,15 +391,21 @@ windows_xfer_shared_library (const char*
> > struct gdbarch *gdbarch, struct obstack *obstack)
> > {
> > char *p;
> > + struct bfd * dll;
> > + CORE_ADDR text_offset;
> > +
> > obstack_grow_str (obstack, "<library name=\"");
> > p = xml_escape_text (so_name);
> > obstack_grow_str (obstack, p);
> > xfree (p);
> > obstack_grow_str (obstack, "\"><segment address=\"");
> > - /* The symbols in a dll are offset by 0x1000, which is the
> > - offset from 0 of the first byte in an image - because of the file
> > - header and the section alignment. */
> > - obstack_grow_str (obstack, paddress (gdbarch, load_addr + 0x1000));
> > + dll = gdb_bfd_open_maybe_remote (so_name);
> > + /* The following calls are OK even if dll is NULL.
> > + The default value 0x1000 is returned by pe_text_section_offset
> > + in that case. */
> > + text_offset = pe_text_section_offset (dll);
> > + gdb_bfd_unref (dll);
>
> I notice that this only handles native debugging. GDBserver also does
> the 0x1000 add, see win32-low.c:handle_load_dll. So I'm now actually
> thinking if the opposite direction may be better. That is, make
> pe_text_section_offset completely independent of bfd (which it almost is),
> and put it in a file under common/ so that gdbserver can use it too.

Pedro,
you are right that my just committed patch does not
fix the issue for windows gdbserver...
So your idea to share the new function between gdb and gdbserver
seemed indeed appealing, but when I looked at the new function pe_text_section_offset
it doesn't seem so easy to me to remove bfd dependency...

I will try to come up with a fix for gdbserver,
but I am not sure it will be soon...

Pierre Muller