【发布时间】:2017-01-31 19:00:36
【问题描述】:
是否可以在 gdb 中对信息源的输出进行 grep 或过滤? 比如:
(gdb) info sources | grep bob.cpp
谢谢
【问题讨论】:
标签: gdb
是否可以在 gdb 中对信息源的输出进行 grep 或过滤? 比如:
(gdb) info sources | grep bob.cpp
谢谢
【问题讨论】:
标签: gdb
是否可以在 gdb 中对信息源的输出进行 grep 或过滤?
更新:
是的。截至提交 ae60f04e08bf(GDB 版本 9 及更高版本)info sources 可以接受正则表达式和其他参数。来自help info sources:
All source files in the program or those matching REGEXP.
Usage: info sources [OPTION]... [REGEXP]
By default, REGEXP is used to match anywhere in the filename.
Options:
-dirname
Show only the files having a dirname matching REGEXP.
-basename
Show only the files having a basename matching REGEXP.
旧答案:
没有。这可能被认为是一个错误:info shared 采用可选的正则表达式来过滤共享库,但 info sources 没有。
解决方法:
(gdb) set logging on # GDB output will now be copied into gdb.txt
(gdb) info sources
(gdb) set logging off
(gdb) shell grep bob.cpp gdb.txt
(gdb) shell rm gdb.txt
如果您需要经常这样做,您可以将上述命令放入user-defined command。
【讨论】:
info sources,gdb 将停止登录gdb.txt。