Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cstdio> | 5 #include <cstdio> |
| 6 #include <cstring> | 6 #include <cstring> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 | 14 |
| 15 static const char kArgs[] = "--args"; | 15 static const char kArgs[] = "--args"; |
| 16 static const char kEvalCommand[] = "--eval-command"; | 16 static const char kEvalCommand[] = "--eval-command"; |
| 17 static const char kCommand[] = "--command"; | |
| 17 static const char kNaClIrt[] = "nacl-irt "; | 18 static const char kNaClIrt[] = "nacl-irt "; |
| 18 static const char kPass[] = "PASS"; | 19 static const char kPass[] = "PASS"; |
| 19 static const char kDump[] = "dump binary value "; | 20 static const char kDump[] = "dump binary value "; |
| 20 static const char kAttach[] = "attach "; | 21 static const char kAttach[] = "attach "; |
| 21 | 22 |
| 22 // Send message to child nacl_helper | 23 // Send message to child nacl_helper |
| 23 void SendMessage(const char* arg) { | 24 void SendMessage(const char* arg) { |
| 24 const char* file_end = strchr(arg, ' '); | 25 const char* file_end = strchr(arg, ' '); |
| 25 CHECK(file_end); | 26 CHECK(file_end); |
| 26 char buf = '\0'; | 27 char buf = '\0'; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 57 i += 2; | 58 i += 2; |
| 58 // Command line shouldn't end with --eval-command switch without value. | 59 // Command line shouldn't end with --eval-command switch without value. |
| 59 CHECK_LE(i, argc); | 60 CHECK_LE(i, argc); |
| 60 if (strncmp(argv[i - 1], kDump, sizeof(kDump) - 1) == 0) { | 61 if (strncmp(argv[i - 1], kDump, sizeof(kDump) - 1) == 0) { |
| 61 message_pipe = argv[i - 1] + sizeof(kDump) - 1; | 62 message_pipe = argv[i - 1] + sizeof(kDump) - 1; |
| 62 } else if (strncmp(argv[i - 1], kAttach, sizeof(kAttach) - 1) == 0) { | 63 } else if (strncmp(argv[i - 1], kAttach, sizeof(kAttach) - 1) == 0) { |
| 63 has_attach_cmd = true; | 64 has_attach_cmd = true; |
| 64 } | 65 } |
| 65 continue; | 66 continue; |
| 66 } | 67 } |
| 68 if (strcmp(argv[i], kCommand) == 0) { | |
|
Mark Seaborn
2012/05/24 17:25:58
It looks to me that if no --command arg is provide
halyavin
2012/05/25 09:37:45
Done.
| |
| 69 // Command line shouldn't end with --command switch without value. | |
| 70 i += 2; | |
| 71 CHECK_LE(i, argc); | |
| 72 std::string nacl_gdb_script; | |
| 73 env->GetVar("NACL_GDB_SCRIPT", &nacl_gdb_script); | |
| 74 CHECK_EQ(strcmp(argv[i - 1], nacl_gdb_script.c_str()), 0); | |
| 75 continue; | |
| 76 } | |
| 67 // Unknown argument. | 77 // Unknown argument. |
| 68 NOTREACHED() << "Invalid argument " << argv[i]; | 78 NOTREACHED() << "Invalid argument " << argv[i]; |
| 69 } | 79 } |
| 70 if (has_attach_cmd) { | 80 if (has_attach_cmd) { |
| 71 CHECK_EQ(i, argc); | 81 CHECK_EQ(i, argc); |
| 72 CHECK(message_pipe); | 82 CHECK(message_pipe); |
| 73 // Test passed, so we can let NaCl launching to continue. | 83 // Test passed, so we can let NaCl launching to continue. |
| 74 SendMessage(message_pipe); | 84 SendMessage(message_pipe); |
| 75 return 0; | 85 return 0; |
| 76 } | 86 } |
| 77 // --args switch must be present. | 87 // --args switch must be present. |
| 78 CHECK_LT(i, argc); | 88 CHECK_LT(i, argc); |
| 79 | 89 |
| 80 CommandLine::StringVector arguments; | 90 CommandLine::StringVector arguments; |
| 81 for (; i < argc; i++) { | 91 for (; i < argc; i++) { |
| 82 arguments.push_back( | 92 arguments.push_back( |
| 83 CommandLine::StringType(argv[i], argv[i] + strlen(argv[i]))); | 93 CommandLine::StringType(argv[i], argv[i] + strlen(argv[i]))); |
| 84 } | 94 } |
| 85 CommandLine cmd_line(arguments); | 95 CommandLine cmd_line(arguments); |
| 86 // Process must be launched successfully. | 96 // Process must be launched successfully. |
| 87 PCHECK(base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL)); | 97 PCHECK(base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL)); |
| 88 return 0; | 98 return 0; |
| 89 } | 99 } |
| OLD | NEW |