Author Topic: Debugger: use gdb python pretty printer for the libstdcxx under msys2  (Read 189 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
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.
Code: [Select]
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

Code: [Select]
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.

Code: [Select]
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:
Code: [Select]
https://github.com/wxWidgets/wxWidgets/blob/master/misc/gdb/print.py
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2569
Re: Debugger: use gdb python pretty printer for the libstdcxx under msys2
« Reply #1 on: November 30, 2019, 01:50:03 pm »
a wiki article would be nice :)