llvm-project
260 строк · 8.0 Кб
1#!/usr/bin/env python
2
3import lldb4
5
6class value(object):7"""A class that wraps an lldb.SBValue object and returns an object that8can be used as an object with attribytes:\n
9argv = a.value(lldb.frame.FindVariable('argv'))\n
10argv.name - return the name of the value that this object contains\n
11argv.type - return the lldb.SBType for this value
12argv.type_name - return the name of the type
13argv.size - return the byte size of this value
14argv.is_in_scope - return true if this value is currently in scope
15argv.is_pointer - return true if this value is a pointer
16argv.format - return the current format for this value
17argv.value - return the value's value as a string
18argv.summary - return a summary of this value's value
19argv.description - return the runtime description for this value
20argv.location - return a string that represents the values location (address, register, etc)
21argv.target - return the lldb.SBTarget for this value
22argv.process - return the lldb.SBProcess for this value
23argv.thread - return the lldb.SBThread for this value
24argv.frame - return the lldb.SBFrame for this value
25argv.num_children - return the number of children this value has
26argv.children - return a list of sbvalue objects that represents all of the children of this value
27"""
28
29def __init__(self, sbvalue):30self.sbvalue = sbvalue31
32def __nonzero__(self):33return self.sbvalue.__nonzero__()34
35def __repr__(self):36return self.sbvalue.__repr__()37
38def __str__(self):39return self.sbvalue.__str__()40
41def __getitem__(self, key):42if isinstance(key, int):43return value(self.sbvalue.GetChildAtIndex(key, lldb.eNoDynamicValues, True))44raise TypeError45
46def __getattr__(self, name):47if name == "name":48return self.sbvalue.GetName()49if name == "type":50return self.sbvalue.GetType()51if name == "type_name":52return self.sbvalue.GetTypeName()53if name == "size":54return self.sbvalue.GetByteSize()55if name == "is_in_scope":56return self.sbvalue.IsInScope()57if name == "is_pointer":58return self.sbvalue.TypeIsPointerType()59if name == "format":60return self.sbvalue.GetFormat()61if name == "value":62return self.sbvalue.GetValue()63if name == "summary":64return self.sbvalue.GetSummary()65if name == "description":66return self.sbvalue.GetObjectDescription()67if name == "location":68return self.sbvalue.GetLocation()69if name == "target":70return self.sbvalue.GetTarget()71if name == "process":72return self.sbvalue.GetProcess()73if name == "thread":74return self.sbvalue.GetThread()75if name == "frame":76return self.sbvalue.GetFrame()77if name == "num_children":78return self.sbvalue.GetNumChildren()79if name == "children":80# Returns an array of sbvalue objects, one for each child of81# the value for the lldb.SBValue82children = []83for i in range(self.sbvalue.GetNumChildren()):84children.append(85value(self.sbvalue.GetChildAtIndex(i, lldb.eNoDynamicValues, True))86)87return children88raise AttributeError89
90
91class variable(object):92'''A class that treats a lldb.SBValue and allows it to be used just as93a variable would be in code. So if you have a Point structure variable
94in your code, you would be able to do: "pt.x + pt.y"'''
95
96def __init__(self, sbvalue):97self.sbvalue = sbvalue98
99def __nonzero__(self):100return self.sbvalue.__nonzero__()101
102def __repr__(self):103return self.sbvalue.__repr__()104
105def __str__(self):106return self.sbvalue.__str__()107
108def __getitem__(self, key):109# Allow array access if this value has children...110if isinstance(key, int):111return variable(self.sbvalue.GetValueForExpressionPath("[%i]" % key))112raise TypeError113
114def __getattr__(self, name):115child_sbvalue = self.sbvalue.GetChildMemberWithName(name)116if child_sbvalue:117return variable(child_sbvalue)118raise AttributeError119
120def __add__(self, other):121return int(self) + int(other)122
123def __sub__(self, other):124return int(self) - int(other)125
126def __mul__(self, other):127return int(self) * int(other)128
129def __floordiv__(self, other):130return int(self) // int(other)131
132def __mod__(self, other):133return int(self) % int(other)134
135def __divmod__(self, other):136return int(self) % int(other)137
138def __pow__(self, other):139return int(self) ** int(other)140
141def __lshift__(self, other):142return int(self) << int(other)143
144def __rshift__(self, other):145return int(self) >> int(other)146
147def __and__(self, other):148return int(self) & int(other)149
150def __xor__(self, other):151return int(self) ^ int(other)152
153def __or__(self, other):154return int(self) | int(other)155
156def __div__(self, other):157return int(self) / int(other)158
159def __truediv__(self, other):160return int(self) / int(other)161
162def __iadd__(self, other):163result = self.__add__(other)164self.sbvalue.SetValueFromCString(str(result))165return result166
167def __isub__(self, other):168result = self.__sub__(other)169self.sbvalue.SetValueFromCString(str(result))170return result171
172def __imul__(self, other):173result = self.__mul__(other)174self.sbvalue.SetValueFromCString(str(result))175return result176
177def __idiv__(self, other):178result = self.__div__(other)179self.sbvalue.SetValueFromCString(str(result))180return result181
182def __itruediv__(self, other):183result = self.__truediv__(other)184self.sbvalue.SetValueFromCString(str(result))185return result186
187def __ifloordiv__(self, other):188result = self.__floordiv__(self, other)189self.sbvalue.SetValueFromCString(str(result))190return result191
192def __imod__(self, other):193result = self.__and__(self, other)194self.sbvalue.SetValueFromCString(str(result))195return result196
197def __ipow__(self, other):198result = self.__pow__(self, other)199self.sbvalue.SetValueFromCString(str(result))200return result201
202def __ipow__(self, other, modulo):203result = self.__pow__(self, other, modulo)204self.sbvalue.SetValueFromCString(str(result))205return result206
207def __ilshift__(self, other):208result = self.__lshift__(self, other)209self.sbvalue.SetValueFromCString(str(result))210return result211
212def __irshift__(self, other):213result = self.__rshift__(self, other)214self.sbvalue.SetValueFromCString(str(result))215return result216
217def __iand__(self, other):218result = self.__and__(self, other)219self.sbvalue.SetValueFromCString(str(result))220return result221
222def __ixor__(self, other):223result = self.__xor__(self, other)224self.sbvalue.SetValueFromCString(str(result))225return result226
227def __ior__(self, other):228result = self.__ior__(self, other)229self.sbvalue.SetValueFromCString(str(result))230return result231
232def __neg__(self):233return -int(self)234
235def __pos__(self):236return +int(self)237
238def __abs__(self):239return abs(int(self))240
241def __invert__(self):242return ~int(self)243
244def __complex__(self):245return complex(int(self))246
247def __int__(self):248return self.sbvalue.GetValueAsSigned()249
250def __long__(self):251return self.sbvalue.GetValueAsSigned()252
253def __float__(self):254return float(self.sbvalue.GetValueAsSigned())255
256def __oct__(self):257return "0%o" % self.sbvalue.GetValueAsSigned()258
259def __hex__(self):260return "0x%x" % self.sbvalue.GetValueAsSigned()261