lldb python basic-在函数的断点内时打印全局数组的值 [英] lldb python basic - print value of a global array while inside a breakpoint in a function

查看:98
本文介绍了lldb python basic-在函数的断点内时打印全局数组的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(某些背景:我对lldb或python并不熟悉,并且不经常使用它们,但目前需要制作一些基本脚本来调试iphone程序)

(Some background: I am not experienced with lldb or python and don't work on them frequently, but currently need to make some basic scripts for debugging an iphone program)

我目前在函数的断点处停止,并想检查已在此函数内部访问的数组的值

I am currently stopped at a breakpoint in side a function, and want to check the value of an array that has been accessed inside this function

此数组声明为

Float32 my_array[128];  

并具有全球范围.我可以使用print命令查看数组,但我想制作一个python脚本,以便可以更好地控制输出格式,并可以稍后使用matplolib将数组元素绘制为图形.

and has global scope. I can view the array using print command, but I would like to make a python script so that I have more control over the output formatting and possibly plot the array elements as a graph using matplolib later on.

我正在查看示例python代码给出的问题,并使用给定的python验证了可以在此函数中查看局部变量(当前我在断点处停止).例如,如果我将base=frame.FindVariable('base')中的'base'更改为我的局部变量'k'(局部变量不是数组),

I am looking at the sample python code given in this question, and using the python given there I have verified that I can view local variables in this function (where currently I am stopped at a break point). For example, if I change 'base' in base=frame.FindVariable('base') to my local variable 'k' (the local variable is not an array) ,

base=frame.FindVariable('k')  

然后print base我可以看到k的值.但是,如果我尝试这样做,

then print base I can see the value of k. However, if I try this,

base=frame.FindVariable('my_array')   

然后执行print base,它给了我No value.如何编写python命令以获取当前作用域中任何类型的变量的值?优选地,它适用于普通变量(int,float),数组和指针,但如果不是,则此时查找数组的值更为重要.

and do print base it gives me No value. How can I write a python command to get the values of any kind of variable currently in scope? Preferably it works for normal variables (int, float), arrays, and pointers, but if not, finding values of arrays are more important at the moment.

推荐答案

SBFrame.FindVariable在该框架局部变量中搜索.它不在全局变量中搜索.

SBFrame.FindVariable searches among the variables local to that frame. It doesn't search among the global variables.

为此,您需要使用范围更广的搜索.如果您知道全局变量位于包含框架代码的二进制图像中-lldb将该二进制图像称为Module-那么您可以找到包含该框架的模块并使用SBModule.FindGlobalVariables.如果不是这样,则可以使用SBTarget.FindGlobalVariables搜索整个目标.如果您知道该名称只有一个全局变量,则可以使用FindFirstGlobalVariable变体.

For that you need to use a search with a wider scope. If you know that the global variable is in the binary image containing the your frame's code - lldb calls that binary image a Module - then you can find the module containing that frame and use SBModule.FindGlobalVariables. If that's not true, you can search the whole target using SBTarget.FindGlobalVariables. If you know that only one global variable of that name exists, you can use FindFirstGlobalVariable variant.

所有这些命令将查找任何类型的变量,并且它们都一致地返回SBValue,因此无论您如何查找它们,都可以以一致的方式设置它们的格式.对于静态分配的数组,数组元素是其子元素,因此您可以使用SBValue.GetChildAtIndex获取单个元素.

All these commands will find variables of any type, and they all consistently return SBValues so you can format them in a consistent manner regardless of how you find them. For statically allocated arrays, the array elements are its children, so you can fetch individual elements with SBValue.GetChildAtIndex.

您可以进入SBFrame的模块,例如:

You can get to a SBFrame's module like:

module = frame.module

及其目标:

target = frame.thread.process.target

lldb分隔了主要为了提高效率而在其中搜索变量的上下文.如果SBFrame.FindVariable搜索全局变量和局部变量,则错误键入的变量名将是代价高得多的错误.但这也使调用更加可预测,因为您将永远不会从系统代表您加载的某些共享库中获得随机的全局信息.

lldb separates the contexts in which to search for variables primarily for efficiency. If SBFrame.FindVariable searched for globals as well as locals, a mistyped variable name would be a much more expensive mistake. But it also makes the call more predictable since you will never get some random global from some shared library that the system loaded on your behalf.

这篇关于lldb python basic-在函数的断点内时打印全局数组的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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