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

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.

Leave a Comment