You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great if one could implement custom formatters for types. There are a few scenarios where this would be helpful:
Data which is stored in a struct but has a better, human-readable representation. One simple example would be timestamp where unixtime or struct tm (from C++ but similar things are done in C) have more digestible/compact representations. Or converting magic values (flags, enums, etc) to their textual representation
Printing nested data structures or large structs quickly fills the screen making it hard to spot the necessary information. Adding custom formatters one could specify e.g. the depth, or elide some content after certain thresholds have been reached.
Highlight unexpected values. If one wants to get very fancy they could use ANSI colors to highlight unexpectedly high values or other things they want to be able to quickly spot. (Doing the ANSI stuff would of course not be the responsibility of this library).
Being able to register custom callback for each data type which are invoked when their string should be printed would allow more powerful visualization. Or maybe as some kind of "transform" function which takes a struct and returns a JSON such that drgn would still handle indentation and such?
Currently one could achieve a similar result by invoking such handlers manually but that is more involved for nested structures and is quite cumbersome
The text was updated successfully, but these errors were encountered:
An even more powerful solution would be to register classes for types. This way one could register a subclass of drgn.Type and customize str, repr, but more importantly could also add custom methods on that type. The API could look something like this:
As a nice side effect this would also allow people to utilize python type hints to a greater extend instead of passing drgn.Type/drgn.Object everywhere
septatrix
changed the title
Allow subclassing drgn.Type and registering those classes
Allow subclassing Type/Object and registering those classes
Mar 6, 2025
It would be great if one could implement custom formatters for types. There are a few scenarios where this would be helpful:
struct tm
(from C++ but similar things are done in C) have more digestible/compact representations. Or converting magic values (flags, enums, etc) to their textual representationBeing able to register custom callback for each data type which are invoked when their string should be printed would allow more powerful visualization. Or maybe as some kind of "transform" function which takes a struct and returns a JSON such that drgn would still handle indentation and such?
Currently one could achieve a similar result by invoking such handlers manually but that is more involved for nested structures and is quite cumbersome
The text was updated successfully, but these errors were encountered: