【问题标题】:GDB grep info sources filesGDB grep 信息源文件
【发布时间】:2017-01-31 19:00:36
【问题描述】:

是否可以在 gdb 中对信息源的输出进行 grep 或过滤? 比如:

(gdb) info sources | grep bob.cpp

谢谢

【问题讨论】:

    标签: gdb


    【解决方案1】:

    是否可以在 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

    【讨论】:

    • 有没有办法在不滚动整个文件列表的情况下登录到 gdb.txt?一旦我退出滚动浏览info sources,gdb 将停止登录gdb.txt
    猜你喜欢
    • 2010-11-19
    • 1970-01-01
    • 2014-07-22
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    相关资源
    最近更新 更多