[英]How to execute a GDB command from a string variable?
Say the debugged process has a string variable as follows: 说调试后的进程具有如下字符串变量:
char* cmd_str = "set confirm on";
How to execute the command from cmd_str
in GDB? 如何在GDB中从cmd_str
执行命令?
(gdb) $cmd = cmd_str
(gdb) ???
You can use gdb's eval
command, which runs printf
on its arguments and then evaluates the result as a command. 您可以使用gdb的eval
命令,该命令在其参数上运行printf
,然后将结果作为命令求值。
(gdb) list
1 #include <stdlib.h>
2 main()
3 {
4 char *a = "set confirm off";
5
6 pause();
7 }
(gdb) break 6
Breakpoint 1 at 0x400540: file cmdtest.c, line 6.
(gdb) run
Starting program: ./cmdtest
Breakpoint 1, main () at cmd.c:6
6 pause();
(gdb) show confirm
Whether to confirm potentially dangerous operations is on.
(gdb) printf "%s", a
set confirm off(gdb)
(gdb) eval "%s", a
(gdb) show confirm
Whether to confirm potentially dangerous operations is off.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.