/
crashpad-initialize-logging.patch
146 lines (135 loc) · 6.27 KB
/
crashpad-initialize-logging.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Joshua Peraza <jperaza@chromium.org>
Date: Wed, 21 Oct 2020 11:10:25 -0700
Subject: Initialize logging for crashpad
Although logging to files is not yet supported by mini_chromium, it is
the default behavior for OS_WIN in chromium. This change should
cause crashpad to log via OutputDebugString() on Windows, instead of
debug.log files. Future work (crbug.com/crashpad/26) should arrange for
logs to be uploaded with reports, embedded in associated minidumps or as
file attachments.
Bug: chromium:711159
Change-Id: I0f9004f7de94dd29d555cc7d23c48a63da6b4bba
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2425108
Reviewed-by: Mark Mentovai <mark@chromium.org>
diff --git a/base/logging.cc b/base/logging.cc
index 608cc1122b98803b66c4b4a4eee1020ffe94e20c..6f9005ba2f21efe2f81b4fde0360d672b9f58022 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -410,21 +410,23 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
0u);
#endif
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
- // Don't bother initializing |g_vlog_info| unless we use one of the
- // vlog switches.
- if (command_line->HasSwitch(switches::kV) ||
- command_line->HasSwitch(switches::kVModule)) {
- // NOTE: If |g_vlog_info| has already been initialized, it might be in use
- // by another thread. Don't delete the old VLogInfo, just create a second
- // one. We keep track of both to avoid memory leak warnings.
- CHECK(!g_vlog_info_prev);
- g_vlog_info_prev = g_vlog_info;
-
- g_vlog_info =
- new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
- command_line->GetSwitchValueASCII(switches::kVModule),
- &g_min_log_level);
+ if (base::CommandLine::InitializedForCurrentProcess()) {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ // Don't bother initializing |g_vlog_info| unless we use one of the
+ // vlog switches.
+ if (command_line->HasSwitch(switches::kV) ||
+ command_line->HasSwitch(switches::kVModule)) {
+ // NOTE: If |g_vlog_info| has already been initialized, it might be in use
+ // by another thread. Don't delete the old VLogInfo, just create a second
+ // one. We keep track of both to avoid memory leak warnings.
+ CHECK(!g_vlog_info_prev);
+ g_vlog_info_prev = g_vlog_info;
+
+ g_vlog_info =
+ new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
+ command_line->GetSwitchValueASCII(switches::kVModule),
+ &g_min_log_level);
+ }
}
g_logging_destination = settings.logging_dest;
@@ -435,7 +437,10 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
config.min_severity = FX_LOG_INFO;
config.console_fd = -1;
config.log_service_channel = ZX_HANDLE_INVALID;
- std::string log_tag = command_line->GetProgram().BaseName().AsUTF8Unsafe();
+ std::string log_tag = base::CommandLine::ForCurrentProcess()
+ ->GetProgram()
+ .BaseName()
+ .AsUTF8Unsafe();
const char* log_tag_data = log_tag.data();
config.tags = &log_tag_data;
config.num_tags = 1;
diff --git a/third_party/crashpad/crashpad/DEPS b/third_party/crashpad/crashpad/DEPS
index 8b958f1887be77ac54c878a9e1474fb67574950a..0cd250f0bb67888e83fcdd8cce856e0d8a8d29a5 100644
--- a/third_party/crashpad/crashpad/DEPS
+++ b/third_party/crashpad/crashpad/DEPS
@@ -42,7 +42,7 @@ deps = {
'7bde79cc274d06451bf65ae82c012a5d3e476b5a',
'crashpad/third_party/mini_chromium/mini_chromium':
Var('chromium_git') + '/chromium/mini_chromium@' +
- 'c426ff98e1d9e9d59777fe8b883a5c0ceeca9ca3',
+ '5fc64bfbf1c000161445c586de45e40464ff2314',
'crashpad/third_party/libfuzzer/src':
Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' +
'fda403cf93ecb8792cb1d061564d89a6553ca020',
diff --git a/third_party/crashpad/crashpad/handler/handler_main.cc b/third_party/crashpad/crashpad/handler/handler_main.cc
index e0a262cd1f38bb4b663b6d13b28fcc272d69bef1..6e6adc536208f5094589e885ce6a7610e994b5d3 100644
--- a/third_party/crashpad/crashpad/handler/handler_main.cc
+++ b/third_party/crashpad/crashpad/handler/handler_main.cc
@@ -519,16 +519,26 @@ class ScopedStoppable {
DISALLOW_COPY_AND_ASSIGN(ScopedStoppable);
};
+void InitCrashpadLogging() {
+ logging::LoggingSettings settings;
+#if defined(OS_CHROMEOS)
+ settings.logging_dest = logging::LOG_TO_FILE;
+ settings.log_file_path = "/var/log/chrome/chrome";
+#elif defined(OS_WIN)
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+#else
+ settings.logging_dest =
+ logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
+#endif
+ logging::InitLogging(settings);
+}
+
} // namespace
int HandlerMain(int argc,
char* argv[],
const UserStreamDataSources* user_stream_sources) {
-#if defined(OS_CHROMEOS)
- if (freopen("/var/log/chrome/chrome", "a", stderr) == nullptr) {
- PLOG(ERROR) << "Failed to redirect stderr to /var/log/chrome/chrome";
- }
-#endif
+ InitCrashpadLogging();
InstallCrashHandler();
CallMetricsRecordNormalExit metrics_record_normal_exit;
diff --git a/third_party/crashpad/crashpad/test/gtest_main.cc b/third_party/crashpad/crashpad/test/gtest_main.cc
index ad3a095ea7657b60b6fc05d09fb04319dbee1b17..5b64a2f886bca5531691963059dd47e89174fb04 100644
--- a/third_party/crashpad/crashpad/test/gtest_main.cc
+++ b/third_party/crashpad/crashpad/test/gtest_main.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "base/logging.h"
#include "build/build_config.h"
#include "gtest/gtest.h"
#include "test/main_arguments.h"
@@ -91,6 +92,12 @@ int main(int argc, char* argv[]) {
#endif // CRASHPAD_IS_IN_CHROMIUM
+// base::TestSuite initializes logging when using Chromium's test launcher.
+logging::LoggingSettings settings;
+settings.logging_dest =
+ logging::LOG_TO_STDERR | logging::LOG_TO_SYSTEM_DEBUG_LOG;
+logging::InitLogging(settings);
+
#if defined(CRASHPAD_TEST_LAUNCHER_GMOCK)
testing::InitGoogleMock(&argc, argv);
#elif defined(CRASHPAD_TEST_LAUNCHER_GTEST)