Author Topic: [HOWTO] Set up GDB to debug wxWidgets (wxString)  (Read 6533 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
[HOWTO] Set up GDB to debug wxWidgets (wxString)
« on: July 24, 2012, 03:04:42 pm »
Hello,
here a little How to set up the new Debugger Interface in Codeblocks to display wxWidgets types like wxString...

1) Download an Python enabled GDB described here: https://code.google.com/p/qp-gcc/wiki/GDB

2) Download the wxWidgets GDB Python-script from here: http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/misc/gdb/print.py?view=markup
    I had to add:
Code
import datetime
import gdb
at the beginning of the file

3) Open C::B -> Settings -> Debugger -> Default
    Add to "Debugger intializaton commands":
Code
python
import sys
import gdb
sys.path.insert(0,'path/to/wxWidgets-python-script')
import script_name
end
set print pretty 1

you have to replace "path/to/wxWidgets-python-script" with your path to the wxWidgets script
and script_name with the filename of your script, without .py
The filename can't contain "-" or spaces

4) Remove tick from "Enable watch script"

5) enjoy the big  advantage to see what is stored in you wxString Variable

if you have trouble make a tick at  C::B -> Settings -> Debugger -> Common -> Full (Debug) log. Now you can see the full output of the gdb in the debugger log window.

sorry for the shortness, but my English is really bad....

greetings
« Last Edit: July 31, 2012, 12:13:43 am by BlueHazzard »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [HOWTO] Set up GDB to debug wxWidgets (wxString)
« Reply #1 on: July 24, 2012, 04:51:00 pm »
2) Download the wxWidgets GDB Python-script from here: http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/misc/gdb/print.py?view=markup
    I had to add:
Code
import datetime
import gdb
at the beginning of the file
You post is quite nice for the beginners try to use python pretty printer.
If I remember correct, I don't need the above change to the wx's python pretty printer, maybe I use an old revision of the print.py.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline eranon

  • Almost regular
  • **
  • Posts: 180
Re: [HOWTO] Set up GDB to debug wxWidgets (wxString)
« Reply #2 on: September 05, 2012, 02:56:55 pm »
I've installed this wx-dedicated Python script some days ago and, in my case, I got this error :

Quote
[debug]Error while executing Python code.
[debug]>>>>>  File "<string>", line 4
[debug]    import print
[debug]               ^
[debug]SyntaxError: invalid syntax

To remove-it I've had to add the "import gdb" line as BlueHazzard did, and rename the "print.py" script file to something else (I've choosen "wxprint.py"). Now it works w/o error.

This using python-enabled GDB 7.2.50.20101213, the python script of 2009-01-04, and Python 2.7 under Windows 7 Pro FR.
[Independent dev. - wxWidgets 3.0.0 under "Win 7 Pro 64-bit, C::B SVN 9435 & wxSmith, TDM64-GCC 4.7 & MSVC9" + "OS X 10.8, FSF GCC 4.7 & C::B SVN 8909"]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [HOWTO] Set up GDB to debug wxWidgets (wxString)
« Reply #3 on: September 05, 2012, 03:08:10 pm »
@eanon, you can see this page: http://forums.codeblocks.org/index.php/topic,11301.msg77000.html
I have a detailed wiki page link in that page.
For gdb, you can use either official mingw's gdb(currently gdb 7.5), or other newer ones(include mybuild in the link above)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline eranon

  • Almost regular
  • **
  • Posts: 180
Re: [HOWTO] Set up GDB to debug wxWidgets (wxString)
« Reply #4 on: September 05, 2012, 03:41:01 pm »
OK, thanks Olly : bookmarked and I'll read calmly asap...
[Independent dev. - wxWidgets 3.0.0 under "Win 7 Pro 64-bit, C::B SVN 9435 & wxSmith, TDM64-GCC 4.7 & MSVC9" + "OS X 10.8, FSF GCC 4.7 & C::B SVN 8909"]