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
a wiki article would be nice :)
Quote from: BlueHazzard on November 30, 2019, 01:50:03 PM
a wiki article would be nice :)
Done, see here: Configure GDB pretty printer for Msys2 - CodeBlocks (http://wiki.codeblocks.org/index.php/Configure_GDB_pretty_printer_for_Msys2)
Though a bit late.
Great!
It doesn't work for the wx print.
When i find some time i will use "source -p" like wxWidgets team say:
Quotethis file is meant to
# be sourced from gdb using "source -p" (or, better, autoloaded
# in the future...)
Quote from: Suryavarman on March 21, 2021, 12:40:18 AM
It doesn't work for the wx print.
When i find some time i will use "source -p" like wxWidgets team say:
Quotethis 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.
It's works. Thank you BlueHazzard ;D
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
ollydbg. Thanks for the Page and info as I was able to get the wxwidget pretty printing to work with the help form the page. I fell into a few minor holes, which could filed in by updating the page so other people do not fall into the same holes, which are/were:
1) In the Menu->Settings->Debugger settings. Open the debugger plugin setting dialog and uncheck the "Disable startup scripts (-nx) (GDB only)" option.
2) 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.
3) Update it to change the "source F:\msys64\mingw64\etc\gdbinit" to "source $(TARGET_COMPILER_DIR)etc\gdbinit"
4) You may want to change the note about the "register_libstdcxx_printers(None)" additional line was added to MSYS in https://github.com/msys2/MINGW-packages/pull/6351 (6-Apr-2020) and if people are using a later version then they do not need to do anything.
Hi, thanks for the response!
Quote from: AndrewCot on June 18, 2021, 09:42:18 AM
ollydbg. Thanks for the Page and info as I was able to get the wxwidget pretty printing to work with the help form the page. I fell into a few minor holes, which could filed in by updating the page so other people do not fall into the same holes, which are/were:
1) 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.
Quote2) 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 (https://forums.next.codeblocks.org/index.php/topic,23590.msg166535.html#msg166535)
You don't need the "hard-coded path" in those settings.
Quote3) Update it to change the "source F:\msys64\mingw64\etc\gdbinit" to "source $(TARGET_COMPILER_DIR)etc\gdbinit"
This is correct, I also do like this.
Quote4) You may want to change the note about the "register_libstdcxx_printers(None)" additional line was added to MSYS in https://github.com/msys2/MINGW-packages/pull/6351 (6-Apr-2020) and if people are using a later version then they do not need to do anything.
Yes, I think msys2 already has configured the pretty printer for the libstdcxx library, what we need is to add some codes to the "gdbinit" file which support the wx's pretty printer.
Feedback on feedback:
1).
"Disable startup scripts (-nx) (GDB only)" option.QuoteIn 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:QuoteIf 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