Hi, 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
It doesn't work for the wx print.
When i find some time i will use "source -p" like wxWidgets team say:
this file is meant to
# be sourced from gdb using "source -p" (or, better, autoloaded
# in the future...)
OK, I understand your problem. Here is the method to solve this problem.
First, you download the file
https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py
For me, I renamed this file to wxprint.py, and I saved it to the same folder as the gdbinit file locates.
Then, I modify the gdbinit file as below:
python
import sys
sys.path.insert(0, sys.path[0] + '/../../gcc-10.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
Look at the two lines:
sys.path.insert(0, sys.path[0] + '/../../../etc')
import wxprint
The first line adds the current directory of the wxprint.py, and the second line just imports the wxprint.py file. I think the "import" directive us just like the "source" directive in Python, am I correct?
Anyway, this works OK in my msys2. I can have both wxWidgets and C++ std library's pretty printers working when debugging. :)
BTW: I haven't find a simple way to load the wxprint.py file, I just want to avoid the first line, but that line is always needed :(. Maybe, some guys can improve the loading code.
This is further simplified config when using msys2 based gdb. We can use the macro variables
For the gdb.exe path, just use this string:
$(TARGET_COMPILER_DIR)bin\gdb.exe
and to use the gdb initialization script, use this string:
source $(TARGET_COMPILER_DIR)etc\gdbinit
See the image shot below:
This make C::B more portable
Feedback on feedback:
1). "Disable startup scripts (-nx) (GDB only)" option.
In the Menu->Settings->Debugger settings. Open the debugger plugin setting dialog and uncheck the "Disable startup scripts (-nx) (GDB only)" option.
>> I think this option should be "checked on", I mean we don't need the startup scripts.
If I leave the option checked [X] then the pretty printer does not work and the watch looks like it does when no pretty printer is defined for wxWidget. If uncheck [ ] the option then the GDB pretty printer watch displays a wxString in a human read able format. See attachment showing this.
2.gdbinit file:
If you are using the https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py file then add the following to the gdbinit file:
sys.path.insert(0, 'D:/temp')
from wxprint import register_wxwidgets_printers
register_wxwidgets_printers (None)
Rember to change the directory to where you have saved the print.py file.
>>I don't do like that, I just shows what I did in this post:
>>Re: Debugger: use gdb python pretty printer for the libstdcxx under msys2
>>You don't need the "hard-coded path" in those settings.
I think the page still needs an update to add the info so someone does not need to find in the forum post (like I had to do as it did not work due to item 1), but I also had to get the syntax correct in the gdbinit):
a) Copy the https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py into :
Linux: /etc (checked on Linux Mint 20.1 Virtual machine)
Windows - MSYS2: x:\msys64\mingw64\etc or x:\msys64\mingw32\etc where x: is the drive you installed Msys2 onto and depending on if you are using the 32 or 64 bit compiler
Windows - Cygwin: - Looks like it supports pretty printing, but by default no gdbinit file exists.
Windows - Mingw64: TBA
MacOSx: TBA
a) Add the following to gdbinit in the directory in the step above:
sys.path.insert(0, sys.path[0] + '/../../../etc')
import wxprint