Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/browser/nacl_host/test/mock_nacl_gdb.cc

Issue 9950055: Enable --nacl-gdb flag on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: style nit Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/process_util.h" 13 #include "base/process_util.h"
13 14
14 static const char kArgs[] = "--args"; 15 static const char kArgs[] = "--args";
15 static const char kEvalCommand[] = "--eval-command"; 16 static const char kEvalCommand[] = "-ex";
Mark Seaborn 2012/04/03 21:57:44 Keep it as --eval-command
16 static const char kNaClIrt[] = "nacl-irt "; 17 static const char kNaClIrt[] = "nacl-irt ";
17 static const char kPass[] = "PASS"; 18 static const char kPass[] = "PASS";
19 static const char kDump[] = "dump binary value ";
20 static const char kAttach[] = "attach ";
21
22 // Send message to child nacl_helper
23 void SendMessage(const char* arg) {
24 const char* file_end = strchr(arg, ' ');
25 CHECK(file_end);
26 char buf = '\0';
27 file_util::WriteFile(FilePath(FilePath::StringType(arg, file_end)), &buf, 1);
28 }
18 29
19 int main(int argc, char** argv) { 30 int main(int argc, char** argv) {
20 scoped_ptr<base::Environment> env(base::Environment::Create()); 31 scoped_ptr<base::Environment> env(base::Environment::Create());
21 std::string mock_nacl_gdb_file; 32 std::string mock_nacl_gdb_file;
22 env->GetVar("MOCK_NACL_GDB", &mock_nacl_gdb_file); 33 env->GetVar("MOCK_NACL_GDB", &mock_nacl_gdb_file);
23 file_util::WriteFile(FilePath::FromUTF8Unsafe(mock_nacl_gdb_file), 34 file_util::WriteFile(FilePath::FromUTF8Unsafe(mock_nacl_gdb_file),
24 kPass, strlen(kPass)); 35 kPass, strlen(kPass));
25 CHECK_GE(argc, 3); 36 CHECK_GE(argc, 3);
26 // First argument should be --eval-command. 37 // First argument should be --eval-command.
27 CHECK_EQ(strcmp(argv[1], kEvalCommand), 0); 38 CHECK_EQ(strcmp(argv[1], kEvalCommand), 0);
28 // Second argument should start with nacl-irt. 39 // Second argument should start with nacl-irt.
29 CHECK_GE(strlen(argv[2]), strlen(kNaClIrt)); 40 CHECK_GE(strlen(argv[2]), strlen(kNaClIrt));
30 CHECK_EQ(strncmp(argv[2], kNaClIrt, strlen(kNaClIrt)), 0); 41 CHECK_EQ(strncmp(argv[2], kNaClIrt, strlen(kNaClIrt)), 0);
31 char* irt_file_name = &argv[2][strlen(kNaClIrt)]; 42 char* irt_file_name = &argv[2][strlen(kNaClIrt)];
32 FILE* irt_file = fopen(irt_file_name, "r"); 43 FILE* irt_file = fopen(irt_file_name, "r");
33 // nacl-irt parameter must be a file name. 44 // nacl-irt parameter must be a file name.
34 PCHECK(irt_file); 45 PCHECK(irt_file);
35 fclose(irt_file); 46 fclose(irt_file);
36 int i = 3; 47 int i = 3;
48 bool has_attach_cmd = false;
49 char* message_pipe = NULL;
37 // Skip additional --eval-command parameters. 50 // Skip additional --eval-command parameters.
38 while (i < argc) { 51 while (i < argc) {
39 if (strcmp(argv[i], kArgs) == 0) { 52 if (strcmp(argv[i], kArgs) == 0) {
40 i++; 53 i++;
41 break; 54 break;
42 } 55 }
43 if (strcmp(argv[i], kEvalCommand) == 0) { 56 if (strcmp(argv[i], kEvalCommand) == 0) {
44 i += 2; 57 i += 2;
45 // Command line shouldn't end with --eval-command switch without value. 58 // Command line shouldn't end with -ex switch without value.
46 CHECK_LE(i, argc); 59 CHECK_LE(i, argc);
60 if (strncmp(argv[i - 1], kDump, sizeof(kDump) - 1) == 0) {
Mark Seaborn 2012/04/03 21:57:44 FYI, you're mixing sizeof() and strlen() in this f
61 message_pipe = argv[i - 1] + sizeof(kDump) - 1;
62 } else if (strncmp(argv[i - 1], kAttach, sizeof(kAttach) - 1) == 0) {
63 has_attach_cmd = true;
64 }
47 continue; 65 continue;
48 } 66 }
49 // Unknown argument. 67 // Unknown argument.
50 NOTREACHED() << "Invalid argument " << argv[i]; 68 NOTREACHED() << "Invalid argument " << argv[i];
51 } 69 }
70 if (has_attach_cmd) {
71 CHECK_EQ(i, argc);
72 CHECK(message_pipe);
73 // Test passed, so we can let NaCl launching to continue.
74 SendMessage(message_pipe);
75 return 0;
76 }
52 // --args switch must be present. 77 // --args switch must be present.
53 CHECK_LT(i, argc); 78 CHECK_LT(i, argc);
54 79
55 CommandLine::StringVector arguments; 80 CommandLine::StringVector arguments;
56 for (; i < argc; i++) { 81 for (; i < argc; i++) {
57 arguments.push_back( 82 arguments.push_back(
58 CommandLine::StringType(argv[i], argv[i] + strlen(argv[i]))); 83 CommandLine::StringType(argv[i], argv[i] + strlen(argv[i])));
59 } 84 }
60 CommandLine cmd_line(arguments); 85 CommandLine cmd_line(arguments);
61 // Process must be launched successfully. 86 // Process must be launched successfully.
62 PCHECK(base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL)); 87 PCHECK(base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL));
63 return 0; 88 return 0;
64 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698