js/src/gdb/mozilla/JSString.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 # Pretty-printers for SpiderMonkey strings.
michael@0 2
michael@0 3 import gdb
michael@0 4 import mozilla.prettyprinters
michael@0 5 from mozilla.prettyprinters import pretty_printer, ptr_pretty_printer
michael@0 6
michael@0 7 # Forget any printers from previous loads of this module.
michael@0 8 mozilla.prettyprinters.clear_module_printers(__name__)
michael@0 9
michael@0 10 # Cache information about the JSString type for this objfile.
michael@0 11 class JSStringTypeCache(object):
michael@0 12 def __init__(self, cache):
michael@0 13 dummy = gdb.Value(0).cast(cache.JSString_ptr_t)
michael@0 14 self.LENGTH_SHIFT = dummy['LENGTH_SHIFT']
michael@0 15 self.FLAGS_MASK = dummy['FLAGS_MASK']
michael@0 16 self.ROPE_FLAGS = dummy['ROPE_FLAGS']
michael@0 17 self.ATOM_BIT = dummy['ATOM_BIT']
michael@0 18
michael@0 19 class Common(mozilla.prettyprinters.Pointer):
michael@0 20 def __init__(self, value, cache):
michael@0 21 super(Common, self).__init__(value, cache)
michael@0 22 if not cache.mod_JSString:
michael@0 23 cache.mod_JSString = JSStringTypeCache(cache)
michael@0 24 self.stc = cache.mod_JSString
michael@0 25
michael@0 26 @ptr_pretty_printer("JSString")
michael@0 27 class JSStringPtr(Common):
michael@0 28 def display_hint(self):
michael@0 29 return "string"
michael@0 30
michael@0 31 def jschars(self):
michael@0 32 d = self.value['d']
michael@0 33 lengthAndFlags = d['lengthAndFlags']
michael@0 34 length = lengthAndFlags >> self.stc.LENGTH_SHIFT
michael@0 35 is_rope = (lengthAndFlags & self.stc.FLAGS_MASK) == self.stc.ROPE_FLAGS
michael@0 36 if is_rope:
michael@0 37 for c in JSStringPtr(d['u1']['left'], self.cache).jschars():
michael@0 38 yield c
michael@0 39 for c in JSStringPtr(d['s']['u2']['right'], self.cache).jschars():
michael@0 40 yield c
michael@0 41 else:
michael@0 42 chars = d['u1']['chars']
michael@0 43 for i in xrange(length):
michael@0 44 yield chars[i]
michael@0 45
michael@0 46 def to_string(self):
michael@0 47 s = u''
michael@0 48 for c in self.jschars():
michael@0 49 s += unichr(c)
michael@0 50 return s
michael@0 51
michael@0 52 @ptr_pretty_printer("JSAtom")
michael@0 53 class JSAtomPtr(Common):
michael@0 54 def to_string(self):
michael@0 55 return self.value.cast(self.cache.JSString_ptr_t)

mercurial