Skip to content

Commit

Permalink
支持调试
Browse files Browse the repository at this point in the history
  • Loading branch information
linyu1 committed Jun 13, 2020
1 parent 4cc3605 commit fab2e90
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
4 changes: 2 additions & 2 deletions runtime/runtime_args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare_args() {
# Instead of using is_debug, we introduce a different flag for specifying a
# Debug build of Dart so that clients can still use a Release build of Dart
# while themselves doing a Debug build.
dart_debug = false
dart_debug = true

# Set the runtime mode. This affects how the runtime is built and what
# features it has. Valid values are:
Expand All @@ -33,7 +33,7 @@ declare_args() {

# The optimization level to use for debug builds. Defaults to 0 for builds with
# code coverage enabled.
dart_debug_optimization_level = "2"
dart_debug_optimization_level = "0"

# Whether to enable code coverage for the standalone VM.
dart_vm_code_coverage = false
Expand Down
22 changes: 15 additions & 7 deletions runtime/vm/debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,7 @@ void Debugger::FindCompiledFunctions(
if ((function.token_pos() == start_pos) &&
(function.end_token_pos() == end_pos) &&
(function.script() == script.raw())) {
function.set_is_debuggable(true);
if (function.is_debuggable()) {
if (FLAG_enable_interpreter && function.HasBytecode()) {
bytecode_function_list->Add(function);
Expand All @@ -3224,10 +3225,12 @@ void Debugger::FindCompiledFunctions(
}
if (function.HasImplicitClosureFunction()) {
function = function.ImplicitClosureFunction();
function.set_is_debuggable(true);
if (function.is_debuggable()) {
if (FLAG_enable_interpreter && function.HasBytecode()) {
bytecode_function_list->Add(function);
}
function.EnsureHasCode();
if (function.HasCode()) {
code_function_list->Add(function);
}
Expand Down Expand Up @@ -3258,26 +3261,30 @@ void Debugger::FindCompiledFunctions(
function ^= functions.At(pos);
ASSERT(!function.IsNull());
bool function_added = false;
function.set_is_debuggable(true);
if (function.is_debuggable() &&
(function.HasCode() ||
(FLAG_enable_interpreter && function.HasBytecode())) &&
/* (function.HasCode() ||
(FLAG_enable_interpreter && function.HasBytecode())) && */
function.token_pos() == start_pos &&
function.end_token_pos() == end_pos &&
function.script() == script.raw()) {
if (FLAG_enable_interpreter && function.HasBytecode()) {
bytecode_function_list->Add(function);
}
function.EnsureHasCode();
if (function.HasCode()) {
code_function_list->Add(function);
}
function_added = true;
}
if (function_added && function.HasImplicitClosureFunction()) {
function = function.ImplicitClosureFunction();
function.set_is_debuggable(true);
if (function.is_debuggable()) {
if (FLAG_enable_interpreter && function.HasBytecode()) {
bytecode_function_list->Add(function);
}
function.EnsureHasCode();
if (function.HasCode()) {
code_function_list->Add(function);
}
Expand Down Expand Up @@ -3314,11 +3321,12 @@ bool Debugger::FindBestFit(const Script& script,
Library& lib = Library::Handle(zone, script.FindLibrary());
ASSERT(!lib.IsNull());
if (!lib.IsDebuggable()) {
if (FLAG_verbose_debug) {
OS::PrintErr("Library '%s' has been marked as non-debuggable\n",
lib.ToCString());
}
return false;
lib.set_debuggable(true);
// if (FLAG_verbose_debug) {
// OS::PrintErr("Library '%s' has been marked as non-debuggable\n",
// lib.ToCString());
// }
// return false;
}
const GrowableObjectArray& closures = GrowableObjectArray::Handle(
zone, isolate_->object_store()->closure_functions());
Expand Down
16 changes: 14 additions & 2 deletions runtime/vm/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9569,6 +9569,7 @@ void Script::LoadSourceFromKernel(const uint8_t* kernel_buffer,
String& uri = String::Handle(resolved_url());
String& source = String::Handle(kernel::KernelLoader::FindSourceForScript(
kernel_buffer, kernel_buffer_len, uri));
OS::PrintErr(">>> LoadSourceFromKernel:%ld url:%s\n",source.Length(), uri.ToMallocCString());
set_source(source);
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)
Expand Down Expand Up @@ -9968,6 +9969,7 @@ RawScript* Script::New(const String& url, const String& source) {
RawScript* Script::New(const String& url,
const String& resolved_url,
const String& source) {
OS::PrintErr(">>> Script::New:%ld url:%s\n",source.Length(), url.ToMallocCString());
Thread* thread = Thread::Current();
Zone* zone = thread->zone();
const Script& result = Script::Handle(zone, Script::New());
Expand Down Expand Up @@ -10716,7 +10718,6 @@ static void AddScriptIfUnique(const GrowableObjectArray& scripts,
return;
}
Script& script_obj = Script::Handle();

for (int i = 0; i < scripts.Length(); i++) {
script_obj ^= scripts.At(i);
if (script_obj.raw() == candidate.raw()) {
Expand All @@ -10725,13 +10726,24 @@ static void AddScriptIfUnique(const GrowableObjectArray& scripts,
}
}
// Add script to the list of scripts.

// const String& url = String::Handle(String::New("org-dartlang-sdk:///sdk/lib/_http/http_impl.dart"));
// String::EncodeIRI(uri);
const String& url = String::Handle(candidate.url());
OS::PrintErr(">>> AddScriptIfUnique url:%s\n",url.ToMallocCString());
if (!candidate.HasSource()) {
const uint8_t* kernel_buffer = Service::dart_library_kernel();
const intptr_t kernel_buffer_len =
Service::dart_library_kernel_length();
candidate.LoadSourceFromKernel(kernel_buffer, kernel_buffer_len);
}
scripts.Add(candidate);
}

RawArray* Library::LoadedScripts() const {
ASSERT(Thread::Current()->IsMutatorThread());
// We compute the list of loaded scripts lazily. The result is
// cached in loaded_scripts_.
// cached in loaded_scripts_.
if (loaded_scripts() == Array::null()) {
// TODO(jensj): This can be cleaned up.
// It really should just return the content of `owned_scripts`, and there
Expand Down
30 changes: 27 additions & 3 deletions runtime/vm/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3260,13 +3260,14 @@ RawError* Service::MaybePause(Isolate* isolate, const Error& error) {
return error.raw();
}

//static int DebugBreakPointCounter = 0;
static bool AddBreakpointCommon(Thread* thread,
JSONStream* js,
const String& script_uri) {
if (CheckDebuggerDisabled(thread, js)) {
return true;
}

const char* breakPointAtScript = js->LookupParam("breakPointAtScript");
const char* line_param = js->LookupParam("line");
intptr_t line = UIntParameter::Parse(line_param);
const char* col_param = js->LookupParam("column");
Expand All @@ -3281,8 +3282,31 @@ static bool AddBreakpointCommon(Thread* thread,
}
ASSERT(!script_uri.IsNull());
Breakpoint* bpt = NULL;
bpt = thread->isolate()->debugger()->SetBreakpointAtLineCol(script_uri, line,
col);

if (breakPointAtScript != NULL) {
// char str[50];
// const char * prefix = "org-dartlang-sdk:///sdk/lib/";
// strcpy(str, prefix);
// strcat(str, breakPointAtScript);
// dart:io-patch/socket_patch.dart
String& aScriptUri = String::Handle(String::New(breakPointAtScript));
bpt = thread->isolate()->debugger()->SetBreakpointAtLineCol(aScriptUri, line,
col);
} else {
bpt = thread->isolate()->debugger()->SetBreakpointAtLineCol(script_uri, line,
col);
}
// if (DebugBreakPointCounter == 0) {
// DebugBreakPointCounter++;
// const String& script_uri_2 = String::Handle(String::New("org-dartlang-sdk:///sdk/lib/_http/http_impl.dart"));
// line = 2266; // 2266 _http/http_impl.dart
// bpt = thread->isolate()->debugger()->SetBreakpointAtLineCol(script_uri_2, line,
// col);
// } else {
// bpt = thread->isolate()->debugger()->SetBreakpointAtLineCol(script_uri, line,
// col);
// }

if (bpt == NULL) {
js->PrintError(kCannotAddBreakpoint,
"%s: Cannot add breakpoint at line '%s'", js->method(),
Expand Down

0 comments on commit fab2e90

Please sign in to comment.