简体   繁体   English

使用Xcode 5调试动态分配的2D阵列

[英]Debugging Dynamically Allocated 2D Array with Xcode 5

I've the following C code that creates a dynamically allocated 2D array. 我有以下C代码创建一个动态分配的2D数组。

numbersArray = (int **)malloc(sizeof(int *)* primeNumber);

for (i =0 ; i < primeNumber; i++)
    numbersArray[i] = (int *)malloc(sizeof(int)*2);

numbersArray is globally defined and primeNumber is just a number that I calculate during the execution of the program. numbersArray是全局定义的,primeNumber只是我在程序执行期间计算的数字。

My program performs well without problems. 我的程序运行良好,没有问题。 I can do various processes on the array. 我可以在阵列上执行各种处理。 It works totally fine. 它完全正常。

My question is that Xcode 5 doesn't show the contents of numbersArray when debugging. 我的问题是,调试时Xcode 5不显示numbersArray的内容。 It just shows the following: 它仅显示以下内容:

Xcode 5中的调试区域

Why can't it display the dynamically allocated array properly that I would be able to see each and every cell in the array? 为什么它不能正确显示动态分配的数组,使我能够看到数组中的每个单元格?

I checked similar questions before posting this and they talked about dynamic allocation that the compiler isn't aware of the array size(s) until runtime but I think I remember that before(in previous versions of Xcode) I was able to see the contents of a dynamically allocated array. 我在发布之前检查了类似的问题,他们谈到了动态分配,即编译器直到运行时才知道数组的大小,但我想我还记得以前(在Xcode的早期版本中)我可以看到内容动态分配的数组。

What's really going on here? 这到底是怎么回事? Has it been always like this or is it an Xcode 5 thing or maybe I have the configure Xcode? 是一直这样吗,还是Xcode 5,还是我有配置Xcode?

First, please don't cast the return value of malloc() in C . 首先, 请不要在C中malloc()的返回值

Now, I think you mis-remember. 现在,我想你记错了。 Unless it's doing pretty advanced analysis, there should be no way for the debugger to know that an int ** variable should be interpreted as an array of a specific size. 除非进行了相当高级的分析,否则调试器将无法知道int **变量应解释为特定大小的数组。

What you can often do, is use various "view memory as ..."-type commands to inspect the memory. 您通常可以执行的操作是使用各种“将内存查看为...”类型的命令来检查内存。 This will be even more complicated by the fact that your array is "jagged", ie each row is a pointer to that rows's data rather than the entire array being a single contiguous allocation. 由于数组是“锯齿状”的,这将使情况变得更加复杂,即每一行都是指向该行数据的指针,而不是整个数组是一个连续的分配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM