public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "corinna at vinschen dot de" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug win32/18027] dwarf2 debug info after rebasing DLLs unusable
Date: Wed, 15 Feb 2023 10:22:03 +0000	[thread overview]
Message-ID: <bug-18027-4717-tXUJxlJseC@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-18027-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=18027

--- Comment #12 from Corinna Vinschen <corinna at vinschen dot de> ---
(In reply to Tom Tromey from comment #11)
> (In reply to Corinna Vinschen from comment #10)
> [...]
> > In fact, the first question is probably if the dwarf2 info couldn't
> > by imagebase-relative, rather than absolute.  If that's possible
> > (and maybe even already handled in GDB?) this could be done by tweaking
> > the linker.
> 
> I think this would be better, but won't it cause issues if we then
> use gdb to debug existing executables?  Since those will have the
> offsets already in the DWARF?

Isn't there some kind of version information in the DWARF sections somewhere?
GDB could use that to distinguish absolute vs. load-address relative DWARF
info.

> > ...then it would be great if GDB could workaround this somehow.
> > The problem here is, I have no clue if there's anything in the DLL
> > which would be indicative of the original image base address after
> > rebasing.  Unless, maybe, some of the dwarf2 info itself can be 
> > used to reconstruct the originl address?
> 
> binutils has a workaround based on _bfd_dwarf2_find_symbol_bias
> (see bfd/dwarf2.c).
> 
> What this does is look for a function in the DWARF that has an address,
> then tries to find that same function in the linker symbols.  When
> it finds a match, it uses those addresses to compute the delta.

Yeah, that actually sounds very simple:

  load address in header: 0x300000000
  func foo in .text: 0x300021300
  func foo in DWARF: 0x4d9241300

  --> original load address at the time the file was created:
  0x300000000 + (0x4d9241300 - 0x300021300) => 0x4D9220000

> This could work in gdb as well, it's just very unfortunate to have to do it.
> However it's hard to see another way.
> 
> One idea I had is to assume that some function lives in the first text page
> and try to use the lowest address seen (this is easier to get just from
> scanning
> the DWARF) to compute the offset, but this fails for cases like a DLL with
> a mix of -g / no-g objects.

We have to assume that the DLL has been built with debugging symbols.  SO
we can safely assume that the DllMain function is always present.

As symbol to look for, one could use DllMain for DLLs, and WinMainCRTStartup
otherwise, they are always present in Cygwin executables.

Alternatively, we know exactly where the .text section starts in a Windows
executable.  .text is at load address + 0x1000.  And there's always *some*
symbol at this address.  So it would be possible to figure out that symbol,
fetch it from DWARF and use the above offset computation, no?


Corinna

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-02-15 10:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26  5:36 [Bug win32/18027] New: " corinna at vinschen dot de
2015-02-26  9:39 ` [Bug win32/18027] " asmwarrior at gmail dot com
2023-02-11 17:48 ` tromey at sourceware dot org
2023-02-12 12:20 ` ssbssa at sourceware dot org
2023-02-13 10:31 ` corinna at vinschen dot de
2023-02-13 10:36 ` corinna at vinschen dot de
2023-02-13 14:01 ` simark at simark dot ca
2023-02-13 16:17 ` corinna at vinschen dot de
2023-02-13 17:13 ` simark at simark dot ca
2023-02-13 17:24 ` ssbssa at sourceware dot org
2023-02-13 19:23 ` tromey at sourceware dot org
2023-02-13 19:46 ` ssbssa at sourceware dot org
2023-02-13 19:48 ` corinna at vinschen dot de
2023-02-13 22:08 ` tromey at sourceware dot org
2023-02-15 10:22 ` corinna at vinschen dot de [this message]
2023-02-17  2:15 ` tromey at sourceware dot org
2023-02-28 14:43 ` tromey at sourceware dot org
2023-02-28 15:20 ` corinna at vinschen dot de
2023-02-28 15:22 ` corinna at vinschen dot de
2023-03-24 17:31 ` tromey at sourceware dot org
2023-03-24 19:00 ` corinna at vinschen dot de
2023-03-27  9:19 ` nickc at redhat dot com
2023-03-28  8:58 ` corinna at vinschen dot de
2023-03-28 14:01 ` nickc at redhat dot com
2023-03-28 18:10 ` corinna at vinschen dot de
2023-03-29 12:46 ` tromey at sourceware dot org
2023-03-30  9:23 ` corinna at vinschen dot de
2023-03-30  9:24 ` corinna at vinschen dot de
2023-04-21 16:38 ` tromey at sourceware dot org
2023-04-21 16:54 ` tromey at sourceware dot org
2023-04-21 17:11 ` tromey at sourceware dot org
2023-04-21 19:48 ` corinna at vinschen dot de
2023-04-24 15:54 ` tromey at sourceware dot org

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=bug-18027-4717-tXUJxlJseC@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).