String to ascii char array converter for debug mode.
authoryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 29 Jul 2011 09:49:40 +0000 (09:49 +0000)
committeryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 29 Jul 2011 09:49:40 +0000 (09:49 +0000)
Review URL: http://codereview.chromium.org/7523052

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8763 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/objects-printer.cc
src/objects.h

index fa03447..5cb5269 100644 (file)
@@ -560,6 +560,21 @@ void String::StringPrint(FILE* out) {
 }
 
 
+// This method is only meant to be called from gdb for debugging purposes.
+// Since the string can also be in two-byte encoding, non-ascii characters
+// will be ignored in the output.
+char* String::ToAsciiArray() {
+  // Static so that subsequent calls frees previously allocated space.
+  // This also means that previous results will be overwritten.
+  static char* buffer = NULL;
+  if (buffer != NULL) free(buffer);
+  buffer = new char[length()+1];
+  WriteToFlat(this, buffer, 0, length());
+  buffer[length()] = 0;
+  return buffer;
+}
+
+
 void JSProxy::JSProxyPrint(FILE* out) {
   HeapObject::PrintHeader(out, "JSProxy");
   PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map()));
index 8ed9060..ba690ec 100644 (file)
@@ -5927,6 +5927,8 @@ class String: public HeapObject {
     StringPrint(stdout);
   }
   void StringPrint(FILE* out);
+
+  char* ToAsciiArray();
 #endif
 #ifdef DEBUG
   void StringVerify();