Difference between revisions of "Pretty Printers"
From Code::Blocks
GravityWe11 (talk | contribs) |
GravityWe11 (talk | contribs) |
||
Line 6: | Line 6: | ||
*Ensure GDB is python-enabled. For Linux (tested with recent Ubuntu), it is installed by default with GDB. For Windows, MinGW's default GDB is not python enabled. One option is to install [http://sourceforge.net/projects/mingwbuilds/ MinGW-Builds] over MinGW (consider backing up MinGW first). This updates GCC to 4.7.2 and includes a Python enabled GDB. | *Ensure GDB is python-enabled. For Linux (tested with recent Ubuntu), it is installed by default with GDB. For Windows, MinGW's default GDB is not python enabled. One option is to install [http://sourceforge.net/projects/mingwbuilds/ MinGW-Builds] over MinGW (consider backing up MinGW first). This updates GCC to 4.7.2 and includes a Python enabled GDB. | ||
<ol> | <ol> | ||
− | To test: | + | To test:<br/> |
Launch GDB from console: | Launch GDB from console: | ||
<span style="font-size: 10pt"><pre> | <span style="font-size: 10pt"><pre> |
Revision as of 22:02, 26 October 2012
GDB Pretty Printers for STL display nicely formatted variables in the hover pop-up and watch window, for all STL containers (vectors, maps, etc).
Test with GDB
- Ensure GDB is python-enabled. For Linux (tested with recent Ubuntu), it is installed by default with GDB. For Windows, MinGW's default GDB is not python enabled. One option is to install MinGW-Builds over MinGW (consider backing up MinGW first). This updates GCC to 4.7.2 and includes a Python enabled GDB.
-
To test:
Launch GDB from console:
(gdb) python print sys.version
- Create a GDB Command File to enable the printer. Store in c:\mingw\bin\pp.gdb (or wherever you want). Below is a sample command file. Replace the path c:/MinGW/share... with your path to printers.py. NOTE: A Python STL printer.py is included with MinGW and MinGW-Builds, so there is no need to download one. It only needs to be loaded into GDB's python, which is the purpose of the command file
python import sys sys.path.insert(0, 'c:/MinGW/share/gcc-4.7.2/python/libstdcxx/v6') from printers import register_libstdcxx_printers register_libstdcxx_printers (None) end
- Test
- Set a breakpoint in a program and debug
- Run the command file from GDB (can use Codeblocks->debugger tab->command, or in GDB from the console) (substitute your path if necessary)
(gdb) source c:\MinGW\bin\pp.gdb
- Test the printer - example:
(gdb) print words2 $1 = std::vector of length 3, capacity 4 = {"one", "two", "three"}
Add to Codeblocks
Once the command file is correctly loading the python printer into GDB, there are two steps to activate in Codeblocks:
- Set debugger initialization command (substitute your path as necessary):
Codeblocks->Settings->Debugger->Default->Debugger initialization commands
source c:\MinGW\bin\pp.gdb
- Disable Codeblocks handling of watch values:
- Codeblocks->Settings->Debugger->Default->Enable Watch Scripts = Unchecked
Other Info
Links:
To Do
The third column in the Codeblocks popup and watch window displays a long unformatted string. Codeblocks is calling the GDB whatis command. Can this command be Pretty-Printed?