1

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.

  • I don't think it's possible to get the output format of the current print command. Usually you would use the `children` API for the values, and the print command would automatically use the chosen print format for them. If that's not possible, you could create a new [parameter](https://sourceware.org/gdb/onlinedocs/gdb/Parameters-In-Python.html) for this which you could query in the pretty printer with [gdb.parameter](https://sourceware.org/gdb/onlinedocs/gdb/Basic-Python.html#index-gdb_002eparameter). – ssbssa Apr 01 '22 at 11:23
  • Thanks @ssbssa, looks like I need to change the usages in anyway. – Home of the Brave Apr 01 '22 at 23:58

1 Answers1

1

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

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