[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:58 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}"
+        return func
+    return decorator
----------------
JDevlieghere wrote:

Seems like this could be extracted in a helper that takes `qualified` and `-F/-l`?

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


More information about the lldb-commits mailing list