Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: runtime/bin/dbg_message.cc

Issue 12033039: Limit textual representation of arrays in debugger (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/dbg_message.cc
===================================================================
--- runtime/bin/dbg_message.cc (revision 17421)
+++ runtime/bin/dbg_message.cc (working copy)
@@ -105,7 +105,7 @@
}
-static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) {
+static void FormatEncodedChars(dart::TextBuffer* buf, Dart_Handle str) {
intptr_t str_len = 0;
Dart_Handle res = Dart_StringLength(str, &str_len);
ASSERT_NOT_ERROR(res);
@@ -116,51 +116,83 @@
res = Dart_StringToUTF16(str, codepoints, &actual_len);
ASSERT_NOT_ERROR(res);
ASSERT(str_len == actual_len);
- buf->AddChar('\"');
for (int i = 0; i < str_len; i++) {
buf->AddEscapedChar(codepoints[i]);
}
- buf->AddChar('\"');
free(codepoints);
}
-static void FormatErrorMsg(dart::TextBuffer* buf, Dart_Handle err) {
- ASSERT(Dart_IsError(err));
- const char* msg = Dart_GetError(err);
- Dart_Handle str = Dart_NewStringFromCString(msg);
- FormatEncodedString(buf, str);
+static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) {
+ buf->AddChar('\"');
+ FormatEncodedChars(buf, str);
+ buf->AddChar('\"');
}
-static void FormatTextualValue(dart::TextBuffer* buf, Dart_Handle object) {
- Dart_Handle text;
- if (Dart_IsNull(object)) {
- text = Dart_Null();
+static void FormatTextualListElement(dart::TextBuffer* buf,
+ Dart_Handle object) {
+ if (Dart_IsList(object)) {
+ buf->Printf("[...]");
+ } else if (Dart_IsNull(object)) {
+ buf->Printf("null");
+ } else if (Dart_IsError(object)) {
+ buf->Printf("#ERROR");
} else {
- Dart_ExceptionPauseInfo savedState = Dart_GetExceptionPauseInfo();
-
- // TODO(hausner): Check whether recursive/reentrant pauses on exceptions
- // should be prevented in Debugger::SignalExceptionThrown() instead.
- if (savedState != kNoPauseOnExceptions) {
- Dart_Handle res = Dart_SetExceptionPauseInfo(kNoPauseOnExceptions);
- ASSERT_NOT_ERROR(res);
+ const bool need_quotes = Dart_IsString(object);
+ Dart_Handle text = Dart_ToString(object);
+ if (need_quotes) buf->Printf("\\\"");
+ if (Dart_IsNull(text)) {
+ buf->Printf("null");
+ } else if (Dart_IsError(text)) {
+ buf->Printf("#ERROR");
+ } else {
+ FormatEncodedChars(buf, text);
}
+ if (need_quotes) buf->Printf("\\\"");
+ }
+}
- text = Dart_ToString(object);
- if (savedState != kNoPauseOnExceptions) {
- Dart_Handle res = Dart_SetExceptionPauseInfo(savedState);
- ASSERT_NOT_ERROR(res);
+static void FormatTextualListValue(dart::TextBuffer* buf, Dart_Handle list) {
srdjan 2013/01/23 18:35:45 Do you want to do the same for very long Strings a
+ intptr_t len = 0;
+ Dart_Handle res = Dart_ListLength(list, &len);
+ ASSERT_NOT_ERROR(res);
+ const intptr_t initial_buffer_length = buf->length();
+ // Maximum number of characters we print for array elements.
+ const intptr_t max_chars = 256;
+ const intptr_t max_buffer_length = initial_buffer_length + max_chars;
+ buf->Printf("[");
+ for (int i = 0; i < len; i++) {
+ if (i > 0) {
+ buf->Printf(", ");
}
+ Dart_Handle elem = Dart_ListGetAt(list, i);
srdjan 2013/01/23 18:35:45 Instead of adding and checking if buffer exceeded,
+ FormatTextualListElement(buf, elem);
+ if (buf->length() > max_buffer_length) {
+ buf->Printf(", ...");
+ break;
+ }
}
- buf->Printf("\"text\":");
- if (Dart_IsNull(text)) {
+ buf->Printf("]");
+}
+
+
+static void FormatTextualValue(dart::TextBuffer* buf,
+ Dart_Handle object) {
+ if (Dart_IsList(object)) {
+ FormatTextualListValue(buf, object);
+ } else if (Dart_IsNull(object)) {
buf->Printf("null");
- } else if (Dart_IsError(text)) {
- FormatErrorMsg(buf, text);
} else {
- FormatEncodedString(buf, text);
+ Dart_Handle text = Dart_ToString(object);
+ if (Dart_IsNull(text)) {
+ buf->Printf("null");
+ } else if (Dart_IsError(text)) {
+ buf->Printf("#ERROR");
+ } else {
+ FormatEncodedChars(buf, text);
+ }
}
}
@@ -180,7 +212,9 @@
} else {
buf->Printf("\"kind\":\"object\",");
}
+ buf->Printf("\"text\":\"");
FormatTextualValue(buf, object);
+ buf->Printf("\"");
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698