Chromium Code Reviews| Index: runtime/bin/main.cc |
| =================================================================== |
| --- runtime/bin/main.cc (revision 2094) |
| +++ runtime/bin/main.cc (working copy) |
| @@ -7,6 +7,7 @@ |
| #include <stdio.h> |
| #include "include/dart_api.h" |
| +#include "include/dart_dapi.h" |
| #include "bin/builtin.h" |
| #include "bin/dartutils.h" |
| @@ -28,6 +29,12 @@ |
| static const char* generate_pprof_symbols_filename = NULL; |
| +// Global state that indicates whether there is a debug breakpoint. |
| +// This pointer points into an argv buffer and does not need to be |
| +// free'd. |
| +static const char* breakpoint_at = NULL; |
| + |
| + |
| static bool IsValidFlag(const char* name, |
| const char* prefix, |
| intptr_t prefix_length) { |
| @@ -56,6 +63,16 @@ |
| } |
| +static bool ProcessDebugOption(const char* option) { |
| + const char* kDebugOption = "--break_at="; |
| + const char* func_name = ProcessOption(option, kDebugOption); |
| + if (func_name != NULL) { |
| + breakpoint_at = func_name; |
| + } |
| + return func_name != NULL; |
| +} |
| + |
| + |
| // Parse out the command line arguments. Returns -1 if the arguments |
| // are incorrect, 0 otherwise. |
| static int ParseArguments(int argc, |
| @@ -73,10 +90,12 @@ |
| while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
| if (ProcessPprofOption(argv[i])) { |
| i += 1; |
| - continue; |
| + } else if (ProcessDebugOption(argv[i])) { |
| + i += 1; |
| + } else { |
| + vm_options->AddArgument(argv[i]); |
| + i += 1; |
| } |
| - vm_options->AddArgument(argv[i]); |
| - i += 1; |
| } |
| if (generate_pprof_symbols_filename != NULL) { |
| Dart_InitPprofSupport(); |
| @@ -329,7 +348,7 @@ |
| return 255; // Indicates we encountered an error. |
| } |
| - // Lookup and invoke the top level main function. |
| + // Lookup the library of the main script. |
| Dart_Handle script_url = Dart_NewString(canonical_script_name); |
| Dart_Handle library = Dart_LookupLibrary(script_url); |
| if (Dart_IsError(library)) { |
| @@ -339,6 +358,35 @@ |
| free(canonical_script_name); |
| return 255; // Indicates we encountered an error. |
| } |
| + // Set debug breakpoint if specified on the command line. |
| + if (breakpoint_at != NULL) { |
| + char* bpt_function = strdup(breakpoint_at); |
| + Dart_Handle class_name; |
| + Dart_Handle function_name; |
| + char* dot = strchr(bpt_function, '.'); |
| + if (dot == NULL) { |
| + class_name = Dart_NewString(""); |
| + function_name = Dart_NewString(breakpoint_at); |
| + } else { |
| + *dot = '\0'; |
| + class_name = Dart_NewString(bpt_function); |
| + function_name = Dart_NewString(dot + 1); |
| + } |
| + free(bpt_function); |
| + Dart_Breakpoint bpt; |
| + result = Dart_SetBreakpointAtEntry( |
| + library, class_name, function_name, &bpt); |
| + if (Dart_IsError(result)) { |
| + fprintf(stderr, "Error setting breakpoint at '%s': %s\n", |
| + breakpoint_at, |
| + Dart_GetError(result)); |
| + Dart_ExitScope(); |
| + Dart_ShutdownIsolate(); |
| + free(canonical_script_name); |
| + return 255; // Indicates we encountered an error. |
| + } |
| + } |
|
siva
2011/12/07 05:44:48
I am assuming this a temporary setup, long term it
hausner
2011/12/07 22:14:26
Yes.
|
| + // Lookup and invoke the top level main function. |
| result = Dart_InvokeStatic(library, |
| Dart_NewString(""), |
| Dart_NewString("main"), |