[Lldb-commits] [lldb] [lldb] Add lldb.summary and lldb.synthetic decorators (PR #195351)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon May 4 22:17:59 PDT 2026


================
@@ -606,3 +606,47 @@ def is_numeric_type(basic_type):
     return (False,False)
 
 %}
+
+%pythoncode %{
+
+def _type_spec(type_name, regex):
+    type_spec = f"'{type_name}'"
+    if regex:
+        type_spec = f"-x {type_spec}"
+    return type_spec
+
+def summary(type_name, regex=False):
+    """A decorator that registers a function as an LLDB type summary provider.
+
+    @lldb.summary("MyType")
+    def MyTypeSummary(valobj, internal_dict):
+        return "summary string"
+    """
+    type_spec = _type_spec(type_name, regex)
+    def decorator(func):
+        qualified = f"{func.__module__}.{func.__qualname__}"
+        func._lldb_register_command = f"type summary add -F {qualified} {type_spec}"
----------------
JDevlieghere wrote:

Instead of a string, would it be worthwhile to store this as a dict and then extract the structured data and then piecing the command together when doing the import? That seems slightly more future proof and may allow better diagnostics if something goes wrong?

https://github.com/llvm/llvm-project/pull/195351


More information about the lldb-commits mailing list