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/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/stl_util.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "mojo/runner/switches.h"
26 void InitializeLogging() {
27 logging::LoggingSettings settings
;
28 settings
.logging_dest
= logging::LOG_TO_SYSTEM_DEBUG_LOG
;
29 logging::InitLogging(settings
);
30 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
31 logging::SetLogItems(false, // Process ID
37 void WaitForDebuggerIfNecessary() {
38 const base::CommandLine
* command_line
=
39 base::CommandLine::ForCurrentProcess();
40 if (command_line
->HasSwitch(switches::kWaitForDebugger
)) {
41 std::vector
<std::string
> apps_to_debug
= base::SplitString(
42 command_line
->GetSwitchValueASCII(switches::kWaitForDebugger
), ",",
43 base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
44 std::string app
= "launcher";
45 if (command_line
->HasSwitch(switches::kChildProcess
)) {
46 app
= command_line
->GetSwitchValuePath(switches::kChildProcess
)
51 if (apps_to_debug
.empty() || ContainsValue(apps_to_debug
, app
)) {
53 base::string16 appw
= base::UTF8ToUTF16(app
);
54 MessageBox(NULL
, appw
.c_str(), appw
.c_str(), MB_OK
| MB_SETFOREGROUND
);
56 LOG(ERROR
) << app
<< " waiting for GDB. pid: " << getpid();
57 base::debug::WaitForDebugger(60, true);