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 class NSNotification |
| 9 | import objc_runtime |
| 10 | import metrics |
| 11 | import CFString |
| 12 | import lldb |
| 13 | |
| 14 | statistics = metrics.Metrics() |
| 15 | statistics.add_metric('invalid_isa') |
| 16 | statistics.add_metric('invalid_pointer') |
| 17 | statistics.add_metric('unknown_class') |
| 18 | statistics.add_metric('code_notrun') |
| 19 | |
| 20 | class NSConcreteNotification_SummaryProvider: |
| 21 | def adjust_for_architecture(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 22 | pass |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 23 | |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 24 | def __init__(self, valobj, params): |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 25 | self.valobj = valobj; |
Enrico Granata | eb55ad4 | 2012-03-09 00:45:19 +0000 | [diff] [blame] | 26 | self.sys_params = params |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 27 | if not (self.sys_params.types_cache.id): |
| 28 | self.sys_params.types_cache.id = self.valobj.GetType().GetBasicType(lldb.eBasicTypeObjCID) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 29 | self.update(); |
| 30 | |
| 31 | def update(self): |
| 32 | self.adjust_for_architecture(); |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 33 | |
| 34 | # skip the ISA and go to the name pointer |
| 35 | def offset(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 36 | return self.sys_params.pointer_size |
Enrico Granata | eb55ad4 | 2012-03-09 00:45:19 +0000 | [diff] [blame] | 37 | |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 38 | def name(self): |
| 39 | string_ptr = self.valobj.CreateChildAtOffset("name", |
| 40 | self.offset(), |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 41 | self.sys_params.types_cache.id) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 42 | return CFString.CFString_SummaryProvider(string_ptr,None) |
| 43 | |
| 44 | |
| 45 | class NSNotificationUnknown_SummaryProvider: |
| 46 | def adjust_for_architecture(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 47 | pass |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 48 | |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 49 | def __init__(self, valobj, params): |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 50 | self.valobj = valobj; |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 51 | self.sys_params = params |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 52 | self.update() |
| 53 | |
| 54 | def update(self): |
| 55 | self.adjust_for_architecture(); |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 56 | |
| 57 | def name(self): |
| 58 | stream = lldb.SBStream() |
| 59 | self.valobj.GetExpressionPath(stream) |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame^] | 60 | name_vo = self.valobj.CreateValueFromExpression("name","(NSString*)[" + stream.GetData() + " name]") |
| 61 | if name_vo.IsValid(): |
| 62 | return CFString.CFString_SummaryProvider(name_vo,None) |
| 63 | return '<variable is not NSNotification>' |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 64 | |
| 65 | |
| 66 | def GetSummary_Impl(valobj): |
| 67 | global statistics |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame^] | 68 | class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics) |
| 69 | if wrapper: |
| 70 | return wrapper |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 71 | |
| 72 | name_string = class_data.class_name() |
| 73 | if name_string == 'NSConcreteNotification': |
Enrico Granata | eb55ad4 | 2012-03-09 00:45:19 +0000 | [diff] [blame] | 74 | wrapper = NSConcreteNotification_SummaryProvider(valobj, class_data.sys_params) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 75 | statistics.metric_hit('code_notrun',valobj) |
| 76 | else: |
Enrico Granata | eb55ad4 | 2012-03-09 00:45:19 +0000 | [diff] [blame] | 77 | wrapper = NSNotificationUnknown_SummaryProvider(valobj, class_data.sys_params) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 78 | statistics.metric_hit('unknown_class',str(valobj) + " seen as " + name_string) |
| 79 | return wrapper; |
| 80 | |
| 81 | def NSNotification_SummaryProvider (valobj,dict): |
| 82 | provider = GetSummary_Impl(valobj); |
| 83 | if provider != None: |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame^] | 84 | if isinstance(provider,objc_runtime.SpecialSituation_Description): |
| 85 | return provider.message() |
| 86 | try: |
| 87 | summary = provider.name(); |
| 88 | except: |
| 89 | summary = None |
| 90 | if summary == None: |
| 91 | summary = '<variable is not NSNotification>' |
| 92 | return str(summary) |
| 93 | return 'Summary Unavailable' |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 94 | |
| 95 | def __lldb_init_module(debugger,dict): |
| 96 | debugger.HandleCommand("type summary add -F NSNotification.NSNotification_SummaryProvider NSNotification") |