Bumping manifests a=b2g-bump
[gecko.git] / js / src / gdb / mozilla / JSString.py
blobf79cd3c2782d822eb8408b09b68ace9964ba3baa
1 # Pretty-printers for SpiderMonkey strings.
3 import gdb
4 import mozilla.prettyprinters
5 from mozilla.prettyprinters import pretty_printer, ptr_pretty_printer
7 try:
8 chr(10000) # UPPER RIGHT PENCIL
9 except ValueError as exc: # yuck, we are in Python 2.x, so chr() is 8-bit
10 chr = unichr # replace with teh unicodes
12 # Forget any printers from previous loads of this module.
13 mozilla.prettyprinters.clear_module_printers(__name__)
15 # Cache information about the JSString type for this objfile.
16 class JSStringTypeCache(object):
17 def __init__(self, cache):
18 dummy = gdb.Value(0).cast(cache.JSString_ptr_t)
19 self.ROPE_FLAGS = dummy['ROPE_FLAGS']
20 self.ATOM_BIT = dummy['ATOM_BIT']
21 self.INLINE_CHARS_BIT = dummy['INLINE_CHARS_BIT']
22 self.TYPE_FLAGS_MASK = dummy['TYPE_FLAGS_MASK']
23 self.LATIN1_CHARS_BIT = dummy['LATIN1_CHARS_BIT']
25 class Common(mozilla.prettyprinters.Pointer):
26 def __init__(self, value, cache):
27 super(Common, self).__init__(value, cache)
28 if not cache.mod_JSString:
29 cache.mod_JSString = JSStringTypeCache(cache)
30 self.stc = cache.mod_JSString
32 @ptr_pretty_printer("JSString")
33 class JSStringPtr(Common):
34 def display_hint(self):
35 return "string"
37 def jschars(self):
38 d = self.value['d']
39 length = d['u1']['length']
40 flags = d['u1']['flags']
41 is_rope = ((flags & self.stc.TYPE_FLAGS_MASK) == self.stc.ROPE_FLAGS)
42 if is_rope:
43 for c in JSStringPtr(d['s']['u2']['left'], self.cache).jschars():
44 yield c
45 for c in JSStringPtr(d['s']['u3']['right'], self.cache).jschars():
46 yield c
47 else:
48 is_inline = (flags & self.stc.INLINE_CHARS_BIT) != 0
49 is_latin1 = (flags & self.stc.LATIN1_CHARS_BIT) != 0
50 if is_inline:
51 if is_latin1:
52 chars = d['inlineStorageLatin1']
53 else:
54 chars = d['inlineStorageTwoByte']
55 else:
56 if is_latin1:
57 chars = d['s']['u2']['nonInlineCharsLatin1']
58 else:
59 chars = d['s']['u2']['nonInlineCharsTwoByte']
60 for i in range(length):
61 yield chars[i]
63 def to_string(self):
64 s = u''
65 for c in self.jschars():
66 s += chr(c)
67 return s
69 @ptr_pretty_printer("JSAtom")
70 class JSAtomPtr(Common):
71 def to_string(self):
72 return self.value.cast(self.cache.JSString_ptr_t)