ios: Cleanup API for chromium integration.

Bug: crashpad: 31
Change-Id: I9149879b2f6886ea17ca828dd60d37eb187ba88e
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2665887
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Justin Cohen 2021-02-02 09:02:28 -05:00 committed by Commit Bot
parent ee563696c3
commit 2cb83e491e
7 changed files with 57 additions and 11 deletions

View File

@ -47,6 +47,7 @@ crashpad_static_library("client") {
sources += [ sources += [
"crash_report_database_mac.mm", "crash_report_database_mac.mm",
"crashpad_client_ios.cc", "crashpad_client_ios.cc",
"simulate_crash_ios.h",
] ]
} }
@ -90,7 +91,6 @@ crashpad_static_library("client") {
deps = [ "../third_party/mini_chromium:chromeos_buildflags" ] deps = [ "../third_party/mini_chromium:chromeos_buildflags" ]
if (crashpad_is_win) { if (crashpad_is_win) {
libs = [ "rpcrt4.lib" ] libs = [ "rpcrt4.lib" ]
cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union

View File

@ -459,9 +459,13 @@ class CrashpadClient {
//! //!
//! This method is only defined on iOS. //! This method is only defined on iOS.
//! //!
//! TODO(justincohen): This method will need to take database, metrics_dir, //! \param[in] database The path to a Crashpad database.
//! url and annotations eventually. //! \param[in] url The URL of an upload server.
void StartCrashpadInProcessHandler(); //! \param[in] annotations Process annotations to set in each crash report.
void StartCrashpadInProcessHandler(
const base::FilePath& database,
const std::string& url,
const std::map<std::string, std::string>& annotations);
// TODO(justincohen): This method is purely for bringing up iOS interfaces. // TODO(justincohen): This method is purely for bringing up iOS interfaces.
//! \brief Requests that the handler capture a dump even though there hasn't //! \brief Requests that the handler capture a dump even though there hasn't

View File

@ -210,7 +210,10 @@ CrashpadClient::CrashpadClient() {}
CrashpadClient::~CrashpadClient() {} CrashpadClient::~CrashpadClient() {}
void CrashpadClient::StartCrashpadInProcessHandler() { void CrashpadClient::StartCrashpadInProcessHandler(
const base::FilePath& database,
const std::string& url,
const std::map<std::string, std::string>& annotations) {
InstallObjcExceptionPreprocessor(); InstallObjcExceptionPreprocessor();
CrashHandler* crash_handler = CrashHandler::Get(); CrashHandler* crash_handler = CrashHandler::Get();

View File

@ -19,6 +19,7 @@
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "test/scoped_temp_dir.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
namespace crashpad { namespace crashpad {
@ -29,8 +30,9 @@ using CrashpadIOSClient = PlatformTest;
TEST_F(CrashpadIOSClient, DumpWithoutCrash) { TEST_F(CrashpadIOSClient, DumpWithoutCrash) {
CrashpadClient client; CrashpadClient client;
client.StartCrashpadInProcessHandler(); ScopedTempDir database_dir;
client.StartCrashpadInProcessHandler(
base::FilePath(database_dir.path()), "", {});
NativeCPUContext context; NativeCPUContext context;
CaptureContext(&context); CaptureContext(&context);
client.DumpWithoutCrash(&context); client.DumpWithoutCrash(&context);
@ -42,7 +44,9 @@ TEST_F(CrashpadIOSClient, DumpWithoutCrash) {
// during development only. // during development only.
TEST_F(CrashpadIOSClient, DISABLED_ThrowNSException) { TEST_F(CrashpadIOSClient, DISABLED_ThrowNSException) {
CrashpadClient client; CrashpadClient client;
client.StartCrashpadInProcessHandler(); ScopedTempDir database_dir;
client.StartCrashpadInProcessHandler(
base::FilePath(database_dir.path()), "", {});
[NSException raise:@"GoogleTestNSException" format:@"ThrowException"]; [NSException raise:@"GoogleTestNSException" format:@"ThrowException"];
} }
@ -52,7 +56,9 @@ TEST_F(CrashpadIOSClient, DISABLED_ThrowNSException) {
// during development only. // during development only.
TEST_F(CrashpadIOSClient, DISABLED_ThrowException) { TEST_F(CrashpadIOSClient, DISABLED_ThrowException) {
CrashpadClient client; CrashpadClient client;
client.StartCrashpadInProcessHandler(); ScopedTempDir database_dir;
client.StartCrashpadInProcessHandler(
base::FilePath(database_dir.path()), "", {});
std::vector<int> empty_vector; std::vector<int> empty_vector;
empty_vector.at(42); empty_vector.at(42);
} }

View File

@ -17,8 +17,10 @@
#include "build/build_config.h" #include "build/build_config.h"
#if defined(OS_APPLE) #if defined(OS_MAC)
#include "client/simulate_crash_mac.h" #include "client/simulate_crash_mac.h"
#elif defined(OS_IOS)
#include "client/simulate_crash_ios.h"
#elif defined(OS_WIN) #elif defined(OS_WIN)
#include "client/simulate_crash_win.h" #include "client/simulate_crash_win.h"
#elif defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) #elif defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)

View File

@ -0,0 +1,31 @@
// Copyright 2021 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CRASHPAD_CLIENT_SIMULATE_CRASH_IOS_H_
#define CRASHPAD_CLIENT_SIMULATE_CRASH_IOS_H_
#include "client/crashpad_client.h"
#include "util/misc/capture_context.h"
//! \file
//! \brief Captures the CPU context and captures a dump without an exception.
#define CRASHPAD_SIMULATE_CRASH() \
do { \
crashpad::NativeCPUContext cpu_context; \
crashpad::CaptureContext(&cpu_context); \
crashpad::CrashpadClient::DumpWithoutCrash(&cpu_context); \
} while (false)
#endif // CRASHPAD_CLIENT_SIMULATE_CRASH_IOS_H_

View File

@ -40,7 +40,7 @@
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Start up crashpad. // Start up crashpad.
crashpad::CrashpadClient client; crashpad::CrashpadClient client;
client.StartCrashpadInProcessHandler(); client.StartCrashpadInProcessHandler(base::FilePath(), "", {});
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];