View array in LLDB: equivalent of GDB's '@

2019-01-10 01:19发布

I would like to view an array of elements pointed to by a pointer. In GDB this can be done by treating the pointed memory as an artificial array of a given length using the operator '@' as

*pointer @ length

where length is the number of elements I want to view.

The above syntax does not work in LLDB supplied with Xcode 4.1.

Is there any way how to accomplish the above in LLDB?

8条回答
倾城 Initia
2楼-- · 2019-01-10 01:48

The only way I found was via a Python scripting module:

""" File: parray.py """
import lldb
import shlex

def parray(debugger, command, result, dict):
    args = shlex.split(command)
    va = lldb.frame.FindVariable(args[0])
    for i in range(0, int(args[1])):
        print va.GetChildAtIndex(i, 0, 1)

Define a command "parray" in lldb:

(lldb) command script import /path/to/parray.py
(lldb) command script add --function parray.parray parray

Now you can use "parray variable length":

(lldb) parray a 5
(double) *a = 0
(double) [1] = 0
(double) [2] = 1.14468
(double) [3] = 2.28936
(double) [4] = 3.43404
查看更多
做自己的国王
3楼-- · 2019-01-10 01:48

Well at that point, you may as well write your own custom C function and invoke it with:

call (int)myprint(args)
查看更多
登录 后发表回答