User forums > Using Code::Blocks

Debugger: use gdb python pretty printer for the libstdcxx under msys2

<< < (2/3) > >>

ollydbg:

--- 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:


--- Quote ---this file is meant to
#               be sourced from gdb using "source -p" (or, better, autoloaded
#               in the future...)
--- End quote ---

--- End quote ---

OK, I understand your problem. Here is the method to solve this problem.

First, you download the file

--- Code: ---https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py

--- End code ---

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:


--- Code: ---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

--- End code ---

Look at the two lines:

--- Code: ---sys.path.insert(0, sys.path[0] + '/../../../etc')
import wxprint

--- End code ---

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.

Suryavarman:
It's works. Thank you BlueHazzard  ;D

ollydbg:
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:


--- Code: ---$(TARGET_COMPILER_DIR)bin\gdb.exe
--- End code ---

and to use the gdb initialization script, use this string:


--- Code: ---source $(TARGET_COMPILER_DIR)etc\gdbinit
--- End code ---

See the image shot below:

This make C::B more portable


AndrewCot:
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.

ollydbg:
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.

--- End quote ---

I think this option should be "checked on", I mean we don't need the startup scripts.



--- Quote ---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.
--- End quote ---
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.



--- Quote ---3) Update it to change the "source F:\msys64\mingw64\etc\gdbinit" to "source $(TARGET_COMPILER_DIR)etc\gdbinit"
--- End quote ---
This is correct, I also do like this.



--- Quote ---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.
--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version