Exit Wiki

Specific GDB hints for wxWidgets:

In GDB Hacks

Commands and tools meant to be called from the GDB command line interface (or put in your .gdbinit file)

Printing the WXK_ constant for an integer

(gdb) print (wxKeyCode) 27
$1 = WXK_ESCAPE

Printing The Class Name

Sometimes you don't know what kind of object you're dealing with. Say you have a wxWindow* and want to know it's actual type. Try this GDB macro:

define print-wxclassname
        call (wxString) ($arg0)->GetClassInfo()->GetClassName()
end

or the gdb whatis command might work too (assuming you're not dealing with wxWindow*s or something equally abstract)

  (gdb) whatis var
  type = wxButton

Debugging Functions

Sometimes you just can't do it all in GDB. Here are some functions that (assuming GDB can see them) should work for you (either calling them via GDB's call command, or programatically doing it)

PrintMap

Prints wxHashMap objects (or std::maps!)

   1 template <typename T>
   2 void PrintMap(T& map)
   3 {
   4     typename T::iterator pos;
   5         
   6     for(pos=map.begin(); pos!=map.end(); ++pos)
   7     {
   8        wxLogDebug("key = %p, value = %p", pos->first, pos->second);
   9        //or, for non-wxWidgets programs...
  10        //std::cout << pos->first << " = " << pos->second << std::endl;
  11 
  12 
  13     }
  14 }

PrintObjArray

   1 template <typename T>
   2 //bah no base "wxObjArray" that I know of. WD-rpw 12-16-2007
   3 void PrintObjArray(T& array)    
   4 {
   5     size_t count =  array.GetCount();
   6         std::cout << "Printing wxObjArray (WX_DECLARE_OBJARRAY), # elems = " << count << std::endl;
   7         
   8     for(size_t i = 0; i < count; ++i)
   9     {
  10         std::cout << "  item #" << i << " = " << (void*)(&array[i]) << " type = " << typeid( array[i] ).name() << std::endl;
  11     }
  12 }

Comments:

Add comments by visiting: GDB/WxWidgets/Comments

GDB/WxWidgets (last edited 2007-12-16 23:47:43 by RyanWilcox)