gdb - 在 GDB 中,是否可以从函数的开头给出一个相对地址(以行为单位)?

标签 gdb breakpoints

主题行基本上说明了一切。

如果我根据文件和行号给出位置,那么如果我编辑文件,该值可能会更改。事实上,如果我在重构期间编辑多个函数,它往往会经常以不方便的方式更改。但是,如果它是(行)相对于函数的开头,则不太可能改变。

如果无法从函数的开头给出行偏移量,那么是否可以使用便利变量来模拟它? IE。如果我要声明映射到特定函数开头的便利变量(我会不断更新的列表)?

根据 help break两者似乎都不可用,但我想我最好问一下。

(gdb) help break
Set breakpoint at specified line or function.
break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]
PROBE_MODIFIER shall be present if the command is to be placed in a
probe point.  Accepted values are `-probe' (for a generic, automatically
guessed probe type) or `-probe-stap' (for a SystemTap probe).
LOCATION may be a line number, function name, or "*" and an address.
If a line number is specified, break at start of code for that line.
If a function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no LOCATION, uses current execution address of the selected
stack frame.  This is useful for breaking on return to a stack frame.

THREADNUM is the number from "info threads".
CONDITION is a boolean expression.

Multiple breakpoints at one place are permitted, and useful if their
conditions are different.

Do "help breakpoints" for info on other commands dealing with breakpoints.

最佳答案

将它添加到 gdb 是一个长期的请求。但是,它现在不存在。 Python 可能有点可能,但可能不完全,因为 Python 当前无法访问所有断点重置事件(因此断点可能会工作一次,但不会在重新运行或库加载或其他一些劣质更改时起作用) )。

但是,引用的文本显示了一种更好的方法——使用探测点。这些是所谓的“SystemTap 探测点”,但实际上它们更像是一个通用的 ELF + GCC 功能——它们源自 SystemTap 项目但不依赖于它。这些使您可以在源中标记一个点并轻松地在其上放置断点,而不管对源的其他编辑如何。它们已经在 linux 发行版中用于标记 unwinder 和 longjump 运行时例程中的特殊位置,以便在存在这些时很好地进行调试。

关于gdb - 在 GDB 中,是否可以从函数的开头给出一个相对地址(以行为单位)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24748924/

相关文章:

c++ - Eclipse cdt,gdb 异常 cygwin_exception::open_stackdumpfile

成员函数的 C++ GDB 断点

c# - 多线程:防止 Visual Studio 阻塞特定线程

php - Netbeans PHP 断点变量值 "Evaluating..."

c++ - 在 gdb 调试器中打印 __m128 数据类型的值

c++ - gdb 共享库中的错误文件名

c - 使用 MinGW 的 C 中的段错误

java - eclipse中跳过所有断点的快捷键

iOS应用程序运行断点