Skip to content

Commit 00e6c56

Browse files
Joshua PerazaCommit Bot
Joshua Peraza
authored and
Commit Bot
committed
Reland "linux: Enable Crashpad for content shell"
This is a reland of 9747ecd Original change's description: > linux: Enable Crashpad for content shell > > Bug: 942279 > Change-Id: I221431e352f11b40c3bc39bbcd8297b431dd8f0c > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1763346 > Commit-Queue: Joshua Peraza <[email protected]> > Reviewed-by: Peter Beverloo <[email protected]> > Cr-Commit-Position: refs/heads/master@{#699880} Bug: 942279 Change-Id: I7ced7adacbbe585f5ea47d00163b69953912b99d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847882 Reviewed-by: Jochen Eisinger <[email protected]> Commit-Queue: Joshua Peraza <[email protected]> Cr-Commit-Position: refs/heads/master@{#729810}
1 parent f289439 commit 00e6c56

File tree

5 files changed

+41
-87
lines changed

5 files changed

+41
-87
lines changed

content/shell/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,9 @@ if (is_android) {
646646
configs -= [ "//build/config/win:console" ]
647647
configs += [ "//build/config/win:windowed" ]
648648
}
649+
}
649650

651+
if (is_win || is_linux) {
650652
data_deps +=
651653
[ "//third_party/crashpad/crashpad/handler:crashpad_handler" ]
652654
}

content/shell/app/shell_main_delegate.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#include "content/shell/android/shell_descriptors.h"
6868
#endif
6969

70-
#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_ANDROID)
70+
#if !defined(OS_FUCHSIA)
7171
#include "components/crash/content/app/crashpad.h" // nogncheck
7272
#endif
7373

@@ -85,7 +85,6 @@
8585
#endif
8686

8787
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
88-
#include "components/crash/content/app/breakpad_linux.h"
8988
#include "v8/include/v8-wasm-trap-handler-posix.h"
9089
#endif
9190

@@ -169,9 +168,7 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
169168

170169
v8_crashpad_support::SetUp();
171170
#endif
172-
#if defined(OS_LINUX)
173-
breakpad::SetFirstChanceExceptionHandler(v8::TryHandleWebAssemblyTrapPosix);
174-
#endif
171+
175172
#if defined(OS_MACOSX)
176173
// Needs to happen before InitializeResourceBundle() and before
177174
// BlinkTestPlatformInitialize() are called.
@@ -325,13 +322,14 @@ void ShellMainDelegate::PreSandboxStartup() {
325322
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
326323
switches::kProcessType);
327324
crash_reporter::SetCrashReporterClient(g_shell_crash_client.Pointer());
328-
#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_ANDROID)
329-
crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
330-
#elif defined(OS_LINUX)
331325
// Reporting for sub-processes will be initialized in ZygoteForked.
332-
if (process_type != service_manager::switches::kZygoteProcess)
333-
breakpad::InitCrashReporter(process_type);
334-
#endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_ANDROID)
326+
if (process_type != service_manager::switches::kZygoteProcess) {
327+
crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
328+
#if defined(OS_LINUX)
329+
crash_reporter::SetFirstChanceExceptionHandler(
330+
v8::TryHandleWebAssemblyTrapPosix);
331+
#endif
332+
}
335333
}
336334
#endif // !defined(OS_FUCHSIA)
337335

@@ -392,7 +390,9 @@ void ShellMainDelegate::ZygoteForked() {
392390
std::string process_type =
393391
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
394392
switches::kProcessType);
395-
breakpad::InitCrashReporter(process_type);
393+
crash_reporter::InitializeCrashpad(false, process_type);
394+
crash_reporter::SetFirstChanceExceptionHandler(
395+
v8::TryHandleWebAssemblyTrapPosix);
396396
}
397397
}
398398
#endif // defined(OS_LINUX)

content/shell/browser/shell_content_browser_client.cc

