[Lldb-commits] [lldb] r152888 - in /lldb/trunk/examples/synthetic: CFString.py StdListSynthProvider.py StdMapSynthProvider.py StdVectorSynthProvider.py objc.py
Enrico Granata
egranata at apple.com
Thu Mar 15 18:15:31 PDT 2012
Author: enrico
Date: Thu Mar 15 20:15:31 2012
New Revision: 152888
URL: http://llvm.org/viewvc/llvm-project?rev=152888&view=rev
Log:
Deleting obsolete files
Removed:
lldb/trunk/examples/synthetic/CFString.py
lldb/trunk/examples/synthetic/StdListSynthProvider.py
lldb/trunk/examples/synthetic/StdMapSynthProvider.py
lldb/trunk/examples/synthetic/StdVectorSynthProvider.py
lldb/trunk/examples/synthetic/objc.py
Removed: lldb/trunk/examples/synthetic/CFString.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/synthetic/CFString.py?rev=152887&view=auto
==============================================================================
--- lldb/trunk/examples/synthetic/CFString.py (original)
+++ lldb/trunk/examples/synthetic/CFString.py (removed)
@@ -1,237 +0,0 @@
-# synthetic children and summary provider for CFString
-# (and related NSString class)
-import lldb
-
-def CFString_SummaryProvider (valobj,dict):
- provider = CFStringSynthProvider(valobj,dict);
- if provider.invalid == False:
- return '@'+provider.get_child_at_index(provider.get_child_index("content")).GetSummary();
- return ''
-
-class CFStringSynthProvider:
- def __init__(self,valobj,dict):
- self.valobj = valobj;
- self.update()
-
- # children other than "content" are for debugging only and must not be used in production code
- def num_children(self):
- if self.invalid:
- return 0;
- return 6;
-
- def read_unicode(self, pointer):
- process = self.valobj.GetTarget().GetProcess()
- error = lldb.SBError()
- pystr = u''
- # cannot do the read at once because the length value has
- # a weird encoding. better play it safe here
- while True:
- content = process.ReadMemory(pointer, 2, error)
- new_bytes = bytearray(content)
- b0 = new_bytes[0]
- b1 = new_bytes[1]
- pointer = pointer + 2
- if b0 == 0 and b1 == 0:
- break
- # rearrange bytes depending on endianness
- # (do we really need this or is Cocoa going to
- # use Windows-compatible little-endian even
- # if the target is big endian?)
- if self.is_little:
- value = b1 * 256 + b0
- else:
- value = b0 * 256 + b1
- pystr = pystr + unichr(value)
- return pystr
-
- # handle the special case strings
- # only use the custom code for the tested LP64 case
- def handle_special(self):
- if self.lp64 == False:
- # for 32bit targets, use safe ObjC code
- return self.handle_unicode_string_safe()
- offset = 12
- pointer = self.valobj.GetValueAsUnsigned(0) + offset
- pystr = self.read_unicode(pointer)
- return self.valobj.CreateValueFromExpression("content",
- "(char*)\"" + pystr.encode('utf-8') + "\"")
-
- # last resort call, use ObjC code to read; the final aim is to
- # be able to strip this call away entirely and only do the read
- # ourselves
- def handle_unicode_string_safe(self):
- return self.valobj.CreateValueFromExpression("content",
- "(char*)\"" + self.valobj.GetObjectDescription() + "\"");
-
- def handle_unicode_string(self):
- # step 1: find offset
- if self.inline:
- pointer = self.valobj.GetValueAsUnsigned(0) + self.size_of_cfruntime_base();
- if self.explicit == False:
- # untested, use the safe code path
- return self.handle_unicode_string_safe();
- else:
- # not sure why 8 bytes are skipped here
- # (lldb) mem read -c 50 0x00000001001154f0
- # 0x1001154f0: 98 1a 85 71 ff 7f 00 00 90 07 00 00 01 00 00 00 ...q?...........
- # 0x100115500: 03 00 00 00 00 00 00 00 *c3 03 78 00 78 00 00 00 ........?.x.x...
- # 0x100115510: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
- # 0x100115520: 00 00 ..
- # content begins at * (i.e. 8 bytes into variants, skipping void* buffer in
- # __notInlineImmutable1 entirely, while the length byte is correctly located
- # for an inline string)
- pointer = pointer + 8;
- else:
- pointer = self.valobj.GetValueAsUnsigned(0) + self.size_of_cfruntime_base();
- # read 8 bytes here and make an address out of them
- vopointer = self.valobj.CreateChildAtOffset("dummy",
- pointer,self.valobj.GetType().GetBasicType(lldb.eBasicTypeChar).GetPointerType());
- pointer = vopointer.GetValueAsUnsigned(0)
- # step 2: read Unicode data at pointer
- pystr = self.read_unicode(pointer)
- # step 3: return it
- return self.valobj.CreateValueFromExpression("content",
- "(char*)\"" + pystr.encode('utf-8') + "\"")
-
- # we read at "the right place" into the __CFString object instead of running code
- # we are replicating the functionality of __CFStrContents in CFString.c here
- def handle_UTF8_inline(self):
- offset = int(self.valobj.GetValue(), 0) + self.size_of_cfruntime_base();
- if self.explicit == False:
- offset = offset + 1;
- return self.valobj.CreateValueFromAddress("content",
- offset, self.valobj.GetType().GetBasicType(lldb.eBasicTypeChar)).AddressOf();
-
- def handle_UTF8_not_inline(self):
- offset = self.size_of_cfruntime_base();
- return self.valobj.CreateChildAtOffset("content",
- offset,self.valobj.GetType().GetBasicType(lldb.eBasicTypeChar).GetPointerType());
-
- def get_child_at_index(self,index):
- if index == 0:
- return self.valobj.CreateValueFromExpression("mutable",
- str(int(self.mutable)));
- if index == 1:
- return self.valobj.CreateValueFromExpression("inline",
- str(int(self.inline)));
- if index == 2:
- return self.valobj.CreateValueFromExpression("explicit",
- str(int(self.explicit)));
- if index == 3:
- return self.valobj.CreateValueFromExpression("unicode",
- str(int(self.unicode)));
- if index == 4:
- return self.valobj.CreateValueFromExpression("special",
- str(int(self.special)));
- if index == 5:
- if self.unicode == True:
- return self.handle_unicode_string();
- elif self.special == True:
- return self.handle_special();
- elif self.inline == True:
- return self.handle_UTF8_inline();
- else:
- return self.handle_UTF8_not_inline();
-
- def get_child_index(self,name):
- if name == "content":
- return self.num_children() - 1;
- if name == "mutable":
- return 0;
- if name == "inline":
- return 1;
- if name == "explicit":
- return 2;
- if name == "unicode":
- return 3;
- if name == "special":
- return 4;
-
- def is_64bit(self):
- return self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8
-
- def is_little_endian(self):
- return self.valobj.GetTarget().GetProcess().GetByteOrder() == lldb.eByteOrderLittle
-
- # CFRuntimeBase is defined as having an additional
- # 4 bytes (padding?) on LP64 architectures
- # to get its size we add up sizeof(pointer)+4
- # and then add 4 more bytes if we are on a 64bit system
- def size_of_cfruntime_base(self):
- if self.lp64 == True:
- return 8+4+4;
- else:
- return 4+4;
-
- # the info bits are part of the CFRuntimeBase structure
- # to get at them we have to skip a uintptr_t and then get
- # at the least-significant byte of a 4 byte array. If we are
- # on big-endian this means going to byte 3, if we are on
- # little endian (OSX & iOS), this means reading byte 0
- def offset_of_info_bits(self):
- if self.lp64 == True:
- offset = 8;
- else:
- offset = 4;
- if self.is_little == False:
- offset = offset + 3;
- return offset;
-
- def read_info_bits(self):
- cfinfo = self.valobj.CreateChildAtOffset("cfinfo",
- self.offset_of_info_bits(),
- self.valobj.GetType().GetBasicType(lldb.eBasicTypeChar));
- cfinfo.SetFormat(11)
- info = cfinfo.GetValue();
- if info != None:
- self.invalid = False;
- return int(info,0);
- else:
- self.invalid = True;
- return None;
-
- # calculating internal flag bits of the CFString object
- # this stuff is defined and discussed in CFString.c
- def is_mutable(self):
- return (self.info_bits & 1) == 1;
-
- def is_inline(self):
- return (self.info_bits & 0x60) == 0;
-
- # this flag's name is ambiguous, it turns out
- # we must skip a length byte to get at the data
- # when this flag is False
- def has_explicit_length(self):
- return (self.info_bits & (1 | 4)) != 4;
-
- # probably a subclass of NSString. obtained this from [str pathExtension]
- # here info_bits = 0 and Unicode data at the start of the padding word
- # in the long run using the isa value might be safer as a way to identify this
- # instead of reading the info_bits
- def is_special_case(self):
- return self.info_bits == 0;
-
- def is_unicode(self):
- return (self.info_bits & 0x10) == 0x10;
-
- # preparing ourselves to read into memory
- # by adjusting architecture-specific info
- def adjust_for_architecture(self):
- self.lp64 = self.is_64bit();
- self.is_little = self.is_little_endian();
-
- # reading info bits out of the CFString and computing
- # useful values to get at the real data
- def compute_flags(self):
- self.info_bits = self.read_info_bits();
- if self.info_bits == None:
- return;
- self.mutable = self.is_mutable();
- self.inline = self.is_inline();
- self.explicit = self.has_explicit_length();
- self.unicode = self.is_unicode();
- self.special = self.is_special_case();
-
- def update(self):
- self.adjust_for_architecture();
- self.compute_flags();
\ No newline at end of file
Removed: lldb/trunk/examples/synthetic/StdListSynthProvider.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/synthetic/StdListSynthProvider.py?rev=152887&view=auto
==============================================================================
--- lldb/trunk/examples/synthetic/StdListSynthProvider.py (original)
+++ lldb/trunk/examples/synthetic/StdListSynthProvider.py (removed)
@@ -1,64 +0,0 @@
-import re
-class StdListSynthProvider:
-
- def __init__(self, valobj, dict):
- self.valobj = valobj
- self.update()
-
- def num_children(self):
- next_val = self.next.GetValueAsUnsigned(0)
- prev_val = self.prev.GetValueAsUnsigned(0)
- # After a std::list has been initialized, both next and prev will be non-NULL
- if next_val == 0 or prev_val == 0:
- return 0
- if next_val == self.node_address:
- return 0
- if next_val == prev_val:
- return 1
- size = 2
- current = self.next
- while current.GetChildMemberWithName('_M_next').GetValueAsUnsigned(0) != self.node_address:
- size = size + 1
- current = current.GetChildMemberWithName('_M_next')
- return (size - 1)
-
- def get_child_index(self,name):
- return int(name.lstrip('[').rstrip(']'))
-
- def get_child_at_index(self,index):
- if index >= self.num_children():
- return None;
- offset = index
- current = self.next
- while offset > 0:
- current = current.GetChildMemberWithName('_M_next')
- offset = offset - 1
- return current.CreateChildAtOffset('['+str(index)+']',2*current.GetType().GetByteSize(),self.data_type)
-
- def extract_type_name(self,name):
- self.type_name = name[16:]
- index = 2
- count_of_template = 1
- while index < len(self.type_name):
- if self.type_name[index] == '<':
- count_of_template = count_of_template + 1
- elif self.type_name[index] == '>':
- count_of_template = count_of_template - 1
- elif self.type_name[index] == ',' and count_of_template == 1:
- self.type_name = self.type_name[:index]
- break
- index = index + 1
- self.type_name_nospaces = self.type_name.replace(", ", ",")
-
- def update(self):
- impl = self.valobj.GetChildMemberWithName('_M_impl')
- node = impl.GetChildMemberWithName('_M_node')
- self.extract_type_name(impl.GetType().GetName())
- self.node_address = self.valobj.AddressOf().GetValueAsUnsigned(0)
- self.next = node.GetChildMemberWithName('_M_next')
- self.prev = node.GetChildMemberWithName('_M_prev')
- self.data_type = node.GetTarget().FindFirstType(self.type_name)
- # tries to fight against a difference in formatting type names between gcc and clang
- if self.data_type.IsValid() == False:
- self.data_type = node.GetTarget().FindFirstType(self.type_name_nospaces)
- self.data_size = self.data_type.GetByteSize()
Removed: lldb/trunk/examples/synthetic/StdMapSynthProvider.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/synthetic/StdMapSynthProvider.py?rev=152887&view=auto
==============================================================================
--- lldb/trunk/examples/synthetic/StdMapSynthProvider.py (original)
+++ lldb/trunk/examples/synthetic/StdMapSynthProvider.py (removed)
@@ -1,112 +0,0 @@
-import re
-
-class StdMapSynthProvider:
-
- def __init__(self, valobj, dict):
- self.valobj = valobj;
- self.update()
-
- def update(self):
- self.Mt = self.valobj.GetChildMemberWithName('_M_t')
- self.Mimpl = self.Mt.GetChildMemberWithName('_M_impl')
- self.Mheader = self.Mimpl.GetChildMemberWithName('_M_header')
- # from libstdc++ implementation of _M_root for rbtree
- self.Mroot = self.Mheader.GetChildMemberWithName('_M_parent')
- # the stuff into the tree is actually a std::pair<const key, value>
- # life would be much easier if gcc had a coherent way to print out
- # template names in debug info
- self.expand_clang_type_name()
- self.expand_gcc_type_name()
- self.data_type = self.Mt.GetTarget().FindFirstType(self.clang_type_name)
- if self.data_type.IsValid() == False:
- self.data_type = self.Mt.GetTarget().FindFirstType(self.gcc_type_name)
- self.data_size = self.data_type.GetByteSize()
- self.skip_size = self.Mheader.GetType().GetByteSize()
-
- def expand_clang_type_name(self):
- type_name = self.Mimpl.GetType().GetName()
- index = type_name.find("std::pair<")
- type_name = type_name[index+5:]
- index = 6
- template_count = 1
- while index < len(type_name):
- if type_name[index] == '<':
- template_count = template_count + 1
- elif type_name[index] == '>' and template_count == 1:
- type_name = type_name[:index+1]
- break
- elif type_name[index] == '>':
- template_count = template_count - 1
- index = index + 1;
- self.clang_type_name = type_name
-
- def expand_gcc_type_name(self):
- type_name = self.Mt.GetType().GetName()
- index = type_name.find("std::pair<")
- type_name = type_name[index+5:]
- index = 6
- template_count = 1
- while index < len(type_name):
- if type_name[index] == '<':
- template_count = template_count + 1
- elif type_name[index] == '>' and template_count == 1:
- type_name = type_name[:index+1]
- break
- elif type_name[index] == '>':
- template_count = template_count - 1
- elif type_name[index] == ' ' and template_count == 1 and type_name[index-1] == ',':
- type_name = type_name[0:index] + type_name[index+1:]
- index = index - 1
- index = index + 1;
- self.gcc_type_name = type_name
-
- def num_children(self):
- root_ptr_val = self.node_ptr_value(self.Mroot)
- if root_ptr_val == 0:
- return 0;
- return self.Mimpl.GetChildMemberWithName('_M_node_count').GetValueAsUnsigned(0)
-
- def get_child_index(self,name):
- return int(name.lstrip('[').rstrip(']'))
-
- def get_child_at_index(self,index):
- if index >= self.num_children():
- return None;
- offset = index
- current = self.left(self.Mheader);
- while offset > 0:
- current = self.increment_node(current)
- offset = offset - 1;
- # skip all the base stuff and get at the data
- return current.CreateChildAtOffset('['+str(index)+']',self.skip_size,self.data_type)
-
- # utility functions
- def node_ptr_value(self,node):
- return node.GetValueAsUnsigned(0)
-
- def right(self,node):
- return node.GetChildMemberWithName("_M_right");
-
- def left(self,node):
- return node.GetChildMemberWithName("_M_left");
-
- def parent(self,node):
- return node.GetChildMemberWithName("_M_parent");
-
- # from libstdc++ implementation of iterator for rbtree
- def increment_node(self,node):
- if self.node_ptr_value(self.right(node)) != 0:
- x = self.right(node);
- while self.node_ptr_value(self.left(x)) != 0:
- x = self.left(x);
- return x;
- else:
- x = node;
- y = self.parent(x)
- while(self.node_ptr_value(x) == self.node_ptr_value(self.right(y))):
- x = y;
- y = self.parent(y);
- if self.node_ptr_value(self.right(x)) != self.node_ptr_value(y):
- x = y;
- return x;
-
Removed: lldb/trunk/examples/synthetic/StdVectorSynthProvider.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/synthetic/StdVectorSynthProvider.py?rev=152887&view=auto
==============================================================================
--- lldb/trunk/examples/synthetic/StdVectorSynthProvider.py (original)
+++ lldb/trunk/examples/synthetic/StdVectorSynthProvider.py (removed)
@@ -1,71 +0,0 @@
-class StdVectorSynthProvider:
-
- def __init__(self, valobj, dict):
- self.valobj = valobj;
- self.update() # initialize this provider
-
- def num_children(self):
- start_val = self.start.GetValueAsUnsigned(0) # read _M_start
- finish_val = self.finish.GetValueAsUnsigned(0) # read _M_finish
- end_val = self.end.GetValueAsUnsigned(0) # read _M_end_of_storage
-
- # Before a vector has been constructed, it will contain bad values
- # so we really need to be careful about the length we return since
- # unitialized data can cause us to return a huge number. We need
- # to also check for any of the start, finish or end of storage values
- # being zero (NULL). If any are, then this vector has not been
- # initialized yet and we should return zero
-
- # Make sure nothing is NULL
- if start_val == 0 or finish_val == 0 or end_val == 0:
- return 0
- # Make sure start is less than finish
- if start_val >= finish_val:
- return 0
- # Make sure finish is less than or equal to end of storage
- if finish_val > end_val:
- return 0
-
- # pointer arithmetic: (_M_finish - _M_start) would return the number of
- # items of type T contained in the vector. because Python has no way to know
- # that we want to subtract two pointers instead of two integers, we have to divide
- # by sizeof(T) to be equivalent to the C++ pointer expression
- num_children = (finish_val-start_val)/self.data_size
- return num_children
-
- # we assume we are getting children named [0] thru [N-1]
- # if for some reason our child name is not in this format,
- # do not bother to show it, and return an invalid value
- def get_child_index(self,name):
- try:
- return int(name.lstrip('[').rstrip(']'))
- except:
- return -1;
-
- def get_child_at_index(self,index):
- # LLDB itself should never query for children < 0, but this might come
- # from someone asking for a nonexisting child and getting -1 as index
- if index < 0:
- return None
- if index >= self.num_children():
- return None;
- # *(_M_start + index), or equivalently _M_start[index] is C++ code to
- # read the index-th item of the vector. in Python we must make an offset
- # that is index * sizeof(T), and then grab the value at that offset from
- # _M_start
- offset = index * self.data_size # index * sizeof(T)
- return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type) # *(_M_start + index)
-
- # an std::vector contains an object named _M_impl, which in turn contains
- # three pointers, _M_start, _M_end and _M_end_of_storage. _M_start points to the
- # beginning of the data area, _M_finish points to where the current vector elements
- # finish, and _M_end_of_storage is the end of the currently alloc'ed memory portion
- # (to allow resizing, a vector may allocate more memory than required)
- def update(self):
- impl = self.valobj.GetChildMemberWithName('_M_impl')
- self.start = impl.GetChildMemberWithName('_M_start')
- self.finish = impl.GetChildMemberWithName('_M_finish')
- self.end = impl.GetChildMemberWithName('_M_end_of_storage')
- self.data_type = self.start.GetType().GetPointeeType() # _M_start is defined as a T*
- self.data_size = self.data_type.GetByteSize() # sizeof(T)
-
Removed: lldb/trunk/examples/synthetic/objc.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/synthetic/objc.py?rev=152887&view=auto
==============================================================================
--- lldb/trunk/examples/synthetic/objc.py (original)
+++ lldb/trunk/examples/synthetic/objc.py (removed)
@@ -1,128 +0,0 @@
-"""
-Objective-C runtime wrapper - Replicates the behavior of AppleObjCRuntimeV2.cpp in Python code
-for the benefit of synthetic children providers and Python summaries
-
-part of The LLVM Compiler Infrastructure
-This file is distributed under the University of Illinois Open Source
-License. See LICENSE.TXT for details.
-"""
-import lldb
-
-class ObjCRuntime:
-
- def __init__(self,valobj = None):
- self.valobj = valobj;
- self.adjust_for_architecture()
-
- def adjust_for_architecture(self):
- self.lp64 = (self.valobj.GetTarget().GetProcess().GetAddressByteSize() == 8)
- self.is_little = (self.valobj.GetTarget().GetProcess().GetByteOrder() == lldb.eByteOrderLittle)
- self.pointer_size = self.valobj.GetTarget().GetProcess().GetAddressByteSize()
- self.addr_type = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
- self.addr_ptr_type = self.addr_type.GetPointerType()
-
- def is_tagged(self):
- if valobj is None:
- return None
- ptr_value = self.valobj.GetPointerValue()
- if (ptr_value % 2) == 1:
- return True
- else:
- return False
-
- def read_ascii(self, pointer):
- process = self.valobj.GetTarget().GetProcess()
- error = lldb.SBError()
- pystr = ''
- # cannot do the read at once because there is no length byte
- while True:
- content = process.ReadMemory(pointer, 1, error)
- new_bytes = bytearray(content)
- b0 = new_bytes[0]
- pointer = pointer + 1
- if b0 == 0:
- break
- pystr = pystr + chr(b0)
- return pystr
-
- def read_isa(self):
- # read ISA pointer
- isa_pointer = self.valobj.CreateChildAtOffset("cfisa",
- 0,
- self.addr_ptr_type)
- if isa_pointer == None or isa_pointer.IsValid() == False:
- return None;
- if isa_pointer.GetValue() == None:
- return None;
- isa = int(isa_pointer.GetValue(), 0)
- if isa == 0 or isa == None:
- return None;
- return isa
-
-
- def get_parent_class(self, isa = None):
- if isa is None:
- isa = self.read_isa()
- # read superclass pointer
- rw_pointer = isa + self.pointer_size
- rw_object = self.valobj.CreateValueFromAddress("parent_isa",
- rw_pointer,
- self.addr_type)
- if rw_object == None or rw_object.IsValid() == False:
- return None;
- if rw_object.GetValue() == None:
- return None;
- rw = int(rw_object.GetValue(), 0)
- if rw == 0 or rw == None:
- return None;
- return rw
-
- def get_class_name(self, isa = None):
- if isa is None:
- isa = self.read_isa()
- # read rw pointer
- rw_pointer = isa + 4 * self.pointer_size
- rw_object = self.valobj.CreateValueFromAddress("rw",
- rw_pointer,
- self.addr_type)
- if rw_object == None or rw_object.IsValid() == False:
- return None;
- if rw_object.GetValue() == None:
- return None;
- rw = int(rw_object.GetValue(), 0)
- if rw == 0 or rw == None:
- return None;
-
- # read data pointer
- data_pointer = rw + 8
- data_object = self.valobj.CreateValueFromAddress("data",
- data_pointer,
- self.addr_type)
- if data_object == None or data_object.IsValid() == False:
- return None;
- if data_object.GetValue() == None:
- return None;
- data = int(data_object.GetValue(), 0)
- if data == 0 or data == None:
- return None;
-
- # read ro pointer
- ro_pointer = data + 12 + self.pointer_size
- if self.lp64:
- ro_pointer += 4
- ro_object = self.valobj.CreateValueFromAddress("ro",
- ro_pointer,
- self.addr_type)
- if ro_object == None or ro_object.IsValid() == False:
- return None;
- if ro_object.GetValue() == None:
- return None;
- name_pointer = int(ro_object.GetValue(), 0)
- if name_pointer == 0 or name_pointer == None:
- return None;
-
- # now read the actual name and compare it to known stuff
- name_string = self.read_ascii(name_pointer)
- if (name_string.startswith("NSKVONotify")):
- return self.get_class_name(self.get_parent_class())
- return name_string
More information about the lldb-commits
mailing list