OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "base/debug_on_start.h" | 7 #include "base/debug_on_start.h" |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/debug_util.h" | 11 #include "base/debug_util.h" |
12 | 12 |
13 // Minimalist implementation to try to find a command line argument. We can use | 13 // Minimalist implementation to try to find a command line argument. We can use |
14 // kernel32 exported functions but not the CRT functions because we're too early | 14 // kernel32 exported functions but not the CRT functions because we're too early |
15 // in the process startup. | 15 // in the process startup. |
16 // The code is not that bright and will find things like ---argument or | 16 // The code is not that bright and will find things like ---argument or |
17 // /-/argument. | 17 // /-/argument. |
18 // Note: command_line is non-destructively modified. | 18 // Note: command_line is non-destructively modified. |
19 bool DebugOnStart::FindArgument(wchar_t* command_line, const wchar_t* argument) | 19 bool DebugOnStart::FindArgument(wchar_t* command_line, const char* argument_c) |
20 { | 20 { |
| 21 wchar_t argument[50]; |
| 22 for (int i = 0; argument_c[i]; ++i) |
| 23 argument[i] = argument_c[i]; |
| 24 |
21 int argument_len = lstrlen(argument); | 25 int argument_len = lstrlen(argument); |
22 int command_line_len = lstrlen(command_line); | 26 int command_line_len = lstrlen(command_line); |
23 while (command_line_len > argument_len) { | 27 while (command_line_len > argument_len) { |
24 wchar_t first_char = command_line[0]; | 28 wchar_t first_char = command_line[0]; |
25 wchar_t last_char = command_line[argument_len+1]; | 29 wchar_t last_char = command_line[argument_len+1]; |
26 // Try to find an argument. | 30 // Try to find an argument. |
27 if ((first_char == L'-' || first_char == L'/') && | 31 if ((first_char == L'-' || first_char == L'/') && |
28 (last_char == L' ' || last_char == 0 || last_char == L'=')) { | 32 (last_char == L' ' || last_char == 0 || last_char == L'=')) { |
29 command_line[argument_len+1] = 0; | 33 command_line[argument_len+1] = 0; |
30 // Skip the - or / | 34 // Skip the - or / |
(...skipping 25 matching lines...) Expand all Loading... |
56 DebugUtil::SpawnDebuggerOnProcess(GetCurrentProcessId()); | 60 DebugUtil::SpawnDebuggerOnProcess(GetCurrentProcessId()); |
57 | 61 |
58 // Wait for a debugger to come take us. | 62 // Wait for a debugger to come take us. |
59 DebugUtil::WaitForDebugger(60, false); | 63 DebugUtil::WaitForDebugger(60, false); |
60 } else if (FindArgument(GetCommandLine(), switches::kWaitForDebugger)) { | 64 } else if (FindArgument(GetCommandLine(), switches::kWaitForDebugger)) { |
61 // Wait for a debugger to come take us. | 65 // Wait for a debugger to come take us. |
62 DebugUtil::WaitForDebugger(60, true); | 66 DebugUtil::WaitForDebugger(60, true); |
63 } | 67 } |
64 return 0; | 68 return 0; |
65 } | 69 } |
OLD | NEW |