https://wiki.codeblocks.org/api.php?action=feedcontributions&user=RobinWhittle&feedformat=atomCode::Blocks - User contributions [en]2024-03-29T11:16:01ZUser contributionsMediaWiki 1.35.0https://wiki.codeblocks.org/index.php?title=Pretty_Printers&diff=7718Pretty Printers2014-02-01T09:49:59Z<p>RobinWhittle: Previous fix wasn't enough - replaced the entire Linux download URL</p>
<hr />
<div>[[Category: User Documentation]]<br />
GDB Pretty Printers for STL display nicely formatted variables in the hover pop-up and watch window, for all STL containers (vectors, maps, etc).<br />
----<br />
[[File:Pprint1.png|border|Popup example]]<br><br />
==Test with GDB==<br />
<br />
*Ensure GDB is python-enabled. For Linux (tested with recent Ubuntu), it is enabled by default. For Windows, MinGW's 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.<br />
<ol><br />
To test, launch GDB from console:<br />
<span style="font-size: 10pt"><pre><br />
(gdb) python print sys.version<br />
</pre></span><br />
If python is enabled, the version will be printed (probably 2.7.x), otherwise, a message will indicate python scripting is not supported.<br />
</ol><br />
*Download printers.py (if necessary)<br />
:Windows users with MinGW should already have this file in /MinGW/share/gcc-4.7.2/python/libstdcxx/v6.<br />
:Linux users can download printers.py [http://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/libstdcxx/v6/printers.py here]. Save as <tt><span style="font-size: 10pt">/home/username/gdb_printers/printers.py</span></tt>.<br />
*Create a GDB [http://sourceware.org/gdb/onlinedocs/gdb/Command-Files.html Command File] to enable the printer. Store in <tt><span style="font-size: 10pt">c:\mingw\bin\pp.gdb</span></tt> (windows) or <tt><span style="font-size: 10pt">/home/username/gdb_printers/pp.gdb</span></tt> (linux). Below is a sample command file. Replace the path c:/MinGW/share... with your path to printers.py.<br />
<blockquote><span style="font-size: 10pt"><pre><br />
python<br />
import sys<br />
sys.path.insert(0, 'c:/MinGW/share/gcc-4.7.2/python/libstdcxx/v6')<br />
from printers import register_libstdcxx_printers<br />
register_libstdcxx_printers (None)<br />
end<br />
</pre></span></blockquote><br />
*Test<br />
#Set a breakpoint in a program and debug<br />
#Run the command file from GDB (can use Codeblocks->debugger tab->command, or in GDB from the console) (substitute your path if necessary)<br />
<ol><span style="font-size: 10pt"><pre>(gdb) source c:\MinGW\bin\pp.gdb</pre></span></ol><br />
<ol start="3"><br />
<li>Test the printer - example:</li><br />
</ol><br />
<ol><span style="font-size: 10pt"><pre>(gdb) print words2<br />
$1 = std::vector of length 3, capacity 4 = {"one", "two", "three"}<br />
</pre></span></ol><br />
<br />
==Add to Codeblocks==<br />
Once the command file is working correctly, there are two steps to activate in Codeblocks:<br />
#Set debugger initialization command (substitute your path as necessary):<br/><span style="font-size: 10pt"><tt>Codeblocks->Settings->Debugger->Default->Debugger initialization commands</tt></span><br />
<ol><span style="font-size: 10pt"><pre>source c:\MinGW\bin\pp.gdb</pre></span><br />
NOTE: A bug in the Linux version of Codeblocks may prevent entering anything in the Debugger Initialization Commands field. A work-around is to open a CBP project file via a file manager, which in turn launches Codeblocks and seems to resolve the issue.<br />
</ol><br />
<ol start="2"><br />
<li>Disable Codeblocks handling of watch values:</li><br />
</ol><br />
<ol><span style="font-size: 10pt"><tt>Codeblocks->Settings->Debugger->Default->Enable Watch Scripts = Unchecked</tt></span></ol><br />
===Other Info===<br />
Links:<br />
<br />
[http://sourceware.org/gdb/onlinedocs/gdb/Python-API.html GDB Python API]<br />
<br />
[http://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html GDB Pretty Printing]<br />
<br />
===To Do===<br />
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?<br />
<br />
==See also==<br />
* [[Debugging with Code::Blocks]]<br />
* [[Debugger scripts]]</div>RobinWhittlehttps://wiki.codeblocks.org/index.php?title=Pretty_Printers&diff=7717Pretty Printers2014-02-01T09:48:22Z<p>RobinWhittle: /* Test with GDB */ Replaced "viewcvs" with "svn" in Linux download URL</p>
<hr />
<div>[[Category: User Documentation]]<br />
GDB Pretty Printers for STL display nicely formatted variables in the hover pop-up and watch window, for all STL containers (vectors, maps, etc).<br />
----<br />
[[File:Pprint1.png|border|Popup example]]<br><br />
==Test with GDB==<br />
<br />
*Ensure GDB is python-enabled. For Linux (tested with recent Ubuntu), it is enabled by default. For Windows, MinGW's 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.<br />
<ol><br />
To test, launch GDB from console:<br />
<span style="font-size: 10pt"><pre><br />
(gdb) python print sys.version<br />
</pre></span><br />
If python is enabled, the version will be printed (probably 2.7.x), otherwise, a message will indicate python scripting is not supported.<br />
</ol><br />
*Download printers.py (if necessary)<br />
:Windows users with MinGW should already have this file in /MinGW/share/gcc-4.7.2/python/libstdcxx/v6.<br />
:Linux users can download printers.py [http://gcc.gnu.org/svn/trunk/libstdc%2B%2B-v3/python/libstdcxx/v6/ here]. Save as <tt><span style="font-size: 10pt">/home/username/gdb_printers/printers.py</span></tt>.<br />
*Create a GDB [http://sourceware.org/gdb/onlinedocs/gdb/Command-Files.html Command File] to enable the printer. Store in <tt><span style="font-size: 10pt">c:\mingw\bin\pp.gdb</span></tt> (windows) or <tt><span style="font-size: 10pt">/home/username/gdb_printers/pp.gdb</span></tt> (linux). Below is a sample command file. Replace the path c:/MinGW/share... with your path to printers.py.<br />
<blockquote><span style="font-size: 10pt"><pre><br />
python<br />
import sys<br />
sys.path.insert(0, 'c:/MinGW/share/gcc-4.7.2/python/libstdcxx/v6')<br />
from printers import register_libstdcxx_printers<br />
register_libstdcxx_printers (None)<br />
end<br />
</pre></span></blockquote><br />
*Test<br />
#Set a breakpoint in a program and debug<br />
#Run the command file from GDB (can use Codeblocks->debugger tab->command, or in GDB from the console) (substitute your path if necessary)<br />
<ol><span style="font-size: 10pt"><pre>(gdb) source c:\MinGW\bin\pp.gdb</pre></span></ol><br />
<ol start="3"><br />
<li>Test the printer - example:</li><br />
</ol><br />
<ol><span style="font-size: 10pt"><pre>(gdb) print words2<br />
$1 = std::vector of length 3, capacity 4 = {"one", "two", "three"}<br />
</pre></span></ol><br />
<br />
==Add to Codeblocks==<br />
Once the command file is working correctly, there are two steps to activate in Codeblocks:<br />
#Set debugger initialization command (substitute your path as necessary):<br/><span style="font-size: 10pt"><tt>Codeblocks->Settings->Debugger->Default->Debugger initialization commands</tt></span><br />
<ol><span style="font-size: 10pt"><pre>source c:\MinGW\bin\pp.gdb</pre></span><br />
NOTE: A bug in the Linux version of Codeblocks may prevent entering anything in the Debugger Initialization Commands field. A work-around is to open a CBP project file via a file manager, which in turn launches Codeblocks and seems to resolve the issue.<br />
</ol><br />
<ol start="2"><br />
<li>Disable Codeblocks handling of watch values:</li><br />
</ol><br />
<ol><span style="font-size: 10pt"><tt>Codeblocks->Settings->Debugger->Default->Enable Watch Scripts = Unchecked</tt></span></ol><br />
===Other Info===<br />
Links:<br />
<br />
[http://sourceware.org/gdb/onlinedocs/gdb/Python-API.html GDB Python API]<br />
<br />
[http://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html GDB Pretty Printing]<br />
<br />
===To Do===<br />
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?<br />
<br />
==See also==<br />
* [[Debugging with Code::Blocks]]<br />
* [[Debugger scripts]]</div>RobinWhittle