4 part of The LLVM Compiler Infrastructure
5 This file is distributed under the University of Illinois Open Source
6 License. See LICENSE.TXT for details.
8 # example summary provider for NSBundle
9 # the real summary is now C++ code built into LLDB
12 import lldb.runtime.objc.objc_runtime
13 import lldb.formatters.metrics
15 import lldb.formatters.Logger
17 statistics = lldb.formatters.metrics.Metrics()
18 statistics.add_metric('invalid_isa')
19 statistics.add_metric('invalid_pointer')
20 statistics.add_metric('unknown_class')
21 statistics.add_metric('code_notrun')
23 # despite the similary to synthetic children providers, these classes are not
24 # trying to provide anything but a summary for an NSURL, so they need not
25 # obey the interface specification for synthetic children providers
28 class NSBundleKnown_SummaryProvider:
30 def adjust_for_architecture(self):
33 def __init__(self, valobj, params):
34 logger = lldb.formatters.Logger.Logger()
36 self.sys_params = params
37 if not(self.sys_params.types_cache.NSString):
38 self.sys_params.types_cache.NSString = self.valobj.GetTarget(
39 ).FindFirstType('NSString').GetPointerType()
43 logger = lldb.formatters.Logger.Logger()
44 self.adjust_for_architecture()
46 # we need to skip the ISA, plus four other values
47 # that are luckily each a pointer in size
48 # which makes our computation trivial :-)
50 logger = lldb.formatters.Logger.Logger()
51 return 5 * self.sys_params.pointer_size
54 logger = lldb.formatters.Logger.Logger()
56 text = self.valobj.CreateChildAtOffset(
57 "text", self.offset(), self.sys_params.types_cache.NSString)
58 my_string = text.GetSummary()
59 if (my_string is None) or (my_string == ''):
60 statistics.metric_hit(
62 self.valobj.GetName()) + " triggered unknown pointer location")
63 return NSBundleUnknown_SummaryProvider(
64 self.valobj, self.sys_params).url_text()
66 statistics.metric_hit('code_notrun', self.valobj)
70 class NSBundleUnknown_SummaryProvider:
72 def adjust_for_architecture(self):
75 def __init__(self, valobj, params):
76 logger = lldb.formatters.Logger.Logger()
78 self.sys_params = params
82 logger = lldb.formatters.Logger.Logger()
83 self.adjust_for_architecture()
86 logger = lldb.formatters.Logger.Logger()
87 stream = lldb.SBStream()
88 self.valobj.GetExpressionPath(stream)
89 expr = "(NSString*)[" + stream.GetData() + " bundlePath]"
90 url_text_vo = self.valobj.CreateValueFromExpression("path", expr)
91 if url_text_vo.IsValid():
92 return url_text_vo.GetSummary()
93 return '<variable is not NSBundle>'
96 def GetSummary_Impl(valobj):
97 logger = lldb.formatters.Logger.Logger()
99 class_data, wrapper = lldb.runtime.objc.objc_runtime.Utilities.prepare_class_detection(
104 name_string = class_data.class_name()
105 logger >> "class name is: " + str(name_string)
107 if name_string == 'NSBundle':
108 wrapper = NSBundleKnown_SummaryProvider(valobj, class_data.sys_params)
109 # [NSBundle mainBundle] does return an object that is
110 # not correctly filled out for our purposes, so we still
111 # end up having to run code in that case
112 # statistics.metric_hit('code_notrun',valobj)
114 wrapper = NSBundleUnknown_SummaryProvider(
115 valobj, class_data.sys_params)
116 statistics.metric_hit(
124 def NSBundle_SummaryProvider(valobj, dict):
125 logger = lldb.formatters.Logger.Logger()
126 provider = GetSummary_Impl(valobj)
127 if provider is not None:
130 lldb.runtime.objc.objc_runtime.SpecialSituation_Description):
131 return provider.message()
133 summary = provider.url_text()
136 logger >> "got summary " + str(summary)
137 if summary is None or summary == '':
138 summary = '<variable is not NSBundle>'
140 return 'Summary Unavailable'
143 def __lldb_init_module(debugger, dict):
144 debugger.HandleCommand(
145 "type summary add -F NSBundle.NSBundle_SummaryProvider NSBundle")