user1673892
user1673892

Reputation: 409

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.

Upvotes: 10

Views: 11086

Answers (2)

Nyon
Nyon

Reputation: 49

There is a better answer over at another thread.

https://stackoverflow.com/a/26303375/767039

I think this is easier to use and remember.

Upvotes: 0

Jim Ingham
Jim Ingham

Reputation: 27110

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.

Upvotes: 16

Related Questions