Reviewers: Yang,

Message:
Hi Yang,
Another bit of trivia, nicer printing for symbols.
thx again,
--Michael

Description:
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

[email protected]

Please review this at https://codereview.chromium.org/677633003/

Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+33, -9 lines):
  M src/objects.h
  M src/objects.cc
  M src/objects-printer.cc


Index: src/objects-printer.cc
diff --git a/src/objects-printer.cc b/src/objects-printer.cc
index c8149bb3295d126256f6a27c75cbd92dd7fa970f..d5606dea427d571950c7609eb99f0e3820745a47 100644
--- a/src/objects-printer.cc
+++ b/src/objects-printer.cc
@@ -427,6 +427,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";
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 47a61f627b817ca7d533aea305cfde7b90e4d110..5e975bcab42a2979e9e0c519fddf7020fa16349c 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1534,15 +1534,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: {
@@ -13630,6 +13622,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:
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 0dc5e3a22f5d2b732c8557c81b395ab72dd962e4..97f81cbc2c8ac3fe92fecab95d1affd337f996d0 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -8643,10 +8643,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);
 };



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to