public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix DLL export forwarding
       [not found] <20231204165029.408-1-ssbssa.ref@yahoo.de>
@ 2023-12-04 16:50 ` Hannes Domani
  2023-12-04 17:34   ` Lancelot SIX
  2023-12-06 19:31   ` Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: Hannes Domani @ 2023-12-04 16:50 UTC (permalink / raw)
  To: gdb-patches

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
---
 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..c9d6d86a085 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 if where 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 ();
 
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix DLL export forwarding
  2023-12-04 16:50 ` [PATCH] Fix DLL export forwarding Hannes Domani
@ 2023-12-04 17:34   ` Lancelot SIX
  2023-12-06 19:31   ` Tom Tromey
  1 sibling, 0 replies; 4+ messages in thread
From: Lancelot SIX @ 2023-12-04 17:34 UTC (permalink / raw)
  To: Hannes Domani; +Cc: gdb-patches

Hi Hannes,

I am not familiar with this part of the code so I'll let someone else
comment on the actual change, but found a minor typo.

Other than this, and FWIW, the change seem reasonable to me.

On Mon, Dec 04, 2023 at 05:50:29PM +0100, Hannes Domani wrote:
> 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
> ---
>  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..c9d6d86a085 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 if where relative to DLL_NAME/OBJFILE, even though
                            ^

s/if if/if it/

> +     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 ();
>  
> -- 
> 2.35.1
> 

Best,
Lancelot.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix DLL export forwarding
  2023-12-04 16:50 ` [PATCH] Fix DLL export forwarding Hannes Domani
  2023-12-04 17:34   ` Lancelot SIX
@ 2023-12-06 19:31   ` Tom Tromey
  2023-12-06 20:16     ` Hannes Domani
  1 sibling, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2023-12-06 19:31 UTC (permalink / raw)
  To: Hannes Domani; +Cc: gdb-patches

>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:

Hannes> I noticed it when I was trying to set a breakpoint at ExitProcess:
...

Thank you for the patch.

I have a couple of tiny nits, this is ok with those fixed -- you don't
have to re-send it.

You can also apply this to the gdb-14 branch if you want.

Hannes> -  unrelocated_addr vma = msymbol.minsym->unrelocated_address ();
Hannes> +  /* Calculate VMA as if if where relative to DLL_NAME/OBJFILE, even though

s/if where/it were/

Hannes> +     it actually points inside another dll (FORWARD_DLL_NAME).  */
Hannes> +  unrelocated_addr vma = unrelocated_addr(msymbol.value_address ()

Space before the first "(".

Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix DLL export forwarding
  2023-12-06 19:31   ` Tom Tromey
@ 2023-12-06 20:16     ` Hannes Domani
  0 siblings, 0 replies; 4+ messages in thread
From: Hannes Domani @ 2023-12-06 20:16 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Lancelot SIX

 Am Mittwoch, 6. Dezember 2023, 20:31:20 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:

> >>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>
> Hannes> I noticed it when I was trying to set a breakpoint at ExitProcess:
> ...
>
> Thank you for the patch.
>
> I have a couple of tiny nits, this is ok with those fixed -- you don't
> have to re-send it.
>
> You can also apply this to the gdb-14 branch if you want.
>
> Hannes> -  unrelocated_addr vma = msymbol.minsym->unrelocated_address ();
> Hannes> +  /* Calculate VMA as if if where relative to DLL_NAME/OBJFILE, even though
>
> s/if where/it were/
>
> Hannes> +    it actually points inside another dll (FORWARD_DLL_NAME).  */
> Hannes> +  unrelocated_addr vma = unrelocated_addr(msymbol.value_address ()
>
> Space before the first "(".
>
> Approved-By: Tom Tromey <tom@tromey.com>

Thank you both Lancelot and Tom for noticing my typos.
They are fixed and it's pushed to both master and gdb-14-branch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-06 20:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20231204165029.408-1-ssbssa.ref@yahoo.de>
2023-12-04 16:50 ` [PATCH] Fix DLL export forwarding Hannes Domani
2023-12-04 17:34   ` Lancelot SIX
2023-12-06 19:31   ` Tom Tromey
2023-12-06 20:16     ` 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).