简体   繁体   English

在Qt Creator中将指针显示为数组,其中CDB用于调试器

[英]Display pointer as array in Qt Creator with CDB for debugger

Edit 2: If it's not possible, I will award the bounty to an answer that proves it (I mean provides some credible sources that back the claim that it's not possible). 编辑2:如果不可能,我会将赏金奖励给证明它的答案(我的意思是提供一些可靠的消息来源,说明这是不可能的)。


Let's say I have a pointer to an array, for example: 假设我有一个指向数组的指针,例如:

int arr[3];
int *p = new int[3];

I can see all the elements of arr , but only the first element of p . 我可以看到arr所有元素,但只能看到p的第一个元素。 How can I see all 3 elements of p ? 我怎样才能看到p所有3个元素?

I tried the various suggestions from the answers from View Array contents in QtCreator and View Array contents in Qt Creator debugger , however they didn't work for me: 我尝试了QtCreator中的 View Array内容和Qt Creator调试器中的 View Array内容的答案中的各种建议,但是它们对我不起作用:

在此输入图像描述

I assume this is because I'm on CDB, while the other 2 questions are for GDB. 我认为这是因为我在CDB,而其他两个问题是GDB。 Is it possible to achieve the same for CDB? 是否有可能为CDB实现同样的目标?

Edit: I forgot to mention, but p,3 also doesn't work. 编辑:我忘了提,但p,3也行不通。

Add into Expression Evaluator (menu Window->Views->Locals and Expressions) 添加到Expression Evaluator(菜单Window-> Views-> Locals and Expressions)

(int(*)[3])p

That works fine in Qt Creator 3.2.1 Based on Qt 5.3.2 (GCC 4.9.2, 64 bit) Built on May 10 2016 at 17:53:15. 这在Qt Creator 3.2.1中运行良好基于Qt 5.3.2(GCC 4.9.2,64 bit)建立于2016年5月10日17:53:15。

You can use *(p+1) and *(p+2), to access the other two element. 您可以使用*(p + 1)和*(p + 2)来访问另外两个元素。

Edit: @sashoalm You need to do this below: 编辑: @sashoalm你需要在下面这样做:

int *pindex[3];
for(int j=0; j< 3;j++){
    pindex[j]= p+j;
}

Then you will be able to see all your p in the debugger. 然后,您将能够在调试器中看到所有p。

Hope this helps. 希望这可以帮助。

To see all element of *p: 要查看* p的所有元素:

  1. Right Click On Local and Expressions. 右键单击“本地和表达式”。
  2. enter *(p+1) and *(p+2). 输入*(p + 1)和*(p + 2)。

So, You can see all three elements. 所以,你可以看到所有三个元素。

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

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