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

Unified Diff: test/cctest/test-debug.cc

Issue 536089: Support backtrace debug command when stack is empty (Closed)
Patch Set: clean Created 10 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: test/cctest/test-debug.cc
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index b69ecccd6b791aeea40694d47368e47b7605f929..36b27e7f997c8a0fcaa391b7f81daa90d2cc7b0f 100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -3872,6 +3872,23 @@ int GetBreakpointIdFromBreakEventMessage(char *message) {
}
+// We match parts of the message to get total frames number.
+int GetTotalFramesInt(char *message) {
+ const char* prefix = "\"totalFrames\":";
+ char* pos = strstr(message, prefix);
+ if (pos == NULL) {
+ return -1;
+ }
+ pos += strlen(prefix);
+ char* pos_end = pos;
+ long res = strtol(pos, &pos_end, 10);
+ if (pos_end == pos) {
+ return -1;
+ }
+ return static_cast<int>(res);
+}
+
+
/* Test MessageQueues */
/* Tests the message queues that hold debugger commands and
* response messages to the debugger. Fills queues and makes
@@ -5827,6 +5844,58 @@ TEST(ProcessDebugMessages) {
}
+struct BracktraceData {
+ static int frame_counter;
+ static void MessageHandler(const v8::Debug::Message& message) {
+ char print_buffer[1000];
+ v8::String::Value json(message.GetJSON());
+ Utf16ToAscii(*json, json.length(), print_buffer, 1000);
+
+ if (strstr(print_buffer, "backtrace") == NULL) {
+ return;
+ }
+ frame_counter = GetTotalFramesInt(print_buffer);
+ }
+};
+
+int BracktraceData::frame_counter;
+
+
+// Test that debug messages get processed when ProcessDebugMessages is called.
+TEST(Backtrace) {
+ v8::HandleScope scope;
+ DebugLocalContext env;
+
+ v8::Debug::SetMessageHandler2(BracktraceData::MessageHandler);
+
+ const int kBufferSize = 1000;
+ uint16_t buffer[kBufferSize];
+ const char* scripts_command =
+ "{\"seq\":0,"
+ "\"type\":\"request\","
+ "\"command\":\"backtrace\"}";
+
+ // Check backtrace from ProcessDebugMessages.
+ BracktraceData::frame_counter = -10;
+ v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
+ v8::Debug::ProcessDebugMessages();
+ CHECK_EQ(BracktraceData::frame_counter, 0);
+
+ v8::Handle<v8::String> void0 = v8::String::New("void(0)");
+ v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0);
+
+ // Check backtrace from "void(0)" script.
+ BracktraceData::frame_counter = -10;
+ v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer));
+ script->Run();
+ CHECK_EQ(BracktraceData::frame_counter, 1);
+
+ // Get rid of the debug message handler.
+ v8::Debug::SetMessageHandler2(NULL);
+ CheckDebuggerUnloaded();
+}
+
+
TEST(GetMirror) {
v8::HandleScope scope;
DebugLocalContext env;
« 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