GDB remote debugging, can't seem to find symbols

23,196

Solution 1

I run "gdb"

You are supposed to give GDB the executable you are debugging (preferably a non-stripped version of it):

gdb /path/to/progname
(gdb) target remote 192.168.98.64:4444

Solution 2

I just encountered this problem myself when I used a cross-compiled gdb (you will in general need this if your remote host has a different architecture). In this case the symbols need to be read from the binary compiled on the remote host. I figured out that the following works for me (also if the architectures on the hosts are the same):

On the remote host:

gdbserver [host]:[port] [remote-path-to-binary-from-gdbserver-workdir]

and then on the local host in (cross-compiled) gdb:

shell sleep 5
target remote [host]:[port]
symbol-file remote:[remote-path-to-binary-from-gdbserver-workdir]
directory [local-root-directory-for-source-files]
continue

Replace the [*] with your data. You can use it as a gdb script (hence the sleep in the first line) or enter it on your gdb command line. The optional directory line tells it to add the local source directory to the search path for sources. This can be useful if you use a frontend which points you to the source code.

Solution 3

When debugging remote, gdb client does not know where to load symbols from. You have two options:

  1. specify executable when starting gdb

     gdb <executable>
     (gdb) target remote <IP>:<port>
     (gdb) load <executable>
      gdb should know symbols now
     (gdb) b main
     (gdb) mon reset
     (gdb) continue
      it should break at main
     (gdb) bt
    
  2. use file command to tell about the symbols.

     gdb
     (gdb) target remote <IP>:<port>
     (gdb) load <executable>
     (gdb) file <executable>
      gdb should know symbols now
     (gdb) b main
     (gdb) mon reset
     (gdb) continue
      it should break at main
     (gdb) bt
    

PS: Make sure you have compiled executable with debug symbols -g -O0

Share:
23,196
fred basset
Author by

fred basset

Engineer working with C, C++, assembler and embedded hardware.

Updated on October 20, 2021

Comments

  • fred basset
    fred basset over 2 years

    I'm trying to remote debug an application running on a machine with address 192.168.98.64. On that machine I run:

    gdbserver serveripaddr:4444 progname
    

    then from the server I run "gdb", then at the gdb prompt run:

    (gdb)  target remote 192.168.98.64:4444
    Remote debugging using 192.168.98.64:4444
    [New Thread 28432]
    warning: Could not load vsyscall page because no executable was specified
    try using the "file" command first.
    0xb775e810 in ?? ()
    (gdb) break internal[TAB]
    

    I was expecting a press of the TAB key when trying to set my breakpoint to bring up a list of corresponding functions starting with internal, but it doesn't bring up anything. The code has been compiled with debugging turned on with -g. What am I doing wrong?

  • 71GA
    71GA over 6 years
    If I don't use -g at compile time i can then only moove through labels that I manually defined. What exactly are the debug symbols? Does GDB create a labels 1:, 2:, 3:... for each line of the source file?
  • Mohammad Azim
    Mohammad Azim over 6 years
    Symbols are information that is compiled in the binary (debug mode) to associate the instructions to the code text. So that you see human readable info in the debugger. For this to work you have to compile with -g and be in the source directory so that gdb can find the source files pointed by the debug binary.