Results 1 to 3 of 3

Thread: GDB - display an array of data in the debugger

  1. #1
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default GDB - display an array of data in the debugger

    This must not be a problem but it is somehow. I have a pointer to a data structure:
    Qt Code:
    1. struct pagelist_t
    2. {
    3. pointer;
    4. int;
    5. };
    6.  
    7. ...
    8.  
    9. pagelist_t *trt;
    To copy to clipboard, switch view to plain text mode 

    The pointer is allocated
    Qt Code:
    1. trt = new pagelist_t[somesize];
    To copy to clipboard, switch view to plain text mode 
    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?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: GDB - display an array of data in the debugger

    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).
    Last edited by Santosh Reddy; 5th December 2013 at 10:48.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    Radek (5th December 2013)

  4. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: GDB - display an array of data in the debugger

    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.
    Last edited by Radek; 5th December 2013 at 11:28.

Similar Threads

  1. Replies: 9
    Last Post: 22nd April 2013, 12:21
  2. Display my data array as an image
    By OzQTNoob in forum Newbie
    Replies: 5
    Last Post: 4th December 2012, 09:17
  3. QGraphicsView (using int array) advice and display help
    By enricong in forum Qt Programming
    Replies: 4
    Last Post: 11th April 2012, 13:40
  4. Qt Creator How to watch data of actual type in debugger?
    By kamre in forum Qt Tools
    Replies: 2
    Last Post: 23rd June 2011, 17:50
  5. Debugger problem retrieving data for watch view hangs
    By frenk_castle in forum Installation and Deployment
    Replies: 0
    Last Post: 5th May 2010, 23:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.