rust/src/test/debuginfo/embedded-visualizer-point.py
ridwanabdillahi 60458b97e7 Add support for embedding pretty printers via the #[debugger_visualizer] attribute. Add tests for embedding pretty printers and update documentation.
Ensure all error checking for `#[debugger_visualizer]` is done up front and not when the `debugger_visualizer` query is run.

Clean up potential ODR violations when embedding pretty printers into the `__rustc_debug_gdb_scripts_section__` section.

Respond to PR comments and update documentation.
2022-05-24 11:14:48 -07:00

23 lines
499 B
Python

import gdb
class PointPrinter:
"Print a Point"
def __init__(self, val):
self.val = val
self.x = int(val["x"])
self.y = int(val["y"])
def to_string(self):
return "({}, {})".format(self.x, self.y)
def lookup(val):
lookup_tag = val.type.tag
if lookup_tag is None:
return None
if "embedded_visualizer::point::Point" == lookup_tag:
return PointPrinter(val)
return None
gdb.current_objfile().pretty_printers.append(lookup)