public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb/gdb-14-branch] Fix DLL export forwarding
@ 2023-12-06 20:14 Hannes Domani
  0 siblings, 0 replies; only message in thread
From: Hannes Domani @ 2023-12-06 20:14 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=43a608adb04251be8999304cf724f55b2d840ac3

commit 43a608adb04251be8999304cf724f55b2d840ac3
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Wed Dec 6 20:52:06 2023 +0100

    Fix DLL export forwarding
    
    I noticed it when I was trying to set a breakpoint at ExitProcess:
    ```
    (gdb) b ExitProcess
    Breakpoint 1 at 0x14001fdd0
    (gdb) r
    Starting program: C:\qiewer\heob\heob64.exe
    Warning:
    Cannot insert breakpoint 1.
    Cannot access memory at address 0x3dbf4120
    Cannot insert breakpoint 1.
    Cannot access memory at address 0x77644120
    ```
    
    The problem doesn't exist in gdb 13.2, and the difference can easily be
    seen when printing ExitProcess.
    gdb 14.1:
    ```
    (gdb) p ExitProcess
    $1 = {<text variable, no debug info>} 0x77644120 <UserHandleGrantAccess+36128>
    ```
    gdb 13.2:
    ```
    (gdb) p ExitProcess
    $1 = {<text variable, no debug info>} 0x77734120 <ntdll!RtlExitUserProcess>
    ```
    
    The new behavior started with 9675da25357c7a3f472731ddc6eb3becc65b469a,
    where VMA was then calculated relative to FORWARD_DLL_NAME, while it was
    relative to DLL_NAME before.
    
    Fixed by calculating VMA relative to DLL_NAME again.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31112
    Approved-By: Tom Tromey <tom@tromey.com>
    
    (cherry picked from commit 2574cd903dd84e7081506e24c2e232ecda11a736)

Diff:
---
 gdb/coff-pe-read.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 56137ac4dd0..8e30c6a4a61 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -210,7 +210,10 @@ add_pe_forwarded_sym (minimal_symbol_reader &reader,
 			      " \"%s\" in dll \"%s\", pointing to \"%s\"\n"),
 		sym_name, dll_name, forward_qualified_name.c_str ());
 
-  unrelocated_addr vma = msymbol.minsym->unrelocated_address ();
+  /* Calculate VMA as if it were relative to DLL_NAME/OBJFILE, even though
+     it actually points inside another dll (FORWARD_DLL_NAME).  */
+  unrelocated_addr vma = unrelocated_addr (msymbol.value_address ()
+					   - objfile->text_section_offset ());
   msymtype = msymbol.minsym->type ();
   section = msymbol.minsym->section_index ();

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-06 20:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06 20:14 [binutils-gdb/gdb-14-branch] Fix DLL export forwarding Hannes Domani

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).