+20-47
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "base/no_destructor.h"
1717
#include "base/path_service.h"
1818
#include "base/stl_util.h"
19+
#include "base/strings/string_number_conversions.h"
1920
#include "base/strings/utf_string_conversions.h"
2021
#include "base/threading/sequence_local_storage_slot.h"
2122
#include "build/build_config.h"
@@ -63,17 +64,20 @@
6364
#if defined(OS_ANDROID)
6465
#include "base/android/apk_assets.h"
6566
#include "base/android/path_utils.h"
66-
#include "components/crash/content/app/crashpad.h"
6767
#include "content/shell/android/shell_descriptors.h"
6868
#endif
6969

7070
#if defined(OS_CHROMEOS)
7171
#include "content/public/browser/context_factory.h"
7272
#endif
7373

74-
#if defined(OS_LINUX) || defined(OS_ANDROID)
75-
#include "base/debug/leak_annotations.h"
74+
#if defined(OS_ANDROID)
7675
#include "components/crash/content/browser/crash_handler_host_linux.h"
76+
#endif
77+
78+
#if defined(OS_LINUX) || defined(OS_ANDROID)
79+
#include "components/crash/content/app/crash_switches.h"
80+
#include "components/crash/content/app/crashpad.h"
7781
#include "content/public/common/content_descriptors.h"
7882
#endif
7983

@@ -97,52 +101,12 @@ int GetCrashSignalFD(const base::CommandLine& command_line) {
97101
return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
98102
}
99103
#elif defined(OS_LINUX)
100-
breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
101-
const std::string& process_type) {
102-
base::FilePath dumps_path =
103-
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
104-
switches::kCrashDumpsDir);
105-
{
106-
ANNOTATE_SCOPED_MEMORY_LEAK;
107-
breakpad::CrashHandlerHostLinux* crash_handler =
108-
new breakpad::CrashHandlerHostLinux(
109-
process_type, dumps_path, false);
110-
crash_handler->StartUploaderThread();
111-
return crash_handler;
112-
}
113-
}
114-
115104
int GetCrashSignalFD(const base::CommandLine& command_line) {
116-
if (!breakpad::IsCrashReporterEnabled())
117-
return -1;
118-
119-
std::string process_type =
120-
command_line.GetSwitchValueASCII(switches::kProcessType);
121-
122-
if (process_type == switches::kRendererProcess) {
123-
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
124-
if (!crash_handler)
125-
crash_handler = CreateCrashHandlerHost(process_type);
126-
return crash_handler->GetDeathSignalSocket();
127-
}
128-
129-
if (process_type == switches::kPpapiPluginProcess) {
130-
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
131-
if (!crash_handler)
132-
crash_handler = CreateCrashHandlerHost(process_type);
133-
return crash_handler->GetDeathSignalSocket();
134-
}
135-
136-
if (process_type == switches::kGpuProcess) {
137-
static breakpad::CrashHandlerHostLinux* crash_handler = nullptr;
138-
if (!crash_handler)
139-
crash_handler = CreateCrashHandlerHost(process_type);
140-
return crash_handler->GetDeathSignalSocket();
141-
}
142-
143-
return -1;
105+
int fd;
106+
pid_t pid;
107+
return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1;
144108
}
145-
#endif // defined(OS_ANDROID)
109+
#endif
146110

