| 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 const char* DEFAULT_DEBUG_IP = "127.0.0.1"; |
| 55 static const char* debug_ip = DEFAULT_DEBUG_IP; |
| 56 static int debug_port = 0; |
| 57 |
| 58 |
| 49 // Value of the --package-root flag. | 59 // Value of the --package-root flag. |
| 50 // (This pointer points into an argv buffer and does not need to be | 60 // (This pointer points into an argv buffer and does not need to be |
| 51 // free'd.) | 61 // free'd.) |
| 52 static const char* package_root = NULL; | 62 static const char* package_root = NULL; |
| 53 | 63 |
| 54 | 64 |
| 55 // Global flag that is used to indicate that we want to compile all the | 65 // Global flag that is used to indicate that we want to compile all the |
| 56 // dart functions and not run anything. | 66 // dart functions and not run anything. |
| 57 static bool has_compile_all = false; | 67 static bool has_compile_all = false; |
| 58 | 68 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 package_root = arg; | 87 package_root = arg; |
| 78 } | 88 } |
| 79 | 89 |
| 80 | 90 |
| 81 static void ProcessCompileAllOption(const char* compile_all) { | 91 static void ProcessCompileAllOption(const char* compile_all) { |
| 82 ASSERT(compile_all != NULL); | 92 ASSERT(compile_all != NULL); |
| 83 has_compile_all = true; | 93 has_compile_all = true; |
| 84 } | 94 } |
| 85 | 95 |
| 86 | 96 |
| 97 static void ProcessDebugOption(const char* port) { |
| 98 // TODO(hausner): Add support for specifying an IP address on which |
| 99 // the debugger should listen. |
| 100 ASSERT(port != NULL); |
| 101 debug_port = 0; |
| 102 if (*port == '\0') { |
| 103 debug_port = DEFAULT_DEBUG_PORT; |
| 104 } else { |
| 105 if ((*port == '=') || (*port == ':')) { |
| 106 debug_port = atoi(port + 1); |
| 107 } |
| 108 } |
| 109 if (debug_port == 0) { |
| 110 fprintf(stderr, "unrecognized --debug option syntax. " |
| 111 "Use --debug[:<port number>]\n"); |
| 112 return; |
| 113 } |
| 114 breakpoint_at = "main"; |
| 115 start_debugger = true; |
| 116 } |
| 117 |
| 118 |
| 87 static void ProcessPprofOption(const char* filename) { | 119 static void ProcessPprofOption(const char* filename) { |
| 88 ASSERT(filename != NULL); | 120 ASSERT(filename != NULL); |
| 89 generate_pprof_symbols_filename = filename; | 121 generate_pprof_symbols_filename = filename; |
| 90 } | 122 } |
| 91 | 123 |
| 92 | 124 |
| 93 static void ProcessImportMapOption(const char* map) { | 125 static void ProcessImportMapOption(const char* map) { |
| 94 ASSERT(map != NULL); | 126 ASSERT(map != NULL); |
| 95 import_map_options->AddArgument(map); | 127 import_map_options->AddArgument(map); |
| 96 } | 128 } |
| 97 | 129 |
| 98 | 130 |
| 99 static struct { | 131 static struct { |
| 100 const char* option_name; | 132 const char* option_name; |
| 101 void (*process)(const char* option); | 133 void (*process)(const char* option); |
| 102 } main_options[] = { | 134 } main_options[] = { |
| 103 { "--break_at=", ProcessBreakpointOption }, | 135 { "--break_at=", ProcessBreakpointOption }, |
| 104 { "--compile_all", ProcessCompileAllOption }, | 136 { "--compile_all", ProcessCompileAllOption }, |
| 137 { "--debug", ProcessDebugOption }, |
| 105 { "--generate_pprof_symbols=", ProcessPprofOption }, | 138 { "--generate_pprof_symbols=", ProcessPprofOption }, |
| 106 { "--import_map=", ProcessImportMapOption }, | 139 { "--import_map=", ProcessImportMapOption }, |
| 107 { "--package-root=", ProcessPackageRootOption }, | 140 { "--package-root=", ProcessPackageRootOption }, |
| 108 { NULL, NULL } | 141 { NULL, NULL } |
| 109 }; | 142 }; |
| 110 | 143 |
| 111 | 144 |
| 112 static bool ProcessMainOptions(const char* option) { | 145 static bool ProcessMainOptions(const char* option) { |
| 113 int i = 0; | 146 int i = 0; |
| 114 const char* name = main_options[0].option_name; | 147 const char* name = main_options[0].option_name; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 639 } |
| 607 // Set debug breakpoint if specified on the command line. | 640 // Set debug breakpoint if specified on the command line. |
| 608 if (breakpoint_at != NULL) { | 641 if (breakpoint_at != NULL) { |
| 609 result = SetBreakpoint(breakpoint_at, library); | 642 result = SetBreakpoint(breakpoint_at, library); |
| 610 if (Dart_IsError(result)) { | 643 if (Dart_IsError(result)) { |
| 611 return ErrorExit("Error setting breakpoint at '%s': %s\n", | 644 return ErrorExit("Error setting breakpoint at '%s': %s\n", |
| 612 breakpoint_at, | 645 breakpoint_at, |
| 613 Dart_GetError(result)); | 646 Dart_GetError(result)); |
| 614 } | 647 } |
| 615 } | 648 } |
| 649 |
| 650 // Start the debugger wire protocol handler if necessary. |
| 651 if (start_debugger) { |
| 652 ASSERT(debug_port != 0); |
| 653 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); |
| 654 } |
| 655 |
| 616 // Lookup and invoke the top level main function. | 656 // Lookup and invoke the top level main function. |
| 617 result = Dart_Invoke(library, Dart_NewString("main"), 0, NULL); | 657 result = Dart_Invoke(library, Dart_NewString("main"), 0, NULL); |
| 618 if (Dart_IsError(result)) { | 658 if (Dart_IsError(result)) { |
| 619 return ErrorExit("%s\n", Dart_GetError(result)); | 659 return ErrorExit("%s\n", Dart_GetError(result)); |
| 620 } | 660 } |
| 621 // Keep handling messages until the last active receive port is closed. | 661 // Keep handling messages until the last active receive port is closed. |
| 622 result = Dart_RunLoop(); | 662 result = Dart_RunLoop(); |
| 623 if (Dart_IsError(result)) { | 663 if (Dart_IsError(result)) { |
| 624 return ErrorExit("%s\n", Dart_GetError(result)); | 664 return ErrorExit("%s\n", Dart_GetError(result)); |
| 625 } | 665 } |
| 626 | 666 |
| 627 Dart_ExitScope(); | 667 Dart_ExitScope(); |
| 628 // Dump symbol information for the profiler. | 668 // Dump symbol information for the profiler. |
| 629 DumpPprofSymbolInfo(); | 669 DumpPprofSymbolInfo(); |
| 630 // Shutdown the isolate. | 670 // Shutdown the isolate. |
| 631 Dart_ShutdownIsolate(); | 671 Dart_ShutdownIsolate(); |
| 632 // Terminate process exit-code handler. | 672 // Terminate process exit-code handler. |
| 633 Process::TerminateExitCodeHandler(); | 673 Process::TerminateExitCodeHandler(); |
| 634 | 674 |
| 635 free(const_cast<char*>(original_script_name)); | 675 free(const_cast<char*>(original_script_name)); |
| 636 free(const_cast<char*>(original_working_directory)); | 676 free(const_cast<char*>(original_working_directory)); |
| 637 free(const_cast<char*>(original_script_url)); | 677 free(const_cast<char*>(original_script_url)); |
| 638 | 678 |
| 639 return 0; | 679 return 0; |
| 640 } | 680 } |
| OLD | NEW |