Improve printing for Symbols.

Private symbols we create in the heap don't have names, but we can
resolve them to a constant string.

This gives handy debugger output like:

(gdb) job 0x2020c67d
0x2020c67d: [Symbol]
 - hash: 547385396
 - name: 0x20208091 <undefined> (uninitialized_symbol)
 - private: 1
 - own: 1
$7 = void
(gdb)

or with ShortPrint() in an array:

...
  [5]: 0x2020c67d <Symbol: 547385396 (uninitialized_symbol)>
...

Printing help for internal symbols

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/677633003

Cr-Commit-Position: refs/heads/master@{#24869}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24869 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 7259d87f
......@@ -395,6 +395,9 @@ void Symbol::SymbolPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "Symbol");
os << " - hash: " << Hash();
os << "\n - name: " << Brief(name());
if (name()->IsUndefined()) {
os << " (" << PrivateSymbolToName() << ")";
}
os << "\n - private: " << is_private();
os << "\n - own: " << is_own();
os << "\n";
......
......@@ -1532,15 +1532,7 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT
}
case SYMBOL_TYPE: {
Symbol* symbol = Symbol::cast(this);
os << "<Symbol: " << symbol->Hash();
if (!symbol->name()->IsUndefined()) {
os << " ";
HeapStringAllocator allocator;
StringStream accumulator(&allocator);
String::cast(symbol->name())->StringShortPrint(&accumulator);
os << accumulator.ToCString().get();
}
os << ">";
symbol->SymbolShortPrint(os);
break;
}
case HEAP_NUMBER_TYPE: {
......@@ -13616,6 +13608,31 @@ int JSObject::GetEnumElementKeys(FixedArray* storage) {
}
const char* Symbol::PrivateSymbolToName() const {
Heap* heap = GetIsolate()->heap();
#define SYMBOL_CHECK_AND_PRINT(name) \
if (this == heap->name()) return #name;
PRIVATE_SYMBOL_LIST(SYMBOL_CHECK_AND_PRINT)
#undef SYMBOL_CHECK_AND_PRINT
return "UNKNOWN";
}
void Symbol::SymbolShortPrint(std::ostream& os) {
os << "<Symbol: " << Hash();
if (!name()->IsUndefined()) {
os << " ";
HeapStringAllocator allocator;
StringStream accumulator(&allocator);
String::cast(name())->StringShortPrint(&accumulator);
os << accumulator.ToCString().get();
} else {
os << " (" << PrivateSymbolToName() << ")";
}
os << ">";
}
// StringSharedKeys are used as keys in the eval cache.
class StringSharedKey : public HashTableKey {
public:
......
......@@ -8654,10 +8654,14 @@ class Symbol: public Name {
typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor;
void SymbolShortPrint(std::ostream& os);
private:
static const int kPrivateBit = 0;
static const int kOwnBit = 1;
const char* PrivateSymbolToName() const;
DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment