Display pointer as array in Qt Creator with CDB for debugger
Asked Answered
N

3

9

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).


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. How can I see all 3 elements of p?

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:

enter image description here

I assume this is because I'm on CDB, while the other 2 questions are for GDB. Is it possible to achieve the same for CDB?

Edit: I forgot to mention, but p,3 also doesn't work.

Narra answered 17/3, 2015 at 9:22 Comment(2)
Try (int (&) [3])pLabannah
@Labannah CDB logs this error: eERROR: Unable to add watch item "watch.1"/"(int (&) [3])p": Cannot add symbol '(int (&) [3])p': DEBUG_ANY_ID was returned as symbol index by AddSymbol.Narra
M
5

Add into Expression Evaluator (menu 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.

Madelenemadelin answered 29/1, 2017 at 8:55 Comment(0)
O
-1

You can use *(p+1) and *(p+2), to access the other two element.

Edit: @sashoalm You need to do this below:

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.

Hope this helps.

Overhear answered 23/3, 2015 at 15:59 Comment(1)
That's not a solution at all. I already know about p[1] and p[2]. I need it to work for arrays of hundreds of elements.Narra
P
-2

To see all element of *p:

  1. Right Click On Local and Expressions.
  2. enter *(p+1) and *(p+2).

So, You can see all three elements.

Pitsaw answered 25/3, 2015 at 7:27 Comment(2)
If you're going to copy an existing answer you might pick one that hasn't been downvoted and doesn't answer the question satisfactorily.Pilferage
Please don't copy others' answers, do some new contributions to SEVaccinia

© 2022 - 2024 — McMap. All rights reserved.