From 2cb83e491e27c083fe8e6bdb92d49e8cc1e382a0 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Tue, 2 Feb 2021 09:02:28 -0500 Subject: [PATCH] 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 Reviewed-by: Mark Mentovai --- client/BUILD.gn | 2 +- client/crashpad_client.h | 10 +++++-- client/crashpad_client_ios.cc | 5 +++- client/crashpad_client_ios_test.mm | 14 ++++++--- client/simulate_crash.h | 4 ++- client/simulate_crash_ios.h | 31 ++++++++++++++++++++ test/ios/host/cptest_application_delegate.mm | 2 +- 7 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 client/simulate_crash_ios.h diff --git a/client/BUILD.gn b/client/BUILD.gn index 0546383b..e26b965a 100644 --- a/client/BUILD.gn +++ b/client/BUILD.gn @@ -47,6 +47,7 @@ crashpad_static_library("client") { sources += [ "crash_report_database_mac.mm", "crashpad_client_ios.cc", + "simulate_crash_ios.h", ] } @@ -90,7 +91,6 @@ crashpad_static_library("client") { deps = [ "../third_party/mini_chromium:chromeos_buildflags" ] - if (crashpad_is_win) { libs = [ "rpcrt4.lib" ] cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union diff --git a/client/crashpad_client.h b/client/crashpad_client.h index b1327a4e..8576427b 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -459,9 +459,13 @@ class CrashpadClient { //! //! This method is only defined on iOS. //! - //! TODO(justincohen): This method will need to take database, metrics_dir, - //! url and annotations eventually. - void StartCrashpadInProcessHandler(); + //! \param[in] database The path to a Crashpad database. + //! \param[in] url The URL of an upload server. + //! \param[in] annotations Process annotations to set in each crash report. + void StartCrashpadInProcessHandler( + const base::FilePath& database, + const std::string& url, + const std::map& annotations); // TODO(justincohen): This method is purely for bringing up iOS interfaces. //! \brief Requests that the handler capture a dump even though there hasn't diff --git a/client/crashpad_client_ios.cc b/client/crashpad_client_ios.cc index 342e1090..673475c3 100644 --- a/client/crashpad_client_ios.cc +++ b/client/crashpad_client_ios.cc @@ -210,7 +210,10 @@ CrashpadClient::CrashpadClient() {} CrashpadClient::~CrashpadClient() {} -void CrashpadClient::StartCrashpadInProcessHandler() { +void CrashpadClient::StartCrashpadInProcessHandler( + const base::FilePath& database, + const std::string& url, + const std::map& annotations) { InstallObjcExceptionPreprocessor(); CrashHandler* crash_handler = CrashHandler::Get(); diff --git a/client/crashpad_client_ios_test.mm b/client/crashpad_client_ios_test.mm index 91d84cbf..5bc3946a 100644 --- a/client/crashpad_client_ios_test.mm +++ b/client/crashpad_client_ios_test.mm @@ -19,6 +19,7 @@ #include #include "gtest/gtest.h" +#include "test/scoped_temp_dir.h" #include "testing/platform_test.h" namespace crashpad { @@ -29,8 +30,9 @@ using CrashpadIOSClient = PlatformTest; TEST_F(CrashpadIOSClient, DumpWithoutCrash) { CrashpadClient client; - client.StartCrashpadInProcessHandler(); - + ScopedTempDir database_dir; + client.StartCrashpadInProcessHandler( + base::FilePath(database_dir.path()), "", {}); NativeCPUContext context; CaptureContext(&context); client.DumpWithoutCrash(&context); @@ -42,7 +44,9 @@ TEST_F(CrashpadIOSClient, DumpWithoutCrash) { // during development only. TEST_F(CrashpadIOSClient, DISABLED_ThrowNSException) { CrashpadClient client; - client.StartCrashpadInProcessHandler(); + ScopedTempDir database_dir; + client.StartCrashpadInProcessHandler( + base::FilePath(database_dir.path()), "", {}); [NSException raise:@"GoogleTestNSException" format:@"ThrowException"]; } @@ -52,7 +56,9 @@ TEST_F(CrashpadIOSClient, DISABLED_ThrowNSException) { // during development only. TEST_F(CrashpadIOSClient, DISABLED_ThrowException) { CrashpadClient client; - client.StartCrashpadInProcessHandler(); + ScopedTempDir database_dir; + client.StartCrashpadInProcessHandler( + base::FilePath(database_dir.path()), "", {}); std::vector empty_vector; empty_vector.at(42); } diff --git a/client/simulate_crash.h b/client/simulate_crash.h index 18af98f3..d01e1682 100644 --- a/client/simulate_crash.h +++ b/client/simulate_crash.h @@ -17,8 +17,10 @@ #include "build/build_config.h" -#if defined(OS_APPLE) +#if defined(OS_MAC) #include "client/simulate_crash_mac.h" +#elif defined(OS_IOS) +#include "client/simulate_crash_ios.h" #elif defined(OS_WIN) #include "client/simulate_crash_win.h" #elif defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) diff --git a/client/simulate_crash_ios.h b/client/simulate_crash_ios.h new file mode 100644 index 00000000..3cd1a69a --- /dev/null +++ b/client/simulate_crash_ios.h @@ -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_ diff --git a/test/ios/host/cptest_application_delegate.mm b/test/ios/host/cptest_application_delegate.mm index 80baf8b3..a9adea74 100644 --- a/test/ios/host/cptest_application_delegate.mm +++ b/test/ios/host/cptest_application_delegate.mm @@ -40,7 +40,7 @@ didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { // Start up crashpad. crashpad::CrashpadClient client; - client.StartCrashpadInProcessHandler(); + client.StartCrashpadInProcessHandler(base::FilePath(), "", {}); self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.window makeKeyAndVisible];