Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame] | 1 | """ |
| 2 | LLDB AppKit formatters |
| 3 | |
| 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. |
| 7 | """ |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 8 | # summary provider for NSBundle |
| 9 | import lldb |
| 10 | import ctypes |
| 11 | import objc_runtime |
| 12 | import metrics |
| 13 | import NSURL |
| 14 | |
| 15 | statistics = 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') |
| 20 | |
| 21 | # despite the similary to synthetic children providers, these classes are not |
| 22 | # trying to provide anything but a summary for an NSURL, so they need not |
| 23 | # obey the interface specification for synthetic children providers |
| 24 | class NSBundleKnown_SummaryProvider: |
| 25 | def adjust_for_architecture(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 26 | pass |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 27 | |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 28 | def __init__(self, valobj, params): |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 29 | self.valobj = valobj; |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 30 | self.sys_params = params |
| 31 | if not(self.sys_params.types_cache.NSString): |
| 32 | self.sys_params.types_cache.NSString = self.valobj.GetTarget().FindFirstType('NSString').GetPointerType() |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 33 | self.update(); |
| 34 | |
| 35 | def update(self): |
| 36 | self.adjust_for_architecture(); |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 37 | |
| 38 | # we need to skip the ISA, plus four other values |
| 39 | # that are luckily each a pointer in size |
| 40 | # which makes our computation trivial :-) |
| 41 | def offset(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 42 | return 5 * self.sys_params.pointer_size |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 43 | |
| 44 | def url_text(self): |
| 45 | global statistics |
| 46 | text = self.valobj.CreateChildAtOffset("text", |
| 47 | self.offset(), |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 48 | self.sys_params.types_cache.NSString) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 49 | my_string = text.GetSummary() |
| 50 | if (my_string == None) or (my_string == ''): |
| 51 | statistics.metric_hit('unknown_class',str(self.valobj) + " triggered unkown pointer location") |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 52 | return NSBundleUnknown_SummaryProvider(self.valobj, self.sys_params).url_text() |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 53 | else: |
| 54 | statistics.metric_hit('code_notrun',self.valobj) |
| 55 | return my_string |
| 56 | |
| 57 | |
| 58 | class NSBundleUnknown_SummaryProvider: |
| 59 | def adjust_for_architecture(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 60 | pass |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 61 | |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 62 | def __init__(self, valobj, params): |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 63 | self.valobj = valobj; |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 64 | self.sys_params = params |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 65 | self.update() |
| 66 | |
| 67 | def update(self): |
| 68 | self.adjust_for_architecture(); |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 69 | |
| 70 | def url_text(self): |
| 71 | stream = lldb.SBStream() |
| 72 | self.valobj.GetExpressionPath(stream) |
| 73 | expr = "(NSString*)[" + stream.GetData() + " bundlePath]" |
| 74 | url_text_vo = self.valobj.CreateValueFromExpression("path",expr); |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame] | 75 | if url_text_vo.IsValid(): |
| 76 | return url_text_vo.GetSummary() |
| 77 | return '<variable is not NSBundle>' |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 78 | |
| 79 | |
| 80 | def GetSummary_Impl(valobj): |
| 81 | global statistics |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame] | 82 | class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics) |
| 83 | if wrapper: |
| 84 | return wrapper |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 85 | |
| 86 | name_string = class_data.class_name() |
| 87 | if name_string == 'NSBundle': |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 88 | wrapper = NSBundleKnown_SummaryProvider(valobj, class_data.sys_params) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 89 | # [NSBundle mainBundle] does return an object that is |
| 90 | # not correctly filled out for our purposes, so we still |
| 91 | # end up having to run code in that case |
| 92 | #statistics.metric_hit('code_notrun',valobj) |
| 93 | else: |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 94 | wrapper = NSBundleUnknown_SummaryProvider(valobj, class_data.sys_params) |
Enrico Granata | a7daeeb | 2012-03-30 00:51:12 +0000 | [diff] [blame^] | 95 | statistics.metric_hit('unknown_class',valobj.GetName() + " seen as " + name_string) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 96 | return wrapper; |
| 97 | |
| 98 | def NSBundle_SummaryProvider (valobj,dict): |
| 99 | provider = GetSummary_Impl(valobj); |
| 100 | if provider != None: |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame] | 101 | if isinstance(provider,objc_runtime.SpecialSituation_Description): |
| 102 | return provider.message() |
| 103 | try: |
| 104 | summary = provider.url_text(); |
| 105 | except: |
| 106 | summary = None |
| 107 | if summary == None or summary == '': |
| 108 | summary = '<variable is not NSBundle>' |
| 109 | return summary |
| 110 | return 'Summary Unavailable' |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 111 | |
| 112 | def __lldb_init_module(debugger,dict): |
| 113 | debugger.HandleCommand("type summary add -F NSBundle.NSBundle_SummaryProvider NSBundle") |