1 // Copyright 2013 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.
5 #include "mojo/runner/init.h"
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 #include "base/debug/debugger.h"
10 #include "base/logging.h"
11 #include "base/stl_util.h"
12 #include "base/strings/string_split.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "mojo/runner/switches.h"
25 void InitializeLogging() {
26 logging::LoggingSettings settings
;
27 settings
.logging_dest
= logging::LOG_TO_SYSTEM_DEBUG_LOG
;
28 logging::InitLogging(settings
);
29 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
30 logging::SetLogItems(false, // Process ID
36 void WaitForDebuggerIfNecessary() {
37 const base::CommandLine
* command_line
=
38 base::CommandLine::ForCurrentProcess();
39 if (command_line
->HasSwitch(switches::kWaitForDebugger
)) {
40 std::vector
<std::string
> apps_to_debug
;
42 command_line
->GetSwitchValueASCII(switches::kWaitForDebugger
), ',',
44 std::string app
= command_line
->GetSwitchValueASCII(switches::kApp
);
46 app
= "launcher"; // If we're not in a child process look for "launcher".
47 if (apps_to_debug
.empty() || ContainsValue(apps_to_debug
, app
)) {
49 base::string16 appw
= base::UTF8ToUTF16(app
);
50 MessageBox(NULL
, appw
.c_str(), appw
.c_str(), MB_OK
| MB_SETFOREGROUND
);
52 LOG(ERROR
) << app
<< " waiting for GDB. pid: " << getpid();
53 base::debug::WaitForDebugger(60, true);