Files
sdk/runtime/vm/debugger_test.cc
T
turnidge@google.com 78f3f14635 Add pause/resume for isolates in vmservice/observatory.
Improve the isolate view and isolate summary.

Details:

- Rig DbgMsgQueueList so it can run even when the debugger hasn't started.

- Add <action-link> element for pause/resume actions.

- Introduce new flex-percentile css classes.

- Add <isolate-run-state>, <isolate-location>, <isolate-shared-summary>, and <isolate-counter-chart> elements.  Counters are now displayed as a pie chart instead of as text.

- Reorg <isolate-view> and <isolate-summary> substantially.

- Add shared style sheet to <script-view>.

- Combine pause-on-start/pause-on-exit with other debugger pause events and present a consistent representation for these in the vm service.  Reorg how pause events are shown in <isolate-run-state>.

- Give the user a nicer message when an isolate is still loading.

- Move the /resume command to /debug/resume.  Implement this with a bool in the Isolate class which is used to smuggle resume requests from the vm service to the dart embedding api.

- Add the /debug/pause command to the vm service

- Break the DebuggerEvent struct out into its own top-level class.  Add JSON printing.

etc.

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org//271153002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@36366 260f80e4-7a28-3924-810f-c04153c831b5
2014-05-20 17:09:08 +00:00

108 lines
3.1 KiB
C++

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/debugger.h"
#include "vm/unit_test.h"
namespace dart {
TEST_CASE(Debugger_PrintBreakpointsToJSONArray) {
const char* kScriptChars =
"main() {\n"
" var x = new StringBuffer();\n"
" x.add('won');\n"
" x.add('too');\n"
" return x.toString();\n"
"}\n";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
EXPECT_VALID(lib);
Isolate* isolate = Isolate::Current();
Debugger* debugger = isolate->debugger();
const String& url = String::Handle(String::New(TestCase::url()));
// Empty case.
{
JSONStream js;
{
JSONArray jsarr(&js);
debugger->PrintBreakpointsToJSONArray(&jsarr);
}
EXPECT_STREQ("[]", js.ToCString());
}
// Test with a couple of breakpoints.
debugger->SetBreakpointAtLine(url, 2);
debugger->SetBreakpointAtLine(url, 3);
{
JSONStream js;
{
JSONArray jsarr(&js);
debugger->PrintBreakpointsToJSONArray(&jsarr);
}
EXPECT_STREQ(
"[{\"type\":\"Breakpoint\",\"id\":2,"
"\"enabled\":true,\"resolved\":false,"
"\"location\":{\"type\":\"Location\","
"\"script\":\"test-lib\",\"tokenPos\":14}},"
"{\"type\":\"Breakpoint\",\"id\":1,"
"\"enabled\":true,\"resolved\":false,"
"\"location\":{\"type\":\"Location\","
"\"script\":\"test-lib\",\"tokenPos\":5}}]",
js.ToCString());
}
}
static bool saw_paused_event = false;
static void InspectPausedEvent(Dart_IsolateId isolate_id,
intptr_t bp_id,
const Dart_CodeLocation& loc) {
Isolate* isolate = Isolate::Current();
Debugger* debugger = isolate->debugger();
// The debugger knows that it is paused, and why.
EXPECT(debugger->IsPaused());
const DebuggerEvent* event = debugger->PauseEvent();
EXPECT(event != NULL);
EXPECT(event->type() == DebuggerEvent::kBreakpointReached);
saw_paused_event = true;
}
TEST_CASE(Debugger_PauseEvent) {
const char* kScriptChars =
"main() {\n"
" var x = new StringBuffer();\n"
" x.write('won');\n"
" x.write('too');\n"
" return x.toString();\n"
"}\n";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
EXPECT_VALID(lib);
Isolate* isolate = Isolate::Current();
Debugger* debugger = isolate->debugger();
const String& url = String::Handle(String::New(TestCase::url()));
// No pause event.
EXPECT(!debugger->IsPaused());
EXPECT(debugger->PauseEvent() == NULL);
saw_paused_event = false;
Dart_SetPausedEventHandler(InspectPausedEvent);
// Set a breakpoint and run.
debugger->SetBreakpointAtLine(url, 2);
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
EXPECT_VALID(result);
EXPECT(Dart_IsString(result));
// We ran the code in InspectPausedEvent.
EXPECT(saw_paused_event);
}
} // namespace dart