PDA

View Full Version : GDB - display an array of data in the debugger



Radek
5th December 2013, 08:56
This must not be a problem but it is somehow. I have a pointer to a data structure:


struct pagelist_t
{
pointer;
int;
};

...

pagelist_t *trt;


The pointer is allocated


trt = new pagelist_t[somesize];

and initialized.

Now, I want to see (using a debugger) that trt is initialized correctly. So start a debugger and get baffled: there is no option in the debugger "display as array". Dereferencing the pointer shows only the first item in the array but this is not enough. I tried the web and found that "this is difficult" followed by mere excuses that the debugger cannot know the size of the array (correct but it should be you who is specifying the array bounds, debuggers can process such request for sure, my own experience not only with GDB) and hints that you should make the pointer watched, etc.

But where is the "watches" window? In the Debug menu is "Add to watch window" grayed. The Watch window is nowhere in sight and "Select widget to watch seems to do nothing. Well, I do not watch a widget but a pointer. The end. Is there a possibility to see elements 0..10 of trt?

Santosh Reddy
5th December 2013, 10:35
But where is the "watches" window?
I assume you are using some version of Qt Creator.
In Qt Creator 2.8. (It is very similar in other version of Qt Creator).
-> "Window" -> "Views" -> "Locals and Expressions" (make sure it is checked)
-> Place the cursor on the variable to watch and "Debug" -> "Add Expression Evaluator". A vertical split will appear in the "Locals and Expressions" view.


Is there a possibility to see elements 0..10 of trt?
Yes it is possible, just cast the variable to array type in the watch window.
Example:
pagelist_t * trt;
trt -> Will show only the first element in the arrray. (which is not valid data)
(pagelist_t[10])trt -> Will show all the 10 elements in the array (note that if the actual array size is less then some garbage value may be shown).

Radek
5th December 2013, 11:10
The Creator is 2.5.0, Qt is 4.8.2 as installed by Debian Wheezy KDE. "Locals and Expressions" is checked. Watch window is nowhere in sight, not even a "dog ear" of it. Neither is "Add Expression Evaluator". I have checked the Debug Menu and submenus (with Debug running and "trt" selected) and the popup menu when right-clicking the "trt".

The first problem seems to be the Watch window. I can create a new evaluated expression (for example trt) and get it once more in the Locals window. But I cannot do more, the popup menu is the same. No Add Expression Evaluator, only a list of string encodings.

----------

Uff! "Insert New Evaluated Expression" and enter "(pagelist_t[10])(*trt)". Uff! Thanks.