gdbgdb-python

How does GDB pretty printer know the output format the user is requesting?


I have a few complex classes generated by a third party domain-specific tool. The classes are complex because the tool tries to be generic as much as possible, so that I was asked to design a GDB pretty printer python script to improve the debugging experience.

I designed it by "to_string" APIs which can print the information with organized rich text (e.g. colors), so far everything works fine.

However, I don't know how to get the output format user requests, no matter that user uses "p" or "p/x" will all output the same string because my script does not know user wants hex rather than decimal.

I tried googling but didn't figure out an elegant approach. I indeed have a few workarounds but they all change the usages (for example, implement two printers to be switched), please give me some suggestions, thank you.


Solution

  • Just realized there had been a feature request to GDB already.

    Bug 17291 - IWBN if the print format was available to pretty-printers.