主题行基本上都说明了一切.
如果我根据文件和行号给出位置,则在编辑文件时该值可能会更改.事实上,如果我在重构期间编辑多个函数,它往往会经常变化并且不方便.但是,如果相对于函数的开头是(line-),它就不太可能改变.
如果不能从函数的开头给出行偏移量,那么是否可以使用便利变量来模拟它?即如果我将声明方便变量映射到特定函数的开头(我会不断更新的列表)?
根据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.
Run Code Online (Sandbox Code Playgroud)
这是一个长期要求将此添加到gdb.但是,它现在不存在.使用Python可能有点可能,但也许并不完全,因为Python目前无法访问所有断点重置事件(因此断点可能只运行一次,但不会重新运行或库加载或其他一些劣质更改).
但是,引用的文本显示了一种更好的方式 - 使用探测点.这些是所谓的"SystemTap探测点",但实际上它们更像是通用的ELF + GCC功能 - 它们来自SystemTap项目,但不依赖于它.这些允许您在源中标记一个点并轻松地在其上放置断点,而不管源的其他编辑.它们已经在Linux发行版中用于标记unwinder和longjump运行时例程中的特殊位置,以便在存在这些例程时很好地进行调试.