获取所有的全局变量/局部变量在GDB的Python接口 [英] Get all global variables/local variables in gdb's python interface

查看:631
本文介绍了获取所有的全局变量/局部变量在GDB的Python接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经学会了扔读<一个href=\"http://stackoverflow.com/questions/6261392/printing-all-global-variables-local-variables\">Printing所有全局变量/局部变量中,我们可以得到当前帧的所有变量在GDB的命令行。

I have learned throw reading Printing all global variables/local variables that we can get all variables of the current frame in gdb's command line.

我的问题是如何获得当前帧的所有变量在GDB的Python接口,因为信息当地人只是给字符串中的结果,这就是不便于进一步使用。

My question is how to get all variables of the current frame in the gdb's python interface, since info locals just give results in strings and that's not convenient for further use.

推荐答案

有没有问题的变化?我不知道,但我怀疑如此,因为我的previous答案是非常错误的。我依稀记得,所用的问题是关于全球的变量,在这种情况下,这是真实的:

Did the question change? I'm not sure, but I suspect so since my previous answer is very wrong. I vaguely recall that the question used to be about global variables, in which case this is true:

我不认为有一种方法。 GDB符号表仅部分暴露于Python的,我相信缺乏迭代他们的能力是洞之一。

I don't think there is a way. GDB symbol tables are only partially exposed to Python, and I believe the lack of an ability to iterate over them is one of the holes.

然而,很容易遍历的本地的Python的变量。您可以使用 gdb.selected_frame()来获得所选择的框架。然后,从框架,你可以使用块()方法来获得阻止对象。

However, it is easy to iterate over the local variables from Python. You can use gdb.selected_frame() to get the selected frame. Then, from the frame you can you use the block() method to get the Block object.

A 阻止对象重新presents一个范围。您可以遍历阻止直接得到该范围的变量。然后,使用 Block.superblock 上去范围。当你打了函数属性块,你打功能的最外面的范围。

A Block object represents a scope. You can iterate over the Block directly to get the variables from that scope. Then, go up a scope using Block.superblock. When you hit a block with a function attribute, you've hit the outermost scope of the function.

这篇关于获取所有的全局变量/局部变量在GDB的Python接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