4

I'm trying remote debug a Rust executable using gdbserver on the remote machine and gdb on the local machine. I set up a Vagrant VM (bento/ubuntu-18.04) and start a gdbserver:

$ vagrant ssh
$ uname -a

Linux dev 4.15.0-121-generic #123-Ubuntu SMP Mon Oct 5 16:16:40 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ gdbserver --version

GNU gdbserver (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "x86_64-linux-gnu"

$ cargo run
$ file ./target/debug/my-app

./target/debug/my-app: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=31b1870cf7ef9e35ebe980acedf7eeaad694bb60, with debug_info, not stripped

$ gdbserver localhost:2000 ./target/debug/my-app

Process ./target/debug/my-app created; pid = 3851
Listening on port 2000

On my local macOS workstation:

$ uname -a

Darwin XXX 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64

$ gdb

GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin19.6.0".
Type "show configuration" for configuration details.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) target remote localhost:2000
Remote debugging using localhost:2000
Reading /vagrant/target/debug/my-app from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /vagrant/target/debug/my-app from remote target...
Reading symbols from target:/vagrant/target/debug/my-app...
warning: I'm sorry, Dave, I can't do that.  Symbol format `elf64-x86-64' unknown.
Reading /lib64/ld-linux-x86-64.so.2 from remote target...
Reading /lib64/ld-linux-x86-64.so.2 from remote target...
Reading symbols from target:/lib64/ld-linux-x86-64.so.2...
Error while reading shared library symbols for target:/lib64/ld-linux-x86-64.so.2:
I'm sorry, Dave, I can't do that.  Symbol format `elf64-x86-64' unknown.
[1]    16617 abort      gdb

What is going wrong here?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Dentrax
  • 574
  • 8
  • 22
  • since when gdb is named gdbserver ? your tittle question is wrong – Stargateur Nov 26 '20 at 09:48
  • gdb and gdbserver are seperate things. gdbserver is a remote server for the gdb. Please read Linux Manpages for more information. Which part of question do you think that it was "wrong"? – Dentrax Nov 26 '20 at 10:58
  • "gdb fails" when your question explain gdb work but not gdbserver or I miss something anyway, both case your question is unclear – Stargateur Nov 26 '20 at 12:03
  • also I don't understand why this question is on SO obviously you should open a issue somewhere in gdb or rust – Stargateur Nov 26 '20 at 12:05
  • How did you install gdb? If you used brew, you might need to use the `--with-all-targets` option when installing it. – Mark Plotnick Nov 26 '20 at 12:27
  • gdb is mixing libraries from the target and host systems. You need to have access to a copy of the target filesystem on the host machine, then use `set sysroot` to point gdb to that copy. – Jmb Nov 26 '20 at 12:52

2 Answers2

1

I had a similar problem on macOS Catalina:

GDB failed with message: I'm sorry, Dave, I can't do that.  Symbol format `elf64-x86-64' unknown.

I could solve it by building from source with specifying the correct target:

  • download gdb source, unzip, and cd into it

  • ./configure --target=amd64-linux

  • make

  • sudo make install

  • (optional for VS Code) add "miDebuggerPath": "/usr/local/bin/amd64-linux-gdb"

binary is installed in "/usr/local/bin/amd64-linux-gdb", and can be called with

amd64-linux-gdb in a terminal.

If this does not work, try these suggested modifications before building:

Update

The approach worked with

Apple clang version 11.0.3 (clang-1103.0.32.29)
and sometimes work with
Apple clang version 12.0.0 (clang-1200.0.32.28) .

wuxb
  • 2,572
  • 1
  • 21
  • 30
nick
  • 99
  • 7
-1
git clone git://sourceware.org/git/binutils-gdb.git
git checkout b413232211bf7c7754095b017f27774d70646489
./configure --target=gdb --enable-targets=all
make -j`nproc`
sudo make install

Reference:

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

https://sourceware.org/bugzilla/show_bug.cgi?id=26949

  • 3
    This answer could be thoroughly improved by describing *why* this code should be run, *what* it does, *how* it does it, etc. – Shepmaster Jun 08 '21 at 14:04