10

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.

user1673892
  • 409
  • 2
  • 5
  • 17

2 Answers2

16

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.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
0

There is a better answer over at another thread.

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

I think this is easier to use and remember.

Community
  • 1
  • 1
Nyon
  • 49
  • 3