是否可以从 GDB 的外部文件中将命令注册到断点?
Is it possible to register commands to a breakpoint from within an external file in GDB?
GDB 允许通过 commands NUM
语法将一组命令注册到特定的断点。我需要通过外部文件为特定断点注册命令集,方法如下:
commands ./main.c:18
silent
print buffer[0]
cont
end
commands ./io.c:29
silent
printf "Hello world %i\n", myvar1
cont
end
commands path/to/file:XX
语法是我编的。因为 commands NUM
语法中的 NUM
需要断点的运行时 ID 号(由 GDB 分配),我不能为此目的使用确定性语法。
我目前正在通过包含以下内容的文本文件注册断点:
break ./main.c:18
break ./io.c:29
然后在 GDB 中发出 source breakpoints.txt
命令。好像没有办法在注册断点的同时注册commands
:
(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),
-probe-stap' (for a SystemTap probe) or
`-probe-dtrace' (for a DTrace 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.
问题
- 有什么简单的方法可以从文件中为预定断点设置一些预定命令吗?
- 如果没有,是否有任何等效的方法将
(gdb) info breakpoints
输出传递给文件或程序,而 pipe
is not available in GDB (version 5.3)? Currently I'm trying a workaround by using logging
功能用于该目的:
set logging file /tmp/breakpoints
set logging on
info breakpoints
set logging off
Is there any easy way to set some predetermined commands for a predetermined breakpoint from within a file?
是:如果您使用 commands
而不使用 NUM
,这些命令将应用于最后一个断点集。所以你想要这样的东西:
break main.c:18
commands
silent
print buffer[0]
cont
end
GDB 允许通过 commands NUM
语法将一组命令注册到特定的断点。我需要通过外部文件为特定断点注册命令集,方法如下:
commands ./main.c:18
silent
print buffer[0]
cont
end
commands ./io.c:29
silent
printf "Hello world %i\n", myvar1
cont
end
commands path/to/file:XX
语法是我编的。因为 commands NUM
语法中的 NUM
需要断点的运行时 ID 号(由 GDB 分配),我不能为此目的使用确定性语法。
我目前正在通过包含以下内容的文本文件注册断点:
break ./main.c:18
break ./io.c:29
然后在 GDB 中发出 source breakpoints.txt
命令。好像没有办法在注册断点的同时注册commands
:
(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),
-probe-stap' (for a SystemTap probe) or `-probe-dtrace' (for a DTrace 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.
问题
- 有什么简单的方法可以从文件中为预定断点设置一些预定命令吗?
- 如果没有,是否有任何等效的方法将
(gdb) info breakpoints
输出传递给文件或程序,而pipe
is not available in GDB (version 5.3)? Currently I'm trying a workaround by usinglogging
功能用于该目的:
set logging file /tmp/breakpoints
set logging on
info breakpoints
set logging off
Is there any easy way to set some predetermined commands for a predetermined breakpoint from within a file?
是:如果您使用 commands
而不使用 NUM
,这些命令将应用于最后一个断点集。所以你想要这样的东西:
break main.c:18
commands
silent
print buffer[0]
cont
end