GDB沒有步入STL和所有其他庫在/ usr:
把你.gdbinit
文件以下。它搜索通過GDB已加載或將可能加載(GDB命令info sources
)的源,並且當它們的絕對路徑以「/ USR」開始跳過它們。它掛鉤了run
命令,因爲符號在執行時可能會重新加載。
# skip all STL source files
define skipstl
python
# get all sources loadable by gdb
def GetSources():
sources = []
for line in gdb.execute('info sources',to_string=True).splitlines():
if line.startswith("/"):
sources += [source.strip() for source in line.split(",")]
return sources
# skip files of which the (absolute) path begins with 'dir'
def SkipDir(dir):
sources = GetSources()
for source in sources:
if source.startswith(dir):
gdb.execute('skip file %s' % source, to_string=True)
# apply only for c++
if 'c++' in gdb.execute('show language', to_string=True):
SkipDir("/usr")
end
end
define hookpost-run
skipstl
end
要檢查的文件列表被跳過,設置斷點的地方(例如,break main
)和運行GDB(例如,run
),然後用info sources
在到達斷點檢查:
(gdb) info skip
Num Type Enb What
1 file y /usr/include/c++/5/bits/unordered_map.h
2 file y /usr/include/c++/5/bits/stl_set.h
3 file y /usr/include/c++/5/bits/stl_map.h
4 file y /usr/include/c++/5/bits/stl_vector.h
...
它易於擴展通過增加一個呼叫SkipDir(<some/absolute/path>)
跳過其他目錄也是如此。
這個怎麼樣?:http://stackoverflow.com/questions/1133365 – 0xC0000022L 2011-06-02 21:14:14
@STATUS,謝謝。這個問題聽起來像是不可能的,至少是自動的,除非目標代碼和動態庫代碼之間存在差異。 – Chance 2011-06-06 14:39:16