Difference between revisions of "Configure GDB pretty printer for Msys2"
m (fix link format) |
(How to add the wxWidgets' pretty printer) |
||
(One intermediate revision by the same user not shown) | |||
Line 35: | Line 35: | ||
<pre>https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py</pre> | <pre>https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py</pre> | ||
+ | |||
+ | |||
+ | =Use predefined macros for the paths= | ||
+ | Under Code::Blocks, you can used some predefined path macros. | ||
+ | |||
+ | For example, you don't need to write | ||
+ | <pre> | ||
+ | source F:\msys64\mingw64\etc\gdbinit | ||
+ | </pre> | ||
+ | Instead, you can use this: | ||
+ | <pre> | ||
+ | source $(TARGET_COMPILER_DIR)etc\gdbinit | ||
+ | </pre> | ||
+ | Since you have already defined the compiler master path in the "Menu->Settings->Compiler->Toolchain executables" as "F:\msys2\mingw64", so the second way is more portable. Also, to mention gdb.exe, you can use | ||
+ | <pre> | ||
+ | $(TARGET_COMPILER_DIR)bin\gdb.exe | ||
+ | </pre> | ||
+ | |||
+ | =Add the pretty printer for wxWidgets= | ||
+ | Here is the full gdbinit content when using latest gcc under msys2/mingw64 | ||
+ | |||
+ | <pre> | ||
+ | python | ||
+ | import sys | ||
+ | sys.path.insert(0, sys.path[0] + '/../../gcc-12.2.0/python') | ||
+ | from libstdcxx.v6.printers import register_libstdcxx_printers | ||
+ | register_libstdcxx_printers (None) | ||
+ | |||
+ | sys.path.insert(0, sys.path[0] + '/../../../etc') | ||
+ | import wxprint | ||
+ | |||
+ | end | ||
+ | </pre> | ||
+ | |||
+ | Note that the two lines were added to the original gdbinit(note once you use pacman to upgrade you gcc, this gdbinit file will get overwritten) | ||
+ | |||
+ | <pre> | ||
+ | sys.path.insert(0, sys.path[0] + '/../../../etc') | ||
+ | import wxprint | ||
+ | </pre> | ||
+ | |||
+ | Here, the "wxprint" is a file named "wxprint.py", which is just the same file as: https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py, I just put this "wxprint.py" in the same folder as the gdbinit file. | ||
+ | |||
+ | |||
=Useful Links= | =Useful Links= | ||
[https://forums.codeblocks.org/index.php?topic=23590.0 Debugger: use gdb python pretty printer for the libstdcxx under msys2] | [https://forums.codeblocks.org/index.php?topic=23590.0 Debugger: use gdb python pretty printer for the libstdcxx under msys2] |
Latest revision as of 06:30, 3 July 2023
This is my way to use gdb python pretty printer for the libstdcxx under msys2. Suppose you use 64bit gcc compiler. My msys2 is installed under F:\msys64
In the Menu->Settings->Debugger settings. Open the debugger plugin setting dialog.
Then, in the "Executable path" field, select "F:\msys64\mingw64\bin\gdb.exe" in the "Debugger initialization commands" field, put the following text in the edit control.
source F:\msys64\mingw64\etc\gdbinit
I see that I have to modify the file "F:\msys64\mingw64\etc\gdbinit" file: below is the original code
python import sys sys.path.insert(0, sys.path[0] + '/../../gcc-9.2.0/python') from libstdcxx.v6.printers import register_libstdcxx_printers end
But you have to add one line before the "end" statement like below to let the register_libstdcxx_printers function get executed.
python import sys sys.path.insert(0, sys.path[0] + '/../../gcc-9.2.0/python') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers(None) end
BTW: It is the same thing to add the python pretty printer for wxWidgets. You can use this file:
https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py
Use predefined macros for the paths
Under Code::Blocks, you can used some predefined path macros.
For example, you don't need to write
source F:\msys64\mingw64\etc\gdbinit
Instead, you can use this:
source $(TARGET_COMPILER_DIR)etc\gdbinit
Since you have already defined the compiler master path in the "Menu->Settings->Compiler->Toolchain executables" as "F:\msys2\mingw64", so the second way is more portable. Also, to mention gdb.exe, you can use
$(TARGET_COMPILER_DIR)bin\gdb.exe
Add the pretty printer for wxWidgets
Here is the full gdbinit content when using latest gcc under msys2/mingw64
python import sys sys.path.insert(0, sys.path[0] + '/../../gcc-12.2.0/python') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (None) sys.path.insert(0, sys.path[0] + '/../../../etc') import wxprint end
Note that the two lines were added to the original gdbinit(note once you use pacman to upgrade you gcc, this gdbinit file will get overwritten)
sys.path.insert(0, sys.path[0] + '/../../../etc') import wxprint
Here, the "wxprint" is a file named "wxprint.py", which is just the same file as: https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py, I just put this "wxprint.py" in the same folder as the gdbinit file.
Useful Links
Debugger: use gdb python pretty printer for the libstdcxx under msys2