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

Side by Side Diff: base/debug_on_start.cc

Issue 5984007: Move base/debug_on_start to base/debugger and rename it to be _win since it... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 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
« no previous file with comments | « base/debug_on_start.h ('k') | base/test/test_suite.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <windows.h>
6
7 #include "base/debug_on_start.h"
8
9 #include "base/base_switches.h"
10 #include "base/basictypes.h"
11 #include "base/debug/debugger.h"
12
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
15 // in the process startup.
16 // The code is not that bright and will find things like ---argument or
17 // /-/argument.
18 // Note: command_line is non-destructively modified.
19 bool DebugOnStart::FindArgument(wchar_t* command_line, const char* argument_c) {
20 wchar_t argument[50];
21 for (int i = 0; argument_c[i]; ++i)
22 argument[i] = argument_c[i];
23
24 int argument_len = lstrlen(argument);
25 int command_line_len = lstrlen(command_line);
26 while (command_line_len > argument_len) {
27 wchar_t first_char = command_line[0];
28 wchar_t last_char = command_line[argument_len+1];
29 // Try to find an argument.
30 if ((first_char == L'-' || first_char == L'/') &&
31 (last_char == L' ' || last_char == 0 || last_char == L'=')) {
32 command_line[argument_len+1] = 0;
33 // Skip the - or /
34 if (lstrcmpi(command_line+1, argument) == 0) {
35 // Found it.
36 command_line[argument_len+1] = last_char;
37 return true;
38 }
39 // Fix back.
40 command_line[argument_len+1] = last_char;
41 }
42 // Continue searching.
43 ++command_line;
44 --command_line_len;
45 }
46 return false;
47 }
48
49 // static
50 int __cdecl DebugOnStart::Init() {
51 // Try to find the argument.
52 if (FindArgument(GetCommandLine(), switches::kDebugOnStart)) {
53 // We can do 2 things here:
54 // - Ask for a debugger to attach to us. This involve reading the registry
55 // key and creating the process.
56 // - Do a int3.
57
58 // It will fails if we run in a sandbox. That is expected.
59 base::debug::SpawnDebuggerOnProcess(GetCurrentProcessId());
60
61 // Wait for a debugger to come take us.
62 base::debug::WaitForDebugger(60, false);
63 } else if (FindArgument(GetCommandLine(), switches::kWaitForDebugger)) {
64 // Wait for a debugger to come take us.
65 base::debug::WaitForDebugger(60, true);
66 }
67 return 0;
68 }
OLDNEW
« no previous file with comments | « base/debug_on_start.h ('k') | base/test/test_suite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698