Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

view contents of a dynamic array in xcode C++ (lldb)

How to view the contents of a dynamically created array in xcode debugger (C++)?

int main(int argc, const char * argv[])
{
int *v;
int size;
cout << "Enter array size" << endl;
cin >> size;
v = new int [size];
for (int i=0; i<size; i++){
    cin >> v [size];
}
// see array contents
return 0;
}

I want to view contents of v.

like image 984
user1673892 Avatar asked Oct 12 '13 00:10

user1673892


1 Answers

We didn't add some syntax in the expression parser like the gdb "@" syntax because we want to keep the language syntax as close to C/ObjC/C++ as possible. Instead, since the task you want to perform is "read some memory as an array of N elements of type T", you would do this using:

(lldb) memory read -t int -c `size` v

In general, -t tells the type, and -c the number of elements, and I'm using the fact that option values in back ticks are evaluated as expressions and the result substituted into the option.

like image 152
Jim Ingham Avatar answered Oct 02 '22 23:10

Jim Ingham