Remote debug error with GDB

2019-02-13 14:19发布

问题:

I tried to remote debug an 32-bit application on x86_64 suse linux, but get this "remote register badly formatted" error.

I start up the gdbserver as listening on port 12345 (gdbserver localhost:12345 my_prog)

And this is the error:

$ gdb
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-suse-linux".
(gdb) target remote <ip>:12345
Remote debugging using <ip>:12345
Remote register badly formatted: T0506:0000000000000000;07:80b8bcff00000000;10:4028f0f700000000;
here: 0000000;07:80b8bcff00000000;10:4028f0f700000000;
(gdb)

This is the debug server machine (uname -a):

Linux server 2.6.16.60-0.31-smp #1 SMP Tue Oct 7 16:16:29 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux

And this is the debug client machine (uname -a):

Linux client 2.6.16.54-0.2.5-default #1 Mon Jan 21 13:29:51 UTC 2008 x86_64 x86_64 x86_64 GNU/Linux

Both machines are running in virtual machines though (VMWare). The gdbserver binary is copied from the client machine to the server machine.

(I remote debug because the runtime environment on the debug server is production-like, and doesn't contain any development tools, access to the source code etc.)

Any suggestions are welcome.

UPDATE: this worked for me by issuing the following command in gdb:

set architecture i386:x86-64

回答1:

Perhaps you need to execute something like set architecture i386 at the (gdb) prompt? What does show architecture say after you connect to the remote target?



回答2:

A 64-bit GDB can directly debug both 32 and 64-bit inferior processes (I believe this is called multi-arch support).

Not so with gdbserver: it doesn't support multi-arch debugging.

You need a gdbserver that matches target architecture, and gdb that matches gdbserver. Build them from source, configure with --target=i686.



回答3:

Maybe you've already checked this, but here goes: - On the 64-bit machine, do you have 32-bit libraries of it (libc, etc)? - Have you tried running gdb with the "-nx" (no initialization files) switch?



回答4:

1) You need a proper gdbserver for your target machine and your host machine (the one which fits the target machine in your case.

Let's say I want to debug a ppc target from an x86 host:

I will need on my target a ppc executable gdbserver.

I will need on my host an x86 executable gdb for powerpc.

After you are set with those things you have to do the following from your host gdb before connecting to the target in case you use shared libs:

set solib-absolute-prefix $ELDK_PREFIX/eldk-4.2-ppc_4xx/$CROSS_COMPILE

dir $ELDK_PREFIX/eldk-4.2-ppc_4xx/$CROSS_COMPILE

otherwise the host gdb will get crazy trying to load shared libs for x86.



回答5:

I think you need to run gdb on your host machine with a copy of the target program. I.e. if you run gdbserver myprog on your target machine, you need to copy over myprog to the host machine and run gdb myprog.

This way gdb on the host machine will automatically pick up the architecture from the executable. Running gdb on the host like this will also load the symbols, without which you would get unresolved symbols (question marks).