From 15b13fac8e27598c5f32c575e13b99648f642d3e Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Fri, 29 Jul 2011 09:49:40 +0000 Subject: [PATCH] String to ascii char array converter for debug mode. 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 | 15 +++++++++++++++ src/objects.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/objects-printer.cc b/src/objects-printer.cc index fa03447a3b..5cb5269d7a 100644 --- a/src/objects-printer.cc +++ b/src/objects-printer.cc @@ -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(map())); diff --git a/src/objects.h b/src/objects.h index 8ed90605f1..ba690ecab5 100644 --- a/src/objects.h +++ b/src/objects.h @@ -5927,6 +5927,8 @@ class String: public HeapObject { StringPrint(stdout); } void StringPrint(FILE* out); + + char* ToAsciiArray(); #endif #ifdef DEBUG void StringVerify();