2020-02-18 14:49:10 -05:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
|
|
|
#include "client/crashpad_client.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
#include "client/client_argv_handling.h"
|
2020-03-04 15:19:46 -05:00
|
|
|
#include "snapshot/ios/process_snapshot_ios.h"
|
2020-03-25 16:12:22 -04:00
|
|
|
#include "util/ios/ios_system_data_collector.h"
|
2020-02-18 14:49:10 -05:00
|
|
|
#include "util/posix/signals.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// A base class for Crashpad signal handler implementations.
|
|
|
|
class SignalHandler {
|
|
|
|
public:
|
|
|
|
// Returns the currently installed signal hander.
|
|
|
|
static SignalHandler* Get() {
|
|
|
|
static SignalHandler* instance = new SignalHandler();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Install(const std::set<int>* unhandled_signals) {
|
|
|
|
return Signals::InstallCrashHandlers(
|
|
|
|
HandleSignal, 0, &old_actions_, unhandled_signals);
|
|
|
|
}
|
|
|
|
|
2020-03-04 15:19:46 -05:00
|
|
|
void HandleCrash(int signo, siginfo_t* siginfo, void* context) {
|
|
|
|
// TODO(justincohen): This is incomplete.
|
|
|
|
ProcessSnapshotIOS process_snapshot;
|
2020-03-25 16:12:22 -04:00
|
|
|
process_snapshot.Initialize(system_data);
|
2020-03-25 16:13:42 -04:00
|
|
|
process_snapshot.SetException(siginfo,
|
|
|
|
reinterpret_cast<ucontext_t*>(context));
|
2020-03-04 15:19:46 -05:00
|
|
|
}
|
|
|
|
|
2020-02-18 14:49:10 -05:00
|
|
|
private:
|
|
|
|
SignalHandler() = default;
|
|
|
|
|
|
|
|
// The base implementation for all signal handlers, suitable for calling
|
|
|
|
// directly to simulate signal delivery.
|
2020-03-04 15:19:46 -05:00
|
|
|
void HandleCrashAndReraiseSignal(int signo,
|
|
|
|
siginfo_t* siginfo,
|
|
|
|
void* context) {
|
|
|
|
HandleCrash(signo, siginfo, context);
|
2020-02-18 14:49:10 -05:00
|
|
|
|
|
|
|
// Always call system handler.
|
|
|
|
Signals::RestoreHandlerAndReraiseSignalOnReturn(
|
|
|
|
siginfo, old_actions_.ActionForSignal(signo));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The signal handler installed at OS-level.
|
|
|
|
static void HandleSignal(int signo, siginfo_t* siginfo, void* context) {
|
2020-03-04 15:19:46 -05:00
|
|
|
Get()->HandleCrashAndReraiseSignal(signo, siginfo, context);
|
2020-02-18 14:49:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Signals::OldActions old_actions_ = {};
|
|
|
|
|
2020-03-25 16:12:22 -04:00
|
|
|
// Collect some system data before the signal handler is triggered.
|
|
|
|
IOSSystemDataCollector system_data;
|
|
|
|
|
2020-02-18 14:49:10 -05:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(SignalHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CrashpadClient::CrashpadClient() {}
|
|
|
|
|
|
|
|
CrashpadClient::~CrashpadClient() {}
|
|
|
|
|
|
|
|
bool CrashpadClient::StartCrashpadInProcessHandler() {
|
|
|
|
return SignalHandler::Get()->Install(nullptr);
|
|
|
|
}
|
|
|
|
|
2020-03-04 15:19:46 -05:00
|
|
|
// static
|
|
|
|
void CrashpadClient::DumpWithoutCrash() {
|
|
|
|
DCHECK(SignalHandler::Get());
|
|
|
|
siginfo_t siginfo = {};
|
|
|
|
SignalHandler::Get()->HandleCrash(siginfo.si_signo, &siginfo, nullptr);
|
|
|
|
}
|
2020-02-18 14:49:10 -05:00
|
|
|
} // namespace crashpad
|