GDB without stepping into STL and all other libraries in /usr:
Put the following in your .gdbinit
file. It searches through the sources that gdb has loaded or will potentially load (gdb command info sources
), and skips them when their absolute path starts with "/usr". It's hooked to the run
command, because symbols might get reloaded when executing it.
# 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
To check the list of files to be skipped, set a breakpoint somewhere (e.g., break main
) and run gdb (e.g., run
), then check with info sources
upon reaching the breakpoint:
(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
...
Its easy to extend this to skip other directories as well by adding a call to SkipDir(<some/absolute/path>)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…