GDB define命令:print$arg1不';t在“定义”中打印正确的值
我想定义一个新命令,它基本上在一行上设置一个断点,打印某个变量的值,然后继续执行。不幸的是,我有问题。这是我正在使用的代码GDB define命令:print$arg1不';t在“定义”中打印正确的值,gdb,gdbinit,Gdb,Gdbinit,我想定义一个新命令,它基本上在一行上设置一个断点,打印某个变量的值,然后继续执行。不幸的是,我有问题。这是我正在使用的代码 (gdb) define print_and_continue Type commands for definition of "print_and_continue". End with a line saying just "end". >break $arg0 >command $bpnum >print $arg1 >continue
(gdb) define print_and_continue
Type commands for definition of "print_and_continue".
End with a line saying just "end".
>break $arg0
>command $bpnum
>print $arg1
>continue
>end
>end
所以我想打印变量len
的值,它在链接列表中定义。h:109
。我执行以下代码:
(gdb) print_and_continue linked_list.h:111 len
Breakpoint 1 at 0x388a: linked_list.h:111. (12 locations)
(gdb) r
...
Breakpoint 1, linked_list<test_struct<1>, 1>::remove_if<run_test<1, 1, 1>(std::vector<int, std::allocator<int> >&)::{lambda(test_struct<1> const&)#1}>(run_test<1, 1, 1>(std::vector<int, std::allocator<int> >&)::{lambda(test_struct<1> const&)#1}&&) (this=0x7fffffffdca0, condition=...) at linked_list.h:112
112 linked_list_node* prev = nullptr;
$1 = void
(gdb)打印并继续链接列表。h:111 len
断点1位于0x388a:链接列表。h:111。(12个地点)
(gdb)r
...
断点1,链接列表::删除链接列表处的if(运行测试(std::vector&):{lambda(测试结构常数&)}&(this=0x7fffffffdca0,条件=…)。h:112
112链接列表节点*prev=nullptr;
$1=无效
似乎print
函数中的$arg1
没有被实际参数替换。我做错了什么
打印函数中的$arg1似乎没有被实际参数替换
我不相信这是事实。相反,命令$bpnum
后面的所有内容都会直接附加到新创建的断点上(没有任何扩展)。您可以在info break
中看到这种情况,它将显示如下内容:
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000001136 at ...
print $arg1
continue
这通常是您想要的(将对参数的求值推迟到到达断点的时间)。否则,如果使用print len
,当您想要打印断点时len
的值时,您将打印len
的当前值
当然,当遇到断点时,周围没有$arg1
(或$arg0
)任何地方,因此您将获得与打印任何其他不存在的GDB变量相同的输出
我做错了什么
您使用的是“快速破解语言”(即“本机”GDB脚本语言),而不是使用正确的编程语言
我99.99%确信定义print\u和\u continue
是可能的(而且可能相当容易)使用
也就是说,我不相信print\u and\u continue
有那么多用处(在我使用GDB的20多年中,我从未需要过这样的东西)