[PATCH, PR 17364] Need better printer names in bound_register.py

Doug Evans dje@google.com
Thu Oct 9 17:34:00 GMT 2014

Walfred Tedeschi writes:
 > Moved the printer to the global scope and changed the name of the
 > printer to a more specific name.
 > 2014.09.11  Walfred Tedeschi  <walfred.tedeschi@intel.com>
 > python/lib/gdb/command:
 > 	* bound_registers.py (mpx_bound_reg_printer) Added function to
 > 	register pretty-printing for bound registers, and fixed comments.
 > 	(build_pretty_printer) Removed.


fwiw, I kinda like grouping together all the pretty-printers provided by gdb.
See https://sourceware.org/ml/gdb-patches/2014-10/msg00081.html

Using RegexpCollectionPrettyPrinter is a bit of overkill since there are no
templates, at least not yet.  We could certainly add
SimpleCollectionPrettyPrinter or some such that just did string comparisons
on tag names instead of regexps, but since this is all implementation detail
we could defer this.

 > +def mpx_bound_reg_printer (val):
 > +    lookup_tag = val.type.tag
 > +    if lookup_tag == None:
 > +        return None
 > +    if lookup_tag == "__gdb_builtin_type_bound128":
 > +        return BoundPrinter (val)

Random comments:

1) "lookup_tag" is a bit confusing as there is no lookup done here.
I'd rename it to just val_type_tag or some such.
[Assuming we keep this version.]

2) "mpx" is presumably enough to distinguish this pretty-printer from other
arch's bounds reg pretty-printers (probably a better choice than "x86" too).

3) If I do "info pretty" I see this:

global pretty-printers:

Having "printer" in the name is superfluous, thus if one was to do
things this way I'd rename mpx_bound_reg_printer to mpx_bound_reg.
That way the user can do "disable pretty-printer global mpx_bound_reg".

4) It might be preferable to pick a name closer to the actual type's name:
"mpx_bound128" ?

Registering printers as functions was how pretty-printers were originally
added, but it turned out to be insufficient: printers need to be disableable
and thus need names.  OTOH one tends to think of the name of the function
here as an implementation detail, except that it isn't.]


Going forward,
I like the idea of providing basic infrastructure for grouping builtin
pretty-printers together and using that for 17364.
Plus this file really doesn't belong in python/lib/gdb/command.

I propose sticking with this patch
but I'm happy to tweak it as desired (e.g. use "mpx_bound128" as the name).

More information about the Gdb-patches mailing list