ipc/chromium/src/base/debug_on_start.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include <windows.h>
michael@0 6
michael@0 7 #include "base/debug_on_start.h"
michael@0 8
michael@0 9 #include "base/base_switches.h"
michael@0 10 #include "base/basictypes.h"
michael@0 11 #include "base/debug_util.h"
michael@0 12
michael@0 13 // Minimalist implementation to try to find a command line argument. We can use
michael@0 14 // kernel32 exported functions but not the CRT functions because we're too early
michael@0 15 // in the process startup.
michael@0 16 // The code is not that bright and will find things like ---argument or
michael@0 17 // /-/argument.
michael@0 18 // Note: command_line is non-destructively modified.
michael@0 19 bool DebugOnStart::FindArgument(wchar_t* command_line, const wchar_t* argument)
michael@0 20 {
michael@0 21 int argument_len = lstrlen(argument);
michael@0 22 int command_line_len = lstrlen(command_line);
michael@0 23 while (command_line_len > argument_len) {
michael@0 24 wchar_t first_char = command_line[0];
michael@0 25 wchar_t last_char = command_line[argument_len+1];
michael@0 26 // Try to find an argument.
michael@0 27 if ((first_char == L'-' || first_char == L'/') &&
michael@0 28 (last_char == L' ' || last_char == 0 || last_char == L'=')) {
michael@0 29 command_line[argument_len+1] = 0;
michael@0 30 // Skip the - or /
michael@0 31 if (lstrcmpi(command_line+1, argument) == 0) {
michael@0 32 // Found it.
michael@0 33 command_line[argument_len+1] = last_char;
michael@0 34 return true;
michael@0 35 }
michael@0 36 // Fix back.
michael@0 37 command_line[argument_len+1] = last_char;
michael@0 38 }
michael@0 39 // Continue searching.
michael@0 40 ++command_line;
michael@0 41 --command_line_len;
michael@0 42 }
michael@0 43 return false;
michael@0 44 }
michael@0 45
michael@0 46 // static
michael@0 47 int __cdecl DebugOnStart::Init() {
michael@0 48 // Try to find the argument.
michael@0 49 if (FindArgument(GetCommandLine(), switches::kDebugOnStart)) {
michael@0 50 // We can do 2 things here:
michael@0 51 // - Ask for a debugger to attach to us. This involve reading the registry
michael@0 52 // key and creating the process.
michael@0 53 // - Do a int3.
michael@0 54
michael@0 55 // It will fails if we run in a sandbox. That is expected.
michael@0 56 DebugUtil::SpawnDebuggerOnProcess(GetCurrentProcessId());
michael@0 57
michael@0 58 // Wait for a debugger to come take us.
michael@0 59 DebugUtil::WaitForDebugger(60, false);
michael@0 60 } else if (FindArgument(GetCommandLine(), switches::kWaitForDebugger)) {
michael@0 61 // Wait for a debugger to come take us.
michael@0 62 DebugUtil::WaitForDebugger(60, true);
michael@0 63 }
michael@0 64 return 0;
michael@0 65 }

mercurial