* GDB: problem debugging 32 bit binary on 64 bit machine
@ 2011-11-29 20:58 Jeff Kenton
2011-11-29 21:11 ` Jan Kratochvil
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Kenton @ 2011-11-29 20:58 UTC (permalink / raw)
To: gdb
A little convoluted, but here's the story:
On our 64 machine gdb fails to read share libraries when debugging 32
bit binaries (i.e., compiled with "-m32"). Debugging code built
"-static" is OK. The error is "Cannot access memory at address
0x400000008" (address is above the 32 bit limit). This is caused by a
call to extract_typed_address() from scan_dyntag() reading an 8 byte
type when it should only be reading 4 bytes.
So, I tweaked extract_typed_address() to know it was dealing with 32
binaries. Now gdb starts happily and reads in the shared libraries but
the program won't execute. It gets
warning: Can't read pathname for load map: Input/output error.
Cannot access memory at address 0x35dc3000
and the backtrace shows that it's in dl_main():
#0 *__GI__dl_debug_state () at dl-debug.c:77
#1 0x0000000077f93d00 in dl_main () at rtld.c:1651
#2 0x0000000077fb1698 in _dl_sysdep_start () at ../elf/dl-sysdep.c:244
#3 0x0000000077f90c70 in _dl_start_final () at rtld.c:334
#4 0x0000000077f96630 in _dl_start () at rtld.c:562
#5 0x0000000077fb2530 in _start () from .../lib32/ld.so.1
I have two questions:
1. is tweaking extract_typed_address() the right way to handle 32 bit
addresses on a 64 bit machine? It seems weird but nothing else came to mind.
2. what's going wrong with dl_main()?
3. meta-question: is this a generic bug in gdb's handling of 32 bit
binaries, or is there likely something I missed while porting?
Thanks.
--jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GDB: problem debugging 32 bit binary on 64 bit machine
2011-11-29 20:58 GDB: problem debugging 32 bit binary on 64 bit machine Jeff Kenton
@ 2011-11-29 21:11 ` Jan Kratochvil
2011-11-30 13:35 ` Jeff Kenton
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kratochvil @ 2011-11-29 21:11 UTC (permalink / raw)
To: Jeff Kenton; +Cc: gdb
On Tue, 29 Nov 2011 21:58:14 +0100, Jeff Kenton wrote:
> 0x400000008" (address is above the 32 bit limit). This is caused by
> a call to extract_typed_address() from scan_dyntag() reading an 8
> byte type when it should only be reading 4 bytes.
ARCH_SIZE there should be 32 and TARGET_GDBARCH should be 32-bit.
I guess for some reasons your GDB found wrong (64-bit) library for your 32-bit
program. See the settings like `set solib-search-path', `set sysroot' etc.
> I have two questions:
> 1. is tweaking extract_typed_address() the right way to handle 32
> bit addresses on a 64 bit machine?
No. If ARCH_SIZE and TARGET_GDBARCH are set right it will work.
> 2. what's going wrong with dl_main()?
There is called a notification new library has been loaded in the inferior,
therefore GDB tries to load a matching symbol file (=the library itself) on
the GDB side.
> 3. meta-question: is this a generic bug in gdb's handling of 32 bit
> binaries, or is there likely something I missed while porting?
It 32-on-64 normally works, at least in Fedora, no custom patches for it
there.
Regards,
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GDB: problem debugging 32 bit binary on 64 bit machine
2011-11-29 21:11 ` Jan Kratochvil
@ 2011-11-30 13:35 ` Jeff Kenton
2011-11-30 22:00 ` Jan Kratochvil
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Kenton @ 2011-11-30 13:35 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb
On 11/29/2011 04:11 PM, Jan Kratochvil wrote:
> On Tue, 29 Nov 2011 21:58:14 +0100, Jeff Kenton wrote:
>> 0x400000008" (address is above the 32 bit limit). This is caused by
>> a call to extract_typed_address() from scan_dyntag() reading an 8
>> byte type when it should only be reading 4 bytes.
> ARCH_SIZE there should be 32 and TARGET_GDBARCH should be 32-bit.
This sounds like the basic problem. Building the 32 bit target_gdbarch
is easy. What's the best way (place in the code) to detect 32 bit vs.
64 bit binaries and switch between different gdbarch's?
Thanks.
>
> I guess for some reasons your GDB found wrong (64-bit) library for your 32-bit
> program. See the settings like `set solib-search-path', `set sysroot' etc.
>
>> I have two questions:
>> 1. is tweaking extract_typed_address() the right way to handle 32
>> bit addresses on a 64 bit machine?
> No. If ARCH_SIZE and TARGET_GDBARCH are set right it will work.
>
>
>> 2. what's going wrong with dl_main()?
> There is called a notification new library has been loaded in the inferior,
> therefore GDB tries to load a matching symbol file (=the library itself) on
> the GDB side.
>
>
>> 3. meta-question: is this a generic bug in gdb's handling of 32 bit
>> binaries, or is there likely something I missed while porting?
> It 32-on-64 normally works, at least in Fedora, no custom patches for it
> there.
>
>
> Regards,
> Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GDB: problem debugging 32 bit binary on 64 bit machine
2011-11-30 13:35 ` Jeff Kenton
@ 2011-11-30 22:00 ` Jan Kratochvil
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kratochvil @ 2011-11-30 22:00 UTC (permalink / raw)
To: Jeff Kenton; +Cc: gdb
On Wed, 30 Nov 2011 14:35:14 +0100, Jeff Kenton wrote:
> This sounds like the basic problem. Building the 32 bit
> target_gdbarch is easy. What's the best way (place in the code) to
> detect 32 bit vs. 64 bit binaries and switch between different
> gdbarch's?
I do not understand the context. The current GDB switches target_gdbarch
right during execution of "./gdb ./gdb", at:
#0 deprecated_target_gdbarch_select_hack (new_gdbarch=0x2071110) at gdbarch.c:4294
#1 in set_gdbarch_from_file (abfd=0x206c990) at arch-utils.c:559
#2 in exec_file_attach (filename=0x7fffffffde00 "./gdb", from_tty=1) at exec.c:294
#3 in catch_command_errors (command=0x488ab7 <exec_file_attach>, arg=0x7fffffffde00 "./gdb", from_tty=1, mask=6) at exceptions.c:531
#4 in captured_main (data=0x7fffffffd9e0) at ./main.c:850
#5 in catch_errors (func=0x4873f6 <captured_main>, func_args=0x7fffffffd9e0, errstring=0xe6ede7 "", mask=6) at exceptions.c:504
#6 in gdb_main (args=0x7fffffffd9e0) at ./main.c:953
#7 in main (argc=2, argv=0x7fffffffdae8) at gdb.c:35
Regards,
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-11-30 22:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-29 20:58 GDB: problem debugging 32 bit binary on 64 bit machine Jeff Kenton
2011-11-29 21:11 ` Jan Kratochvil
2011-11-30 13:35 ` Jeff Kenton
2011-11-30 22:00 ` Jan Kratochvil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox