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 # summary provider for class NSException
9 import lldb
.runtime
.objc
.objc_runtime
10 import lldb
.formatters
.metrics
13 import lldb
.formatters
.Logger
15 statistics
= lldb
.formatters
.metrics
.Metrics()
16 statistics
.add_metric("invalid_isa")
17 statistics
.add_metric("invalid_pointer")
18 statistics
.add_metric("unknown_class")
19 statistics
.add_metric("code_notrun")
22 class NSKnownException_SummaryProvider
:
23 def adjust_for_architecture(self
):
26 def __init__(self
, valobj
, params
):
27 logger
= lldb
.formatters
.Logger
.Logger()
29 self
.sys_params
= params
30 if not (self
.sys_params
.types_cache
.id):
31 self
.sys_params
.types_cache
.id = self
.valobj
.GetType().GetBasicType(
37 logger
= lldb
.formatters
.Logger
.Logger()
38 self
.adjust_for_architecture()
40 def offset_name(self
):
41 logger
= lldb
.formatters
.Logger
.Logger()
42 return self
.sys_params
.pointer_size
44 def offset_reason(self
):
45 logger
= lldb
.formatters
.Logger
.Logger()
46 return 2 * self
.sys_params
.pointer_size
48 def description(self
):
49 logger
= lldb
.formatters
.Logger
.Logger()
50 name_ptr
= self
.valobj
.CreateChildAtOffset(
51 "name", self
.offset_name(), self
.sys_params
.types_cache
.id
53 reason_ptr
= self
.valobj
.CreateChildAtOffset(
54 "reason", self
.offset_reason(), self
.sys_params
.types_cache
.id
58 + CFString
.CFString_SummaryProvider(name_ptr
, None)
60 + CFString
.CFString_SummaryProvider(reason_ptr
, None)
64 class NSUnknownException_SummaryProvider
:
65 def adjust_for_architecture(self
):
68 def __init__(self
, valobj
, params
):
69 logger
= lldb
.formatters
.Logger
.Logger()
71 self
.sys_params
= params
75 logger
= lldb
.formatters
.Logger
.Logger()
76 self
.adjust_for_architecture()
78 def description(self
):
79 logger
= lldb
.formatters
.Logger
.Logger()
80 stream
= lldb
.SBStream()
81 self
.valobj
.GetExpressionPath(stream
)
82 name_vo
= self
.valobj
.CreateValueFromExpression(
83 "name", "(NSString*)[" + stream
.GetData() + " name]"
85 reason_vo
= self
.valobj
.CreateValueFromExpression(
86 "reason", "(NSString*)[" + stream
.GetData() + " reason]"
88 if name_vo
.IsValid() and reason_vo
.IsValid():
90 CFString
.CFString_SummaryProvider(name_vo
, None)
92 + CFString
.CFString_SummaryProvider(reason_vo
, None)
94 return "<variable is not NSException>"
97 def GetSummary_Impl(valobj
):
98 logger
= lldb
.formatters
.Logger
.Logger()
103 ) = lldb
.runtime
.objc
.objc_runtime
.Utilities
.prepare_class_detection(
109 name_string
= class_data
.class_name()
110 logger
>> "class name is: " + str(name_string
)
112 if name_string
== "NSException":
113 wrapper
= NSKnownException_SummaryProvider(valobj
, class_data
.sys_params
)
114 statistics
.metric_hit("code_notrun", valobj
)
116 wrapper
= NSUnknownException_SummaryProvider(valobj
, class_data
.sys_params
)
117 statistics
.metric_hit(
118 "unknown_class", valobj
.GetName() + " seen as " + name_string
123 def NSException_SummaryProvider(valobj
, dict):
124 logger
= lldb
.formatters
.Logger
.Logger()
125 provider
= GetSummary_Impl(valobj
)
126 if provider
is not None:
128 provider
, lldb
.runtime
.objc
.objc_runtime
.SpecialSituation_Description
130 return provider
.message()
132 summary
= provider
.description()
135 logger
>> "got summary " + str(summary
)
137 summary
= "<variable is not NSException>"
139 return "Summary Unavailable"
142 def __lldb_init_module(debugger
, dict):
143 debugger
.HandleCommand(
144 "type summary add -F NSException.NSException_SummaryProvider NSException"