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 NSData |
| 9 | import lldb |
| 10 | import ctypes |
| 11 | import objc_runtime |
| 12 | import metrics |
| 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 | # despite the similary to synthetic children providers, these classes are not |
| 21 | # trying to provide anything but the port number of an NSMachPort, so they need not |
| 22 | # obey the interface specification for synthetic children providers |
| 23 | class NSMachPortKnown_SummaryProvider: |
| 24 | def adjust_for_architecture(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 25 | pass |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 26 | |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 27 | def __init__(self, valobj, params): |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 28 | self.valobj = valobj; |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 29 | self.sys_params = params |
| 30 | if not(self.sys_params.types_cache.NSUInteger): |
| 31 | if self.sys_params.is_64_bit: |
| 32 | self.sys_params.types_cache.NSUInteger = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong) |
| 33 | else: |
| 34 | self.sys_params.types_cache.NSUInteger = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 35 | self.update(); |
| 36 | |
| 37 | def update(self): |
| 38 | self.adjust_for_architecture(); |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 39 | |
| 40 | # one pointer is the ISA |
| 41 | # then we have one other internal pointer, plus |
| 42 | # 4 bytes worth of flags. hence, these values |
| 43 | def offset(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 44 | if self.sys_params.is_64_bit: |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 45 | return 20 |
| 46 | else: |
| 47 | return 12 |
| 48 | |
| 49 | def port(self): |
| 50 | vport = self.valobj.CreateChildAtOffset("port", |
| 51 | self.offset(), |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 52 | self.sys_params.types_cache.NSUInteger) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 53 | return vport.GetValueAsUnsigned(0) |
| 54 | |
| 55 | |
| 56 | class NSMachPortUnknown_SummaryProvider: |
| 57 | def adjust_for_architecture(self): |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 58 | pass |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 59 | |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 60 | def __init__(self, valobj, params): |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 61 | self.valobj = valobj; |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 62 | self.sys_params = params |
| 63 | self.update(); |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 64 | |
| 65 | def update(self): |
| 66 | self.adjust_for_architecture(); |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 67 | |
| 68 | def port(self): |
| 69 | stream = lldb.SBStream() |
| 70 | self.valobj.GetExpressionPath(stream) |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame] | 71 | num_children_vo = self.valobj.CreateValueFromExpression("port","(int)[" + stream.GetData() + " machPort]") |
| 72 | if num_children_vo.IsValid(): |
| 73 | return num_children_vo.GetValueAsUnsigned(0) |
| 74 | return '<variable is not NSMachPort>' |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 75 | |
| 76 | |
| 77 | def GetSummary_Impl(valobj): |
| 78 | global statistics |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame] | 79 | class_data,wrapper = objc_runtime.Utilities.prepare_class_detection(valobj,statistics) |
| 80 | if wrapper: |
| 81 | return wrapper |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 82 | |
| 83 | name_string = class_data.class_name() |
| 84 | if name_string == 'NSMachPort': |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 85 | wrapper = NSMachPortKnown_SummaryProvider(valobj, class_data.sys_params) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 86 | statistics.metric_hit('code_notrun',valobj) |
| 87 | else: |
Enrico Granata | cfdafa3 | 2012-03-05 19:56:33 +0000 | [diff] [blame] | 88 | wrapper = NSMachPortUnknown_SummaryProvider(valobj, class_data.sys_params) |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 89 | statistics.metric_hit('unknown_class',str(valobj) + " seen as " + name_string) |
| 90 | return wrapper; |
| 91 | |
| 92 | def NSMachPort_SummaryProvider (valobj,dict): |
| 93 | provider = GetSummary_Impl(valobj); |
| 94 | if provider != None: |
Enrico Granata | 3f1052b | 2012-03-13 21:52:00 +0000 | [diff] [blame] | 95 | if isinstance(provider,objc_runtime.SpecialSituation_Description): |
| 96 | return provider.message() |
| 97 | try: |
| 98 | summary = provider.port(); |
| 99 | except: |
| 100 | summary = None |
| 101 | if summary == None: |
| 102 | summary = '<variable is not NSMachPort>' |
| 103 | if isinstance(summary, basestring): |
| 104 | return summay |
| 105 | return 'mach port: ' + str(summary) |
| 106 | return 'Summary Unavailable' |
Enrico Granata | eb4a479 | 2012-02-23 23:10:27 +0000 | [diff] [blame] | 107 | |
| 108 | def __lldb_init_module(debugger,dict): |
| 109 | debugger.HandleCommand("type summary add -F NSMachPort.NSMachPort_SummaryProvider NSMachPort") |