如何在使用 GDB 遍历代码时禁用 C++ 模板的步进? [英] How to disable stepping in C++ template while walking thru code using GDB?

查看:39
本文介绍了如何在使用 GDB 遍历代码时禁用 C++ 模板的步进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 GDB 遍历代码,而 GDB 总是试图显示 C++ 模板源代码,这使得调试不方便并浪费了我很多时间.

GDB 尝试介入该函数,但在找不到实现模板的文件时显示错误,或者跳转到我不想看到的模板代码中.

我找不到如何禁用显示/单步进入容器或模板源代码的方法.我想直接跨过去,但我不知道该功能是否可用.

是否可以在使用 GDB 进行调试时禁用步入模板?当我跨过前任.make_unique 函数,我希望 GDB 不会试图显示 make_unique 实现.有什么建议吗?

解决方案

skip 就是你想要的.您可以跳过函数或文件.

如果你进入一些不需要的代码,你可以使用skip this跳过你刚刚进入的函数或skip file跳过它所在的文件.

您也可以随时使用 skip function_nameskip filename 并在几个字符后按 TAB 将使 gdb 完成名称你.

也可以分别使用正则表达式或 glob 文件模式指定函数名或文件名.

对于您总是想跳过的常见事情,您应该将跳过命令添加到您的主文件夹中的 .gdbinit 文件中.例如,我的 .gdbinit 中有以下代码.

#进入时跳过Catch库函数跳过 -rfu 捕捉跳过 -rfu _catch_sr# 跳过 std 命名空间中的所有内容跳过 -rfu ^std::跳过 -rfu ^gsl::# 跳过 SFML 工作区中的所有内容跳过 -rfu ^sf::跳过 -rfu ^arma::跳过 -rfu ^胶水

使用正则表达式,这意味着 gdb 将跳过 std 命名空间中的任何内容以及我经常使用的其他一些库中的任何内容,例如 catch犰狳等>

对于 glob 模式,你可以做一些事情,比如

skip -gfile/usr/include/c++/9.1.0/bits/*

不幸的是,glob 模式似乎无法处理诸如某个文件夹的任何子文件夹中的任何文件"之类的事情.如果 gdb 允许诸如

之类的东西,那将非常有用

skip -gfile/home/myuser/.conan/**/*

例如从 .conan 文件夹中跳过子文件夹中的任何文件.此文件夹是 conan 包管理器安装库的位置.然后使用单个 skip 命令 gdb 将不会进入任何外部库代码.

I am trying to walk thru code using GDB, and GDB always tries to show C++ templates source code which makes debugging inconvenient and wastes lots of my time.

GDB tries to step in the function and it shows an error when it can't find files where templates are implemented, or it jumps into template code which I don't want to see.

I couldn't find a method of how to disable showing/stepping into container or template source code. I want to just step over, but I don't know if that feature is available.

Is it possible to disable step into template while debugging with GDB? When I step over for ex. make_unique function, I expect GDB to not trying to show make_unique implementation. Any suggestion?

解决方案

skip is what you want. You can skip functions or files.

If you step into some unwanted code you can use skip this to skip the function you just step into or skip file to skip the file where it is.

At any moment you can also use skip function_name or skip filename and pressing TAB after a few characters will make gdb complete the name for you.

It is also possible so specify function names or file names using a regular expressions or a glob file pattern, respectively.

For common things you always want to skip you should add the skip commands to the .gdbinit file in your home folder. For instance, I have the code below in my .gdbinit.

# Skip the Catch library functions  when stepping into
skip -rfu Catch
skip -rfu _catch_sr

# Skip everything from the std namespace
skip -rfu ^std::
skip -rfu ^gsl::
# Skip everything in SFML workspace
skip -rfu ^sf::
skip -rfu ^arma::
skip -rfu ^Glue

With regular expressions, it means gdb will skip anything in the std namespace as well from a few other libraries I use regularly, such as catch, armadillo, etc.

For the glob pattern you could do something such as

skip -gfile /usr/include/c++/9.1.0/bits/*

Unfortunately, the glob pattern does not seem to handle something such as "any file in any subfolder of some folder". It would be very useful if gdb allowed something such as

skip -gfile /home/myuser/.conan/**/*

to skip any file in a subfolder from the .conan folder, for instance. This folder is where the conan package manager installs the libraries. Then with a single skip command gdb would not step into any external library code.

这篇关于如何在使用 GDB 遍历代码时禁用 C++ 模板的步进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