如何在 GDB 工具中使用 actions 命令?
How to use actions command in GDB tool?
下面是我用来理解 gdb 中的动作命令的代码。
#include <stdio.h>
int Use_Action(int CatchedInt, char * CatchedStr)
{
printf("CatchedInt = %d, CatchedStr = %s\n", CatchedInt, CatchedStr);
return 0;
}
int main(void)
{
int PassingInt = 20;
char PassingStr[10] = "Hello";
Use_Action(PassingInt, PassingStr);
}
在 GDB 工具中,我在 https://sourceware.org/gdb/current/onlinedocs/gdb/Tracepoint-Actions.html
的帮助下完成了以下操作
(gdb) trace Use_Action
Tracepoint 1 at 0x1169: file action.c, line 5.
(gdb) info tracepoints
Num Type Disp Enb Address What
1 tracepoint keep y 0x0000000000001169 in Use_Action at action.c:5
not installed on target
(gdb) actions
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
>collect CatchedInt
>end
(gdb) info tracepoints
Num Type Disp Enb Address What
1 tracepoint keep y 0x0000000000001169 in Use_Action at action.c:5
collect CatchedInt
not installed on target
如果我通过命令 collect Catchedint 收集了 "Catchedint" 的值,那么如何显示该值。我错过了什么吗?或者我理解错了这个动作命令!!?
Is there something I missed?
是:您需要在收集跟踪时实际 运行 程序,使用 tstart
、run
和 tstop
命令。
如果您尝试这样做,您可能会收到此错误:
(gdb) tstart
You can't do that when your target is `exec'
那是因为只有一些目标支持跟踪点,而本地执行不支持。您需要改用 gdbserver
。
下面是我用来理解 gdb 中的动作命令的代码。
#include <stdio.h>
int Use_Action(int CatchedInt, char * CatchedStr)
{
printf("CatchedInt = %d, CatchedStr = %s\n", CatchedInt, CatchedStr);
return 0;
}
int main(void)
{
int PassingInt = 20;
char PassingStr[10] = "Hello";
Use_Action(PassingInt, PassingStr);
}
在 GDB 工具中,我在 https://sourceware.org/gdb/current/onlinedocs/gdb/Tracepoint-Actions.html
的帮助下完成了以下操作(gdb) trace Use_Action
Tracepoint 1 at 0x1169: file action.c, line 5.
(gdb) info tracepoints
Num Type Disp Enb Address What
1 tracepoint keep y 0x0000000000001169 in Use_Action at action.c:5
not installed on target
(gdb) actions
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
>collect CatchedInt
>end
(gdb) info tracepoints
Num Type Disp Enb Address What
1 tracepoint keep y 0x0000000000001169 in Use_Action at action.c:5
collect CatchedInt
not installed on target
如果我通过命令 collect Catchedint 收集了 "Catchedint" 的值,那么如何显示该值。我错过了什么吗?或者我理解错了这个动作命令!!?
Is there something I missed?
是:您需要在收集跟踪时实际 运行 程序,使用 tstart
、run
和 tstop
命令。
如果您尝试这样做,您可能会收到此错误:
(gdb) tstart
You can't do that when your target is `exec'
那是因为只有一些目标支持跟踪点,而本地执行不支持。您需要改用 gdbserver
。