4 Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 See https://llvm.org/LICENSE.txt for license information.
6 SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 # example summary provider for NSNotification
9 # the real summary is now C++ code built into LLDB
10 import lldb
.runtime
.objc
.objc_runtime
11 import lldb
.formatters
.metrics
14 import lldb
.formatters
.Logger
16 statistics
= lldb
.formatters
.metrics
.Metrics()
17 statistics
.add_metric("invalid_isa")
18 statistics
.add_metric("invalid_pointer")
19 statistics
.add_metric("unknown_class")
20 statistics
.add_metric("code_notrun")
23 class NSConcreteNotification_SummaryProvider
:
24 def adjust_for_architecture(self
):
27 def __init__(self
, valobj
, params
):
28 logger
= lldb
.formatters
.Logger
.Logger()
30 self
.sys_params
= params
31 if not (self
.sys_params
.types_cache
.id):
32 self
.sys_params
.types_cache
.id = self
.valobj
.GetType().GetBasicType(
38 logger
= lldb
.formatters
.Logger
.Logger()
39 self
.adjust_for_architecture()
41 # skip the ISA and go to the name pointer
43 logger
= lldb
.formatters
.Logger
.Logger()
44 return self
.sys_params
.pointer_size
47 logger
= lldb
.formatters
.Logger
.Logger()
48 string_ptr
= self
.valobj
.CreateChildAtOffset(
49 "name", self
.offset(), self
.sys_params
.types_cache
.id
51 return CFString
.CFString_SummaryProvider(string_ptr
, None)
54 class NSNotificationUnknown_SummaryProvider
:
55 def adjust_for_architecture(self
):
58 def __init__(self
, valobj
, params
):
59 logger
= lldb
.formatters
.Logger
.Logger()
61 self
.sys_params
= params
65 logger
= lldb
.formatters
.Logger
.Logger()
66 self
.adjust_for_architecture()
69 logger
= lldb
.formatters
.Logger
.Logger()
70 stream
= lldb
.SBStream()
71 self
.valobj
.GetExpressionPath(stream
)
72 name_vo
= self
.valobj
.CreateValueFromExpression(
73 "name", "(NSString*)[" + stream
.GetData() + " name]"
76 return CFString
.CFString_SummaryProvider(name_vo
, None)
77 return "<variable is not NSNotification>"
80 def GetSummary_Impl(valobj
):
81 logger
= lldb
.formatters
.Logger
.Logger()
86 ) = lldb
.runtime
.objc
.objc_runtime
.Utilities
.prepare_class_detection(
92 name_string
= class_data
.class_name()
93 logger
>> "class name is: " + str(name_string
)
95 if name_string
== "NSConcreteNotification":
96 wrapper
= NSConcreteNotification_SummaryProvider(valobj
, class_data
.sys_params
)
97 statistics
.metric_hit("code_notrun", valobj
)
99 wrapper
= NSNotificationUnknown_SummaryProvider(valobj
, class_data
.sys_params
)
100 statistics
.metric_hit(
101 "unknown_class", valobj
.GetName() + " seen as " + name_string
106 def NSNotification_SummaryProvider(valobj
, dict):
107 logger
= lldb
.formatters
.Logger
.Logger()
108 provider
= GetSummary_Impl(valobj
)
109 if provider
is not None:
111 provider
, lldb
.runtime
.objc
.objc_runtime
.SpecialSituation_Description
113 return provider
.message()
115 summary
= provider
.name()
118 logger
>> "got summary " + str(summary
)
120 summary
= "<variable is not NSNotification>"
122 return "Summary Unavailable"
125 def __lldb_init_module(debugger
, dict):
126 debugger
.HandleCommand(
127 "type summary add -F NSNotification.NSNotification_SummaryProvider NSNotification"