147111
const service_manager::Manifest& GetContentBrowserOverlayManifest() {
148112
static base::NoDestructor<service_manager::Manifest> manifest{
@@ -255,6 +219,15 @@ void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
255219
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
256220
switches::kEnableCrashReporter)) {
257221
command_line->AppendSwitch(switches::kEnableCrashReporter);
222+
#if defined(OS_LINUX)
223+
int fd;
224+
pid_t pid;
225+
if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
226+
command_line->AppendSwitchASCII(
227+
crash_reporter::switches::kCrashpadHandlerPid,
228+
base::NumberToString(pid));
229+
}
230+
#endif // OS_LINUX
258231
}
259232
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
260233
switches::kCrashDumpsDir)) {

content/shell/tools/breakpad_integration_test.py

+5-16
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ def run_test(options, crash_dir, symbols_dir, platform,
148148

149149
print '# Retrieve crash dump.'
150150
if platform == 'android':
151-
dmp_file = get_android_dump(crash_dir)
151+
minidump = get_android_dump(crash_dir)
152152
else:
153153
dmp_dir = crash_dir
154154
# TODO(crbug.com/782923): This test should not reach directly into the
155155
# Crashpad database, but instead should use crashpad_database_util.
156-
if platform == 'darwin':
156+
if platform == 'darwin' or platform == 'linux2':
157157
dmp_dir = os.path.join(dmp_dir, 'pending')
158158
elif platform == 'win32':
159159
dmp_dir = os.path.join(dmp_dir, 'reports')
@@ -162,24 +162,13 @@ def run_test(options, crash_dir, symbols_dir, platform,
162162
failure = 'Expected 1 crash dump, found %d.' % len(dmp_files)
163163
if len(dmp_files) != 1:
164164
raise Exception(failure)
165-
dmp_file = dmp_files[0]
166-
167-
if platform not in ('darwin', 'win32', 'android'):
168-
minidump = os.path.join(crash_dir, 'minidump')
169-
dmp_to_minidump = os.path.join(BREAKPAD_TOOLS_DIR, 'dmp2minidump.py')
170-
cmd = [dmp_to_minidump, dmp_file, minidump]
171-
if options.verbose:
172-
print ' '.join(cmd)
173-
failure = 'Failed to run dmp_to_minidump.'
174-
subprocess.check_call(cmd)
175-
else:
176-
minidump = dmp_file
165+
minidump = dmp_files[0]
177166

178167
print '# Symbolize crash dump.'
179168
if platform == 'win32':
180169
cdb_exe = os.path.join(options.build_dir, 'cdb', 'cdb.exe')
181170
cmd = [cdb_exe, '-y', options.build_dir, '-c', '.lines;.excr;k30;q',
182-
'-z', dmp_file]
171+
'-z', minidump]
183172
if options.verbose:
184173
print ' '.join(cmd)
185174
failure = 'Failed to run cdb.exe.'
@@ -199,7 +188,7 @@ def run_test(options, crash_dir, symbols_dir, platform,
199188
# Check whether the stack contains a CrashIntentionally symbol.
200189
found_symbol = 'CrashIntentionally' in stack
201190

202-
os.remove(dmp_file)
191+
os.remove(minidump)
203192

204193
if options.no_symbols:
205194
if found_symbol:

docs/testing/using_crashpad_with_content_shell.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ building. This slows down linking several minutes, so don't just always set it
1616
by default.
1717
***
1818

19-
*** note
20-
**Linux:** Add `use_debug_fission = true` to your [gn build
21-
arguments](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) before
22-
building.
23-
***
24-
2519
Then, create a directory where the crash dumps will be stored:
2620

2721
* Linux/Mac:
@@ -67,13 +61,9 @@ Crashpad can be enabled by passing `--enable-crash-reporter` and
6761

6862
## Retrieving the crash dump
6963

70-
On Linux and Android, we first have to retrieve the crash dump. On Mac and
71-
Windows, this step can be skipped.
64+
On Android, we first have to retrieve the crash dump. On other platforms, this
65+
step can be skipped.
7266

73-
* Linux:
74-
```bash
75-
components/crash/content/tools/dmp2minidump.py /tmp/crashes/*.dmp /tmp/minidump
76-
```
7767
* Android:
7868
```bash
7969
adb pull $(adb shell ls /data/data/org.chromium.content_shell_apk/cache/pending/*.dmp) /tmp/chromium-renderer-minidump.dmp

0 commit comments

Comments
 (0)