Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

c++ - Viewing a dynamically-allocated array with the Xcode debugger?

Let's say I have an array in C++:

double* velocity = new double[100];

Using the GDB command line, I can view this array with the command:

> print *velocity @ 100

and it will print a nicely-formatted list of all the double values inside the array.

However, when using the Xcode debugger, the most it will do is treat this as a pointer to a single double value, and display velocity[0] in the variable list.

This makes it a real PITA to debug programs that contain large dynamically allocated array. There has got to be some way to tell Xcode "This is a pointer to an array of length 100", and have it display the thing as such. Anyone know what it is?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think that my answer will be a good addition for the old one.

New versions of Xcode use lldb debugger as default tool instead of gdb.

According this page:

With the release of Xcode 5, the LLDB debugger becomes the foundation for the debugging experience on OS X.

So for Xcode since version 5 and up I use this lldb command:

memory read -t int -c8 `array_name`

where:
8 - the number of elements in array
array_name - the name of array
int - the type of array

The result of execution of this command will be something like this:

(lldb) memory read -t int -c8 array
(int) 0x7fff5fbff870 = 7
(int) 0x7fff5fbff874 = 6
(int) 0x7fff5fbff878 = 9
(int) 0x7fff5fbff87c = 10
(int) 0x7fff5fbff880 = 1
(int) 0x7fff5fbff884 = 8
(int) 0x7fff5fbff888 = 4
(int) 0x7fff5fbff88c = 3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...