lldb python basic - print value of a global array while inside a breakpoint in a function

前端 未结 1 1801
故里飘歌
故里飘歌 2020-12-21 17:29

(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)

相关标签:
1条回答
  • 2020-12-21 17:53

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

    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.

    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.

    You can get to a SBFrame's module like:

    module = frame.module
    

    and its target:

    target = frame.thread.process.target
    

    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.

    0 讨论(0)
提交回复
热议问题