【发布时间】:2020-07-06 19:05:57
【问题描述】:
我想使用gdb 中的标准库进行调试。
我用参数-d 运行gdb 来指定标准库的源文件。
$ gdb ./test -d /usr/src/glibc/glibc-2.27/
test.cpp:
#include<iostream>
#include<string>
using namespace std;
int main(){
string hex("0x0010");
long hex_number = strtol(hex.c_str(), NULL, 16);
cout << hex_number << endl;
return 0;
}
但是,gdb 告诉我找不到源文件strtol.c。
(gdb) b 8
Breakpoint 1 at 0xc8c: file /home/purin/Desktop/CodeWork/adv_unix_programming/hw1/test.cpp, line 8.
(gdb) run
Starting program: /home/purin/Desktop/CodeWork/adv_unix_programming/hw1/test
Breakpoint 1, main () at /home/purin/Desktop/CodeWork/adv_unix_programming/hw1/test.cpp:8
8 long hex_number = strtol(hex.c_str(), NULL, 16);
(gdb) s
__strtol (nptr=0x7fffffffd820 "0x0010", endptr=0x0, base=16) at ../stdlib/strtol.c:106
106 ../stdlib/strtol.c: file or directory does not exits
(gdb) info source
Current source file is ../stdlib/strtol.c
Compilation directory is /build/glibc-OTsEL5/glibc-2.27/stdlib
Source language is c.
Producer is GNU C11 7.3.0 -mtune=generic -march=x86-64 -g -O2 -O3 -std=gnu11 -fgnu89-inline -fmerge-all-constants -frounding-math -fstack-protector-strong -fPIC -ftls-model=initial-exec -fstack-protector-strong.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info.
如果我执行这个命令,gdb 可以找到源代码:
(gdb) dir /usr/src/glibc/glibc-2.27/stdlib/
我确定我在路径/usr/src/glibc/glibc-2.27/stdlib/strtol.c 中有strtol.c,并且库有调试信息。
为什么gdb无法搜索/usr/src/glibc/glibc-2.27/下的目录找到stdlib/strtol.c?
【问题讨论】:
-
看看这是否有效(来自GDB complaining about missing raise.c):
set substitute-path /build/glibc-OTsEL5/glibc-2.27 /usr/src/glibc/glibc-2.27