mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 645416, part 11 - Update GDB pretty-printers for symbols. r=jimb.
--HG-- extra : rebase_source : ab2063ab6073b748069c6a8ad1cd34ab0d5e7d86
This commit is contained in:
parent
50238c4db4
commit
17baf1bfcc
@ -11,6 +11,7 @@ UNIFIED_SOURCES += [
|
||||
'tests/test-jsid.cpp',
|
||||
'tests/test-JSObject.cpp',
|
||||
'tests/test-JSString.cpp',
|
||||
'tests/test-JSSymbol.cpp',
|
||||
'tests/test-jsval.cpp',
|
||||
'tests/test-prettyprinters.cpp',
|
||||
'tests/test-Root.cpp',
|
||||
|
33
js/src/gdb/mozilla/JSSymbol.py
Normal file
33
js/src/gdb/mozilla/JSSymbol.py
Normal file
@ -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_'])
|
||||
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]
|
||||
|
@ -11,6 +11,7 @@ import mozilla.prettyprinters
|
||||
import mozilla.jsid
|
||||
import mozilla.JSObject
|
||||
import mozilla.JSString
|
||||
import mozilla.JSSymbol
|
||||
import mozilla.jsval
|
||||
import mozilla.Root
|
||||
|
||||
|
@ -161,6 +161,7 @@ class jsvalTypeCache(object):
|
||||
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']
|
||||
|
||||
@ -203,6 +204,8 @@ class jsval_layout(object):
|
||||
return '$jsmagic(%d)' % (value,)
|
||||
elif tag == self.jtc.STRING:
|
||||
value = self.box.as_address().cast(self.cache.JSString_ptr_t)
|
||||
elif tag == self.jtc.SYMBOL:
|
||||
value = self.box.as_address().cast(self.cache.JSSymbol_ptr_t)
|
||||
elif tag == self.jtc.NULL:
|
||||
return 'JSVAL_NULL'
|
||||
elif tag == self.jtc.OBJECT:
|
||||
|
@ -174,6 +174,7 @@ class TypeCache(object):
|
||||
self.void_ptr_t = self.void_t.pointer()
|
||||
try:
|
||||
self.JSString_ptr_t = gdb.lookup_type('JSString').pointer()
|
||||
self.JSSymbol_ptr_t = gdb.lookup_type('JS::Symbol').pointer()
|
||||
self.JSObject_ptr_t = gdb.lookup_type('JSObject').pointer()
|
||||
except gdb.error:
|
||||
raise NotSpiderMonkeyObjfileError
|
||||
|
20
js/src/gdb/tests/test-JSSymbol.cpp
Normal file
20
js/src/gdb/tests/test-JSSymbol.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "gdb-tests.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
FRAGMENT(JSSymbol, simple) {
|
||||
using namespace JS;
|
||||
|
||||
RootedString hello(cx, JS_NewStringCopyZ(cx, "Hello!"));
|
||||
|
||||
Rooted<Symbol*> unique(cx, NewSymbol(cx, NullPtr()));
|
||||
Rooted<Symbol*> unique_with_desc(cx, NewSymbol(cx, hello));
|
||||
Rooted<Symbol*> registry(cx, GetSymbolFor(cx, hello));
|
||||
Rooted<Symbol*> well_known(cx, GetWellKnownSymbol(cx, SymbolCode::iterator));
|
||||
|
||||
breakpoint();
|
||||
|
||||
(void) unique;
|
||||
(void) unique_with_desc;
|
||||
(void) registry;
|
||||
(void) well_known;
|
||||
}
|
10
js/src/gdb/tests/test-JSSymbol.py
Normal file
10
js/src/gdb/tests/test-JSSymbol.py
Normal file
@ -0,0 +1,10 @@
|
||||
# Printing JS::Symbols.
|
||||
|
||||
assert_subprinter_registered('SpiderMonkey', 'ptr-to-JS::Symbol')
|
||||
|
||||
run_fragment('JSSymbol.simple')
|
||||
|
||||
assert_pretty('unique', 'Symbol()')
|
||||
assert_pretty('unique_with_desc', 'Symbol("Hello!")')
|
||||
assert_pretty('registry', 'Symbol.for("Hello!")')
|
||||
assert_pretty('well_known', 'Symbol.iterator')
|
@ -2,24 +2,27 @@
|
||||
#include "jsapi.h"
|
||||
|
||||
FRAGMENT(jsval, simple) {
|
||||
JS::Rooted<jsval> fortytwo(cx, INT_TO_JSVAL(42));
|
||||
JS::Rooted<jsval> negone(cx, INT_TO_JSVAL(-1));
|
||||
JS::Rooted<jsval> undefined(cx, JSVAL_VOID);
|
||||
JS::Rooted<jsval> null(cx, JSVAL_NULL);
|
||||
JS::Rooted<jsval> js_true(cx, JSVAL_TRUE);
|
||||
JS::Rooted<jsval> js_false(cx, JSVAL_FALSE);
|
||||
JS::Rooted<jsval> elements_hole(cx, js::MagicValue(JS_ELEMENTS_HOLE));
|
||||
using namespace JS;
|
||||
|
||||
JS::Rooted<jsval> empty_string(cx);
|
||||
RootedValue fortytwo(cx, Int32Value(42));
|
||||
RootedValue negone(cx, Int32Value(-1));
|
||||
RootedValue undefined(cx, UndefinedValue());
|
||||
RootedValue null(cx, NullValue());
|
||||
RootedValue js_true(cx, BooleanValue(true));
|
||||
RootedValue js_false(cx, BooleanValue(false));
|
||||
RootedValue elements_hole(cx, js::MagicValue(JS_ELEMENTS_HOLE));
|
||||
|
||||
RootedValue empty_string(cx);
|
||||
empty_string.setString(JS_NewStringCopyZ(cx, ""));
|
||||
JS::Rooted<jsval> friendly_string(cx);
|
||||
friendly_string.setString(JS_NewStringCopyZ(cx, "Hello!"));
|
||||
RootedString hello(cx, JS_NewStringCopyZ(cx, "Hello!"));
|
||||
RootedValue friendly_string(cx, StringValue(hello));
|
||||
RootedValue symbol(cx, SymbolValue(GetSymbolFor(cx, hello)));
|
||||
|
||||
JS::Rooted<jsval> global(cx);
|
||||
global.setObject(*JS::CurrentGlobalOrNull(cx));
|
||||
RootedValue global(cx);
|
||||
global.setObject(*CurrentGlobalOrNull(cx));
|
||||
|
||||
// Some interesting value that floating-point won't munge.
|
||||
JS::Rooted<jsval> onehundredthirtysevenonehundredtwentyeighths(cx, DOUBLE_TO_JSVAL(137.0 / 128.0));
|
||||
RootedValue onehundredthirtysevenonehundredtwentyeighths(cx, DOUBLE_TO_JSVAL(137.0 / 128.0));
|
||||
|
||||
breakpoint();
|
||||
|
||||
@ -32,5 +35,6 @@ FRAGMENT(jsval, simple) {
|
||||
(void) elements_hole;
|
||||
(void) empty_string;
|
||||
(void) friendly_string;
|
||||
(void) symbol;
|
||||
(void) global;
|
||||
}
|
||||
|
@ -13,5 +13,6 @@ assert_pretty('js_false', 'JSVAL_FALSE')
|
||||
assert_pretty('elements_hole', '$jsmagic(JS_ELEMENTS_HOLE)')
|
||||
assert_pretty('empty_string', '$jsval("")')
|
||||
assert_pretty('friendly_string', '$jsval("Hello!")')
|
||||
assert_pretty('symbol', '$jsval(Symbol.for("Hello!"))')
|
||||
assert_pretty('global', '$jsval((JSObject *) [object global] delegate)')
|
||||
assert_pretty('onehundredthirtysevenonehundredtwentyeighths', '$jsval(1.0703125)')
|
||||
|
Loading…
Reference in New Issue
Block a user