使用 Xcode 调试器查看动态分配的数组?
假设我有一个 C++ 数组:
Let's say I have an array in C++:
double* velocity = new double[100];
使用 GDB 命令行,我可以通过以下命令查看这个数组:
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.
但是,当使用 Xcode 调试器时,它最多会将其视为指向单个双精度值的指针,并在变量列表中显示 velocity[0].
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.
这使它成为调试包含大型动态分配数组的程序的真正 PITA.必须有某种方法来告诉 Xcode这是一个指向长度为 100 的数组的指针",并让它这样显示.有人知道是什么吗?
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?
推荐答案
可以使用gdb语法作为表达式:
You can use gdb syntax as expressions:
- 使用 Run/Show/Expressions... 菜单显示表达式窗口
- 在窗口底部输入
'*velocity @ 100'
(表达式:)
- Use Run/Show/Expressions... menu to show the expressions window
- Enter
'*velocity @ 100'
at the bottom of the window (Expression:)
相关文章