OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
11 | 11 |
12 #include "bin/builtin.h" | 12 #include "bin/builtin.h" |
13 #include "bin/dartutils.h" | 13 #include "bin/dartutils.h" |
14 #include "bin/dbg_connection.h" | |
14 #include "bin/directory.h" | 15 #include "bin/directory.h" |
15 #include "bin/eventhandler.h" | 16 #include "bin/eventhandler.h" |
16 #include "bin/extensions.h" | 17 #include "bin/extensions.h" |
17 #include "bin/file.h" | 18 #include "bin/file.h" |
18 #include "bin/platform.h" | 19 #include "bin/platform.h" |
19 #include "bin/process.h" | 20 #include "bin/process.h" |
20 #include "platform/globals.h" | 21 #include "platform/globals.h" |
21 | 22 |
22 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 23 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
23 // it is initialized to NULL. | 24 // it is initialized to NULL. |
(...skipping 15 matching lines...) Expand all Loading... | |
39 // to be generated or not. | 40 // to be generated or not. |
40 static const char* generate_pprof_symbols_filename = NULL; | 41 static const char* generate_pprof_symbols_filename = NULL; |
41 | 42 |
42 | 43 |
43 // Global state that indicates whether there is a debug breakpoint. | 44 // Global state that indicates whether there is a debug breakpoint. |
44 // This pointer points into an argv buffer and does not need to be | 45 // This pointer points into an argv buffer and does not need to be |
45 // free'd. | 46 // free'd. |
46 static const char* breakpoint_at = NULL; | 47 static const char* breakpoint_at = NULL; |
47 | 48 |
48 | 49 |
50 // Global state that indicates whether we should open a connection | |
51 // and listen for a debugger to connect. | |
52 static bool start_debugger = false; | |
53 static const int DEFAULT_DEBUG_PORT = 5858; | |
54 static int debug_port = 0; | |
55 | |
56 | |
49 // Value of the --package-root flag. | 57 // Value of the --package-root flag. |
50 // (This pointer points into an argv buffer and does not need to be | 58 // (This pointer points into an argv buffer and does not need to be |
51 // free'd.) | 59 // free'd.) |
52 static const char* package_root = NULL; | 60 static const char* package_root = NULL; |
53 | 61 |
54 | 62 |
55 // Global flag that is used to indicate that we want to compile all the | 63 // Global flag that is used to indicate that we want to compile all the |
56 // dart functions and not run anything. | 64 // dart functions and not run anything. |
57 static bool has_compile_all = false; | 65 static bool has_compile_all = false; |
58 | 66 |
(...skipping 18 matching lines...) Expand all Loading... | |
77 package_root = arg; | 85 package_root = arg; |
78 } | 86 } |
79 | 87 |
80 | 88 |
81 static void ProcessCompileAllOption(const char* compile_all) { | 89 static void ProcessCompileAllOption(const char* compile_all) { |
82 ASSERT(compile_all != NULL); | 90 ASSERT(compile_all != NULL); |
83 has_compile_all = true; | 91 has_compile_all = true; |
84 } | 92 } |
85 | 93 |
86 | 94 |
95 static void ProcessDebugOption(const char* port) { | |
96 ASSERT(port != NULL); | |
97 debug_port = 0; | |
98 if (*port == '\0') { | |
99 debug_port = DEFAULT_DEBUG_PORT; | |
100 } else { | |
101 if ((*port == '=') || (*port == ':')) { | |
102 debug_port = atoi(port + 1); | |
103 } | |
104 } | |
105 if (debug_port == 0) { | |
106 fprintf(stderr, "unrecognized --debug option syntax. " | |
107 "Use --debug[:<port number>]\n"); | |
siva
2012/05/03 22:52:08
see comment regarding having this option be
--debu
hausner
2012/05/03 23:52:00
Done.
| |
108 return; | |
109 } | |
110 breakpoint_at = "main"; | |
siva
2012/05/03 22:52:08
Maybe later on this should also be a command line
hausner
2012/05/03 23:52:00
I agree. For now, I need this because I can't inte
| |
111 start_debugger = true; | |
112 } | |
113 | |
114 | |
87 static void ProcessPprofOption(const char* filename) { | 115 static void ProcessPprofOption(const char* filename) { |
88 ASSERT(filename != NULL); | 116 ASSERT(filename != NULL); |
89 generate_pprof_symbols_filename = filename; | 117 generate_pprof_symbols_filename = filename; |
90 } | 118 } |
91 | 119 |
92 | 120 |
93 static void ProcessImportMapOption(const char* map) { | 121 static void ProcessImportMapOption(const char* map) { |
94 ASSERT(map != NULL); | 122 ASSERT(map != NULL); |
95 import_map_options->AddArgument(map); | 123 import_map_options->AddArgument(map); |
96 } | 124 } |
97 | 125 |
98 | 126 |
99 static struct { | 127 static struct { |
100 const char* option_name; | 128 const char* option_name; |
101 void (*process)(const char* option); | 129 void (*process)(const char* option); |
102 } main_options[] = { | 130 } main_options[] = { |
103 { "--break_at=", ProcessBreakpointOption }, | 131 { "--break_at=", ProcessBreakpointOption }, |
104 { "--compile_all", ProcessCompileAllOption }, | 132 { "--compile_all", ProcessCompileAllOption }, |
133 { "--debug", ProcessDebugOption }, | |
105 { "--generate_pprof_symbols=", ProcessPprofOption }, | 134 { "--generate_pprof_symbols=", ProcessPprofOption }, |
106 { "--import_map=", ProcessImportMapOption }, | 135 { "--import_map=", ProcessImportMapOption }, |
107 { "--package-root=", ProcessPackageRootOption }, | 136 { "--package-root=", ProcessPackageRootOption }, |
108 { NULL, NULL } | 137 { NULL, NULL } |
109 }; | 138 }; |
110 | 139 |
111 | 140 |
112 static bool ProcessMainOptions(const char* option) { | 141 static bool ProcessMainOptions(const char* option) { |
113 int i = 0; | 142 int i = 0; |
114 const char* name = main_options[0].option_name; | 143 const char* name = main_options[0].option_name; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 } | 635 } |
607 // Set debug breakpoint if specified on the command line. | 636 // Set debug breakpoint if specified on the command line. |
608 if (breakpoint_at != NULL) { | 637 if (breakpoint_at != NULL) { |
609 result = SetBreakpoint(breakpoint_at, library); | 638 result = SetBreakpoint(breakpoint_at, library); |
610 if (Dart_IsError(result)) { | 639 if (Dart_IsError(result)) { |
611 return ErrorExit("Error setting breakpoint at '%s': %s\n", | 640 return ErrorExit("Error setting breakpoint at '%s': %s\n", |
612 breakpoint_at, | 641 breakpoint_at, |
613 Dart_GetError(result)); | 642 Dart_GetError(result)); |
614 } | 643 } |
615 } | 644 } |
645 | |
646 // Start the debugger wire protocol handler if necessary. | |
647 if (start_debugger) { | |
648 ASSERT(debug_port != 0); | |
649 DebuggerConnectionHandler::StartHandler(debug_port); | |
650 } | |
651 | |
616 // Lookup and invoke the top level main function. | 652 // Lookup and invoke the top level main function. |
617 result = Dart_Invoke(library, Dart_NewString("main"), 0, NULL); | 653 result = Dart_Invoke(library, Dart_NewString("main"), 0, NULL); |
618 if (Dart_IsError(result)) { | 654 if (Dart_IsError(result)) { |
619 return ErrorExit("%s\n", Dart_GetError(result)); | 655 return ErrorExit("%s\n", Dart_GetError(result)); |
620 } | 656 } |
621 // Keep handling messages until the last active receive port is closed. | 657 // Keep handling messages until the last active receive port is closed. |
622 result = Dart_RunLoop(); | 658 result = Dart_RunLoop(); |
623 if (Dart_IsError(result)) { | 659 if (Dart_IsError(result)) { |
624 return ErrorExit("%s\n", Dart_GetError(result)); | 660 return ErrorExit("%s\n", Dart_GetError(result)); |
625 } | 661 } |
626 | 662 |
627 Dart_ExitScope(); | 663 Dart_ExitScope(); |
628 // Dump symbol information for the profiler. | 664 // Dump symbol information for the profiler. |
629 DumpPprofSymbolInfo(); | 665 DumpPprofSymbolInfo(); |
630 // Shutdown the isolate. | 666 // Shutdown the isolate. |
631 Dart_ShutdownIsolate(); | 667 Dart_ShutdownIsolate(); |
632 // Terminate process exit-code handler. | 668 // Terminate process exit-code handler. |
633 Process::TerminateExitCodeHandler(); | 669 Process::TerminateExitCodeHandler(); |
634 | 670 |
635 free(const_cast<char*>(original_script_name)); | 671 free(const_cast<char*>(original_script_name)); |
636 free(const_cast<char*>(original_working_directory)); | 672 free(const_cast<char*>(original_working_directory)); |
637 free(const_cast<char*>(original_script_url)); | 673 free(const_cast<char*>(original_script_url)); |
638 | 674 |
639 return 0; | 675 return 0; |
640 } | 676 } |
OLD | NEW |