簡體   English   中英

gdb 找不到庫的源文件

[英]gdb cannot find source file of libarary

我想在gdb使用標准庫進行調試。 我用參數-d運行gdb來指定標准庫的源文件。

$ gdb ./test -d /usr/src/glibc/glibc-2.27/

測試.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.cstrtol.c並且庫有調試信息。

為什么gdb不能搜索/usr/src/glibc/glibc-2.27/下的目錄來找出stdlib/strtol.c

也許原因是如果你加入兩個路​​徑/usr/src/glibc/glibc-2.27/../stdlib/strtol.c你會得到路徑/usr/src/glibc/stdlib/strtol.c ,但不是預期路徑/usr/src/glibc/glibc-2.27/stdlib/strtol.c ../stdlib/strtol.c之所以存放在調試信息中,很可能是使用了構建目錄/build/glibc-OTsEL5/glibc-2.27/build ,而../stdlib/strtol.c是相對的構建目錄的路徑。

運行解決方案之一

$ gdb ./test -d /usr/src/glibc/glibc-2.27/stdlib/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM