summaryrefslogtreecommitdiffstats
path: root/js/src/gdb/mozilla/JSSymbol.py
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/gdb/mozilla/JSSymbol.py')
-rw-r--r--js/src/gdb/mozilla/JSSymbol.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/js/src/gdb/mozilla/JSSymbol.py b/js/src/gdb/mozilla/JSSymbol.py
new file mode 100644
index 000000000..5d747d107
--- /dev/null
+++ b/js/src/gdb/mozilla/JSSymbol.py
@@ -0,0 +1,33 @@
+# Pretty-printer for SpiderMonkey symbols.
+
+import gdb
+import mozilla.prettyprinters
+from mozilla.prettyprinters import ptr_pretty_printer
+
+# Forget any printers from previous loads of this module.
+mozilla.prettyprinters.clear_module_printers(__name__)
+
+# JS::SymbolCode enumerators
+InSymbolRegistry = 0xfffffffe
+UniqueSymbol = 0xffffffff
+
+@ptr_pretty_printer("JS::Symbol")
+class JSSymbolPtr(mozilla.prettyprinters.Pointer):
+ def __init__(self, value, cache):
+ super(JSSymbolPtr, self).__init__(value, cache)
+ self.value = value
+
+ def to_string(self):
+ code = int(self.value['code_']) & 0xffffffff
+ desc = str(self.value['description_'])
+ if code == InSymbolRegistry:
+ return "Symbol.for({})".format(desc)
+ elif code == UniqueSymbol:
+ return "Symbol({})".format(desc)
+ else:
+ # Well-known symbol. Strip off the quotes added by the JSString *
+ # pretty-printer.
+ assert desc[0] == '"'
+ assert desc[-1] == '"'
+ return desc[1:-1]
+