I have two identical 64-bit Centos 5 processors that are connected to the network and share their / home mount. I am compiling a simple Hello World program on one, and then I figured out how to use gdb on one machine to remotely debug it on another machine. This seems to be normal when each defaults to 64 bits.
However, if I compile my Hello World with -m32 to generate 32-bit binary, then how our complete system compiles, then I cannot figure out how to properly connect gdb and gdbserver. Before I try to do this on our complete system, I suggest that I should work with a greeting. Depending on how I try to connect to gdb and gdbserver, I either receive messages about poorly formatted registers, warnings about architecture mismatches, or illegal memory links.
It seems that I have little understanding that the consequences of -m32 are in my compilation, and I don’t know how to run gdb and gdbserver, or in the correct order to specify the architecture or files or something else. :(
What does it take to use gdb and gdbserver in a 32-bit (-m32) executable in the 64-bit Linux line?
Examples below and thanks,
hello.cpp:
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Hello World." << std::endl;
return -1;
}
:
- gdb i386/ gdbserver = >
- gdb i386/file hello/ gdbserver = >
- gdb () i386: x86-64/file hello/ gdbserver = >
:
==============================
gdbserver :
$ gdbserver --multi rdev6:2010 hello
Process hello created; pid = 32603
Listening on port 2010
Remote debugging from host 134.51.26.149
readchar: Got EOF
Remote side has terminated connection. GDBserver will reopen the connection.
Listening on port 2010
:
==============================
- , i386 32 , archi i386,
note: gdb .
$ gdb
GNU gdb Fedora (6.8-37.el5)
his GDB was configured as "x86_64-redhat-linux-gnu".
(gdb) set archi i386
The target architecture is assumed to be i386
(gdb) target extended-remote rdev6:2010
Remote debugging using rdev6:2010
warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
Remote register badly formatted: T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
Try to load the executable by `file' first,
you may also check `set/show architecture'.
(gdb)
==============================
- , i386 32 , archi i386,
: gdb
$ gdb
GNU gdb Fedora (6.8-37.el5)
his GDB was configured as "x86_64-redhat-linux-gnu".
(gdb) set archi i386
The target architecture is assumed to be i386
(gdb) file hello
Reading symbols from /home/j/hello...done.
(gdb) target extended-remote rdev6:2010
Remote debugging using rdev6:2010
warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
Remote register badly formatted: T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
Try to load the executable by `file' first,
you may also check `set/show architecture'.
(gdb) sho archi
The target architecture is assumed to be i386
(gdb)
==============================
- ( ), i386: x86-64, archi i386: x86-64,
: gdb
$ gdb
GNU gdb Fedora (6.8-37.el5)
This GDB was configured as "x86_64-redhat-linux-gnu".
(gdb) set archi i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) file hello
Reading symbols from /home/j/hello...done.
(gdb) show archi
The target architecture is assumed to be i386:x86-64
(gdb) target extended-remote rdev6:2010
Remote debugging using rdev6:2010
[New Thread 32667]
Cannot access memory at address 0x800000008
(gdb)