Bug 1179278: GDB pretty-printers: handle encoding errors when trying to print JSObject class names. DONTBUILD r=jorendorff

--HG--
extra : rebase_source : b463225bc35fe7f8e2848e20578362e1bfa8bde3
This commit is contained in:
Jim Blandy 2015-06-30 23:47:14 -07:00
parent e41745c1c8
commit 595069840a
3 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,6 @@
# Pretty-printers for SpiderMonkey JSObjects.
import re
import gdb
import mozilla.JSString
import mozilla.prettyprinters as prettyprinters
@ -20,6 +21,8 @@ class JSObjectTypeCache(object):
# search for pretty-printers under the names of base classes, and
# JSFunction has JSObject as a base class.
gdb_string_regexp = re.compile(r'(?:0x[0-9a-z]+ )?(?:<.*> )?"(.*)"', re.I)
@ptr_pretty_printer('JSObject')
class JSObjectPtrOrRef(prettyprinters.Pointer):
def __init__(self, value, cache):
@ -31,8 +34,15 @@ class JSObjectPtrOrRef(prettyprinters.Pointer):
def summary(self):
group = deref(self.value['group_'])
classp = group['clasp_']
class_name = classp['name'].string()
non_native = classp['flags'] & self.otc.class_NON_NATIVE
# Use GDB to format the class name, but then strip off the address
# and the quotes.
class_name = str(classp['name'])
m = gdb_string_regexp.match(class_name)
if m:
class_name = m.group(1)
if non_native:
return '[object {}]'.format(class_name)
else:

View File

@ -16,6 +16,9 @@ FRAGMENT(JSObject, simple) {
JSObject* plainRaw = plain;
JSObject* funcRaw = func;
static const JSClass cls = { "\xc7X" };
RootedObject badClassName(cx, JS_NewObject(cx, &cls));
breakpoint();
(void) glob;

View File

@ -16,5 +16,7 @@ assert_pretty('func', '(JSObject *) [object Function "dys"]')
assert_pretty('anon', '(JSObject *) [object Function <unnamed>]')
assert_pretty('funcPtr', '(JSFunction *) [object Function "formFollows"]')
assert_pretty('badClassName', '(JSObject *) [object \\307X]')
assert_pretty('plainRef', '(JSObject &) @ [object Object]')
assert_pretty('funcRef', '(JSFunction &) @ [object Function "formFollows"]')