Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View array in LLDB: equivalent of GDB's '@' operator in Xcode 4.1

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?

like image 834
midinastasurazz Avatar asked Aug 15 '11 06:08

midinastasurazz


1 Answers

There are two ways to do this in lldb.

Most commonly, you use the parray lldb command which takes a COUNT and an EXPRESSION; EXPRESSION is evaluated and should result in a pointer to memory. lldb will then print COUNT items of that type at that address. e.g.

parray 10 ptr 

where ptr is of type int *.

Alternatively, it can be done by casting the pointer to a pointer-to-array.

For example, if you have a int* ptr, and you want to view it as an array of ten integers, you can do

p *(int(*)[10])ptr 

Because it relies only on standard C features, this method works without any plugins or special settings. It likewise works with other debuggers like GDB or CDB, even though they also have specialized syntaxes for printing arrays.

like image 180
Siyuan Ren Avatar answered Sep 20 '22 00:09

Siyuan Ren