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