通过gdb用户定义的命令返回一个值 [英] Return a value via a gdb user-defined command
问题描述
我正在调试一个核心文件,所以我没有任何运行任何活动进程。
我使用gdb用户定义的命令检查核心文件中的一堆数据,并尝试使用用户定义的命令简化进程。
然而,我找不到一种方法来让用户定义命令返回可用于其他命令的值。
例如:
(注意return行的注释)
define dump_linked_list
set $ node = global_list-> head
set $ count = 1
while $ node!= 0
printf%p - >,$ node
set $ node = $ node-> next
set $ count = $ count + 1
end
return $ count ## GDB不理解此返回
结束
理想情况下,我的dump_linked_list命令将返回列表中找到的节点数,以便可以在另一个已定义的com中使用它mand:
define higher_function
set $ total_nodes = dump_linked_list
printf总节点数为%d \ n,$ total_nodes
end
gdb命令中可能会出现这种情况?
我觉得它一定是,但我一直在搜索文档,找不到任何提及它或任何示例。 b $ b
据我所知,GDB没有这样的功能。您可以设置一个您知道的某个名称的变量,并将其用作返回值。例如,总是像下面这样设置变量 retval :
set $ retval =<任意值>
然后,所有新定义的函数都可以将它用作以前调用函数的返回值。我知道这只是解决方法,但它相对简单,它的工作原理。
I'm debugging with a core-file, so I have no active process in which to run anything.
I'm using gdb user-defined commands to inspect a bunch of data from the core file, and attempting to simplify the process using user-defined commands.
However, I cannot find a way to make the user-defined commands return values which could be used in other commands.
For example:
(note the comment on the "return" line)
define dump_linked_list
set $node = global_list->head
set $count = 1
while $node != 0
printf "%p -->", $node
set $node = $node->next
set $count = $count + 1
end
return $count ## GDB doesn't understand this return
end
Ideally, my dump_linked_list command would return the number of nodes found in the list, so that it could be used in another defined command:
define higher_function
set $total_nodes = dump_linked_list
printf "Total Nodes is %d\n", $total_nodes
end
Is such a thing possible in gdb commands?
I feel it must be, but I've been searching documentation and cannot find a mention of it, or any examples.
As far as I know GDB does not have such a functionality. You can set a variable of some name that you know and use it as a "return" value. For example always set the variable retval like this:
set $retval = <whatever value>
Then all your newly defined functions can use it as a return value from previously called functions. I know this is only workaround, but it is relatively simple and it works.
这篇关于通过gdb用户定义的命令返回一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!