Commit f7f0b873 authored by Kimiyuki Onaka's avatar Kimiyuki Onaka Committed by Commit Bot

Add DumpNativeCrash interface

ArcCrashCollector calls DumpNativeCrash with file names and FDs when a
new crash dump appears. DumpNativeCrash is responsible to call
crash_reporter. FDs are used for passing the file contents.

BUG=b:136697350
TEST=tast run my_crbook arc.NativeCrash.\* arc.AppCrash.\*

Change-Id: I5017d388eb3182454023b354c3714bbecc664354
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379331
Commit-Queue: Kimiyuki Onaka <kimiyuki@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Reviewed-by: default avatarMiriam Zimmerman <mutexlox@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810839}
parent ece08cd7
......@@ -4,6 +4,7 @@
#include "components/arc/crash_collector/arc_crash_collector_bridge.h"
#include <inttypes.h>
#include <sysexits.h>
#include <unistd.h>
......@@ -14,10 +15,12 @@
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/process/launch.h"
#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/arc_util.h"
#include "components/arc/session/arc_bridge_service.h"
#include "mojo/public/cpp/system/platform_handle.h"
......@@ -25,32 +28,47 @@ namespace {
const char kCrashReporterPath[] = "/sbin/crash_reporter";
// Runs crash_reporter to save the crash info provided via the pipe.
void RunCrashReporter(const std::string& crash_type,
const std::string& device,
const std::string& board,
const std::string& cpu_abi,
const base::Optional<std::string>& fingerprint,
base::ScopedFD pipe) {
bool RunCrashReporter(const std::vector<std::string>& args, int stdin_fd) {
base::LaunchOptions options;
options.fds_to_remap.emplace_back(pipe.get(), STDIN_FILENO);
options.fds_to_remap.emplace_back(stdin_fd, STDIN_FILENO);
std::vector<std::string> argv = {
kCrashReporterPath, "--arc_java_crash=" + crash_type,
"--arc_device=" + device, "--arc_board=" + board,
"--arc_cpu_abi=" + cpu_abi};
if (fingerprint)
argv.emplace_back("--arc_fingerprint=" + fingerprint.value());
auto process = base::LaunchProcess(argv, options);
auto process = base::LaunchProcess(args, options);
int exit_code = 0;
if (!process.WaitForExit(&exit_code)) {
LOG(ERROR) << "Failed to wait for " << kCrashReporterPath;
} else if (exit_code != EX_OK) {
return false;
}
if (exit_code != EX_OK) {
LOG(ERROR) << kCrashReporterPath << " failed with exit code " << exit_code;
return false;
}
return true;
}
// Runs crash_reporter to save the java crash info provided via the pipe.
void RunJavaCrashReporter(const std::string& crash_type,
base::ScopedFD pipe,
std::vector<std::string> args) {
args.push_back("--arc_java_crash=" + crash_type);
if (!RunCrashReporter(args, pipe.get()))
LOG(ERROR) << "Failed to run crash_reporter";
}
// Runs crash_reporter to save the native crash info provided via the files.
void RunNativeCrashReporter(const std::string& exec_name,
int32_t pid,
int64_t timestamp,
base::ScopedFD minidump_fd,
std::vector<std::string> args) {
args.insert(args.end(),
{"--exe=" + exec_name, base::StringPrintf("--pid=%d", pid),
base::StringPrintf("--arc_native_time=%" PRId64, timestamp),
"--arc_native"});
if (!RunCrashReporter(args, minidump_fd.get()))
LOG(ERROR) << "Failed to run crash_reporter";
}
} // namespace
......@@ -100,9 +118,21 @@ void ArcCrashCollectorBridge::DumpCrash(const std::string& type,
mojo::ScopedHandle pipe) {
base::ThreadPool::PostTask(
FROM_HERE, {base::WithBaseSyncPrimitives()},
base::BindOnce(&RunCrashReporter, type, device_, board_, cpu_abi_,
fingerprint_,
mojo::UnwrapPlatformHandle(std::move(pipe)).TakeFD()));
base::BindOnce(&RunJavaCrashReporter, type,
mojo::UnwrapPlatformHandle(std::move(pipe)).TakeFD(),
CreateCrashReporterArgs()));
}
void ArcCrashCollectorBridge::DumpNativeCrash(const std::string& exec_name,
int32_t pid,
int64_t timestamp,
mojo::ScopedHandle minidump_fd) {
base::ThreadPool::PostTask(
FROM_HERE, {base::WithBaseSyncPrimitives()},
base::BindOnce(
&RunNativeCrashReporter, exec_name, pid, timestamp,
mojo::UnwrapPlatformHandle(std::move(minidump_fd)).TakeFD(),
CreateCrashReporterArgs()));
}
void ArcCrashCollectorBridge::SetBuildProperties(
......@@ -116,4 +146,20 @@ void ArcCrashCollectorBridge::SetBuildProperties(
fingerprint_ = fingerprint;
}
std::vector<std::string> ArcCrashCollectorBridge::CreateCrashReporterArgs() {
std::vector<std::string> args = {
kCrashReporterPath,
"--arc_device=" + device_,
"--arc_board=" + board_,
"--arc_cpu_abi=" + cpu_abi_,
};
if (fingerprint_)
args.push_back("--arc_fingerprint=" + fingerprint_.value());
if (arc::IsArcVmEnabled())
args.emplace_back("--arc_is_arcvm");
return args;
}
} // namespace arc
......@@ -32,11 +32,17 @@ class ArcCrashCollectorBridge
ArcCrashCollectorBridge(content::BrowserContext* context,
ArcBridgeService* bridge);
ArcCrashCollectorBridge(const ArcCrashCollectorBridge&) = delete;
ArcCrashCollectorBridge& operator=(const ArcCrashCollectorBridge&) = delete;
~ArcCrashCollectorBridge() override;
// mojom::CrashCollectorHost overrides.
void DumpCrash(const std::string& type, mojo::ScopedHandle pipe) override;
void DumpNativeCrash(const std::string& exec_name,
int32_t pid,
int64_t timestamp,
mojo::ScopedHandle minidump_fd) override;
void SetBuildProperties(
const std::string& device,
const std::string& board,
......@@ -44,14 +50,14 @@ class ArcCrashCollectorBridge
const base::Optional<std::string>& fingerprint) override;
private:
std::vector<std::string> CreateCrashReporterArgs();
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
std::string device_;
std::string board_;
std::string cpu_abi_;
base::Optional<std::string> fingerprint_;
DISALLOW_COPY_AND_ASSIGN(ArcCrashCollectorBridge);
};
} // namespace arc
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next MinVersion: 4
// Next MinVersion: 5
module arc.mojom;
// Next Method ID: 2
// Next Method ID: 3
interface CrashCollectorHost {
// Sends a dump for a non-native crash of the given |type|. The host reads
// the dump from |pipe|, or rejects the dump by closing |pipe|. Note that
......@@ -19,6 +19,12 @@ interface CrashCollectorHost {
string board,
string cpu_abi,
[MinVersion=3] string? fingerprint);
// Sends a dump for a native crash.
[MinVersion=4] DumpNativeCrash@2(string exec_name,
int32 pid,
int64 timestamp,
handle minidump_fd);
};
// Next Method ID: 2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment