Bug 1448232 - Make gdb JS::Value prettyprinting integration handle |gdb.types.make_enum_dict(gdb.lookup_type('JSValueType'))| when the compiler-generated keys have a 'JSValueTag::' prefix with clang. r=sfink
authorJeff Walden <jwalden@mit.edu>
Mon, 26 Mar 2018 20:34:02 -0700
changeset 773610 c6fc8a5bf238503fb8ab6218d8e3c79150f22b90
parent 773609 3919fa7286d5e52bdf453ada871c0dd89100f915
child 773611 851ed02cdac10ef8038cf73d0df080f393530546
push id104266
push userbmo:hsivonen@hsivonen.fi
push dateWed, 28 Mar 2018 07:33:03 +0000
reviewerssfink
bugs1448232
milestone61.0a1
Bug 1448232 - Make gdb JS::Value prettyprinting integration handle |gdb.types.make_enum_dict(gdb.lookup_type('JSValueType'))| when the compiler-generated keys have a 'JSValueTag::' prefix with clang. r=sfink
js/src/gdb/mozilla/jsval.py
--- a/js/src/gdb/mozilla/jsval.py
+++ b/js/src/gdb/mozilla/jsval.py
@@ -150,25 +150,34 @@ class Nunbox(Box):
     def as_uint32(self): return int(self.asBits & Nunbox.PAYLOAD_MASK)
     def as_address(self): return gdb.Value(self.asBits & Nunbox.PAYLOAD_MASK)
 
 # Cache information about the jsval type for this objfile.
 class jsvalTypeCache(object):
     def __init__(self, cache):
         # Capture the tag values.
         d = gdb.types.make_enum_dict(gdb.lookup_type('JSValueType'))
-        self.DOUBLE    = d['JSVAL_TYPE_DOUBLE']
-        self.INT32     = d['JSVAL_TYPE_INT32']
-        self.UNDEFINED = d['JSVAL_TYPE_UNDEFINED']
-        self.BOOLEAN   = d['JSVAL_TYPE_BOOLEAN']
-        self.MAGIC     = d['JSVAL_TYPE_MAGIC']
-        self.STRING    = d['JSVAL_TYPE_STRING']
-        self.SYMBOL    = d['JSVAL_TYPE_SYMBOL']
-        self.NULL      = d['JSVAL_TYPE_NULL']
-        self.OBJECT    = d['JSVAL_TYPE_OBJECT']
+
+        # The enum keys are prefixed when building with some compilers (clang at
+        # a minimum), so use a helper function to handle either key format.
+        def get(key):
+            val = d.get(key)
+            if val is not None:
+                return val
+            return d['JSValueType::' + key]
+
+        self.DOUBLE = get('JSVAL_TYPE_DOUBLE')
+        self.INT32 = get('JSVAL_TYPE_INT32')
+        self.UNDEFINED = get('JSVAL_TYPE_UNDEFINED')
+        self.BOOLEAN = get('JSVAL_TYPE_BOOLEAN')
+        self.MAGIC = get('JSVAL_TYPE_MAGIC')
+        self.STRING = get('JSVAL_TYPE_STRING')
+        self.SYMBOL = get('JSVAL_TYPE_SYMBOL')
+        self.NULL = get('JSVAL_TYPE_NULL')
+        self.OBJECT = get('JSVAL_TYPE_OBJECT')
 
         # Let self.magic_names be an array whose i'th element is the name of
         # the i'th magic value.
         d = gdb.types.make_enum_dict(gdb.lookup_type('JSWhyMagic'))
         self.magic_names = list(range(max(d.values()) + 1))
         for (k,v) in d.items(): self.magic_names[v] = k
 
         # Choose an unboxing scheme for this architecture.