告诉gdb跳过标准文件

| 我正在用GDB调试C ++代码,当它进入包含标准库对象的某些对象的构造函数时,它向我显示了这些对象的构造函数(如
std::map
)及其下的所有内容。 我知道
next
运算符,但是我更愿意将所有标准库代码都列入黑名单,这绝不是我正在研究的错误的根源。理想的行为是简单的“ 2”将把我发送到下一个“用户名”代码。     
已邀请:
  * GDB 7.4中的更改         现在,当使用\“ skip function \”和\“ skip file \”命令步进时,GDB允许您跳过不重要的功能和文件。        
gdb 7.12支持文件遍历以指定要在调试器中跳过的文件。相同的文档如下: https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html 要跳过单步进入目录/ usr / include / c ++ / 5 / bits中的所有库标头,请将以下行添加到〜/ .gdbinit中
# To skip all .h files in /usr/include/c++/5/bits
skip -gfi /usr/include/c++/5/bits/*.h
而不是跳过特定文件,例如stl_vector.h,将以下行添加到〜/ .gdbinit
# To skip the file /usr/include/c++/5/bits/stl_vector.h
skip file /usr/include/c++/5/bits/stl_vector.h
使用gdb 7.11和以下版本执行上述操作会导致以下错误:
Ignore function pending future shared library load? (y or [n]) [answered N; input not from terminal]
但是,gdb 7.12似乎已经解决了上述问题。 对于gdb 7.11或更低版本,此博客解决了相同的问题。 注意-您可以在gdb命令提示符下使用以下命令列出所有标记为跳过的文件
info skip
    
步骤说明并跳过所有无源文件 对于大多数应用程序来说这太慢了,但是很有趣! 基于:显示在gdb中执行的每个汇编指令
class ContinueUntilSource(gdb.Command):
    def __init__(self):
        super().__init__(
            \'cus\',
            gdb.COMMAND_BREAKPOINTS,
            gdb.COMPLETE_NONE,
            False
        )
    def invoke(self, argument, from_tty):
        argv = gdb.string_to_argv(argument)
        if argv:
            gdb.write(\'Does not take any arguments.\\n\')
        else:
            done = False
            thread = gdb.inferiors()[0].threads()[0]
            while True:
                message = gdb.execute(\'si\', to_string=True)
                if not thread.is_valid():
                    break
                try:
                    path = gdb.selected_frame().find_sal().symtab.fullname()
                except:
                    pass
                else:
                    if os.path.exists(path):
                        break
ContinueUntilSource()
已在Ubuntu 16.04,GDB 7.11中测试。 GitHub上游。     
根据Ciro Santilli的回答命令
ss
步骤修改,该步骤位于特定来源内。您可以指定源文件名,否则将步进当前文件名。逐步浏览bison / yacc源或其他生成С代码并插入
#line
指令的元数据源非常方便。
import os.path

class StepSource(gdb.Command):
    def __init__(self):
        super().__init__(
            \'ss\',
            gdb.COMMAND_BREAKPOINTS,
            gdb.COMPLETE_NONE,
            False
        )
    def invoke(self, argument, from_tty):
        argv = gdb.string_to_argv(argument)
        if argv:
            if len(argv) > 1:
                gdb.write(\'Usage:\\nns [source-name]]\\n\')
                return
            source = argv[0]
            full_path = False if os.path.basename(source) == source else True
        else:
            source = gdb.selected_frame().find_sal().symtab.fullname()
            full_path = True
        thread = gdb.inferiors()[0].threads()[0]
        while True:
            message = gdb.execute(\'next\', to_string=True)
            if not thread.is_valid():
                break
            try:
                cur_source = gdb.selected_frame().find_sal().symtab.fullname()
                if not full_path:
                    cur_source = os.path.basename(cur_source)
            except:
                break
            else:
                if source == cur_source:
                    break
StepSource()
已知错误 它在运行时不会中断SIGINT上的调试器; 不确定是否将
pass
更改为ѭ12as。     

要回复问题请先登录注册