GDB远程调试,似乎找不到符号

fre*_*set 14 gdb remote-debugging

我正在尝试远程调试在地址为192.168.98.64的计算机上运行的应用程序.在那台机器上我运行:

gdbserver serveripaddr:4444 progname

然后从服务器运行"gdb",然后在gdb提示符下运行:

(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]

当我试图设置我的断点以显示从内部开始的相应函数列表时,我期待按下TAB键,但它不会产生任何结果.编译代码时使用-g打开调试.我究竟做错了什么?

Emp*_*ian 11

我跑"gdb"

你应该给GDB你正在调试的可执行文件(最好是它的非剥离版本):

gdb /path/to/progname
(gdb) target remote 192.168.98.64:4444
Run Code Online (Sandbox Code Playgroud)


hig*_*guy 6

当我使用交叉编译的gdb时,我自己就遇到了这个问题(如果你的远程主机有不同的架构,你通常会需要这个).在这种情况下,需要从远程主机上编译的二进制文件中读取符号.我发现以下内容适合我(如果主机上的架构相同):

在远程主机上:

gdbserver [host]:[port] [remote-path-to-binary-from-gdbserver-workdir]
Run Code Online (Sandbox Code Playgroud)

然后在(交叉编译)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
Run Code Online (Sandbox Code Playgroud)

替换为[*]您的数据.您可以将它用作gdb脚本(因此sleep在第一行中)或在gdb命令行中输入它.可选目录行告诉它将本地源目录添加到源的搜索路径.如果您使用指向源代码的前端,这将非常有用.


Moh*_*zim 5

远程调试时,gdb客户端不知道从何处加载符号。您有两种选择:

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) contnue
 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) contnue
 it should break at main
(gdb) bt
Run Code Online (Sandbox Code Playgroud)

PS:确保已使用调试符号编译了可执行文件 -g -O0