2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-17 14:00:58 -04:00
|
|
|
|
//
|
|
|
|
|
// 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_SNAPSHOT_MAC_PROCESS_SNAPSHOT_MAC_H_
|
|
|
|
|
#define CRASHPAD_SNAPSHOT_MAC_PROCESS_SNAPSHOT_MAC_H_
|
|
|
|
|
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2015-02-17 17:38:02 -05:00
|
|
|
|
#include <map>
|
2016-04-25 12:13:07 -07:00
|
|
|
|
#include <memory>
|
2015-02-17 17:38:02 -05:00
|
|
|
|
#include <string>
|
2014-10-17 14:00:58 -04:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
2015-03-11 17:07:11 -04:00
|
|
|
|
#include "client/crashpad_info.h"
|
2015-05-01 13:48:23 -07:00
|
|
|
|
#include "snapshot/crashpad_info_client_options.h"
|
2014-10-17 14:00:58 -04:00
|
|
|
|
#include "snapshot/exception_snapshot.h"
|
|
|
|
|
#include "snapshot/mac/exception_snapshot_mac.h"
|
|
|
|
|
#include "snapshot/mac/module_snapshot_mac.h"
|
2018-02-22 12:12:26 -08:00
|
|
|
|
#include "snapshot/mac/process_reader_mac.h"
|
2014-10-17 14:00:58 -04:00
|
|
|
|
#include "snapshot/mac/system_snapshot_mac.h"
|
|
|
|
|
#include "snapshot/mac/thread_snapshot_mac.h"
|
2015-10-13 12:37:44 -07:00
|
|
|
|
#include "snapshot/memory_map_region_snapshot.h"
|
2014-10-17 14:00:58 -04:00
|
|
|
|
#include "snapshot/module_snapshot.h"
|
|
|
|
|
#include "snapshot/process_snapshot.h"
|
|
|
|
|
#include "snapshot/system_snapshot.h"
|
|
|
|
|
#include "snapshot/thread_snapshot.h"
|
2016-02-11 17:19:30 -08:00
|
|
|
|
#include "snapshot/unloaded_module_snapshot.h"
|
2015-04-02 15:28:28 -04:00
|
|
|
|
#include "util/mach/mach_extensions.h"
|
2014-10-17 14:00:58 -04:00
|
|
|
|
#include "util/misc/initialization_state_dcheck.h"
|
2015-03-11 17:10:50 -04:00
|
|
|
|
#include "util/misc/uuid.h"
|
2014-10-17 14:00:58 -04:00
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
2016-11-07 09:01:20 -05:00
|
|
|
|
//! \brief A ProcessSnapshot of a running (or crashed) process running on a
|
|
|
|
|
//! macOS system.
|
2014-10-17 14:00:58 -04:00
|
|
|
|
class ProcessSnapshotMac final : public ProcessSnapshot {
|
|
|
|
|
public:
|
|
|
|
|
ProcessSnapshotMac();
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
|
|
ProcessSnapshotMac(const ProcessSnapshotMac&) = delete;
|
|
|
|
|
ProcessSnapshotMac& operator=(const ProcessSnapshotMac&) = delete;
|
|
|
|
|
|
2014-10-29 17:31:23 -04:00
|
|
|
|
~ProcessSnapshotMac() override;
|
2014-10-17 14:00:58 -04:00
|
|
|
|
|
|
|
|
|
//! \brief Initializes the object.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] task The task to create a snapshot from.
|
|
|
|
|
//!
|
|
|
|
|
//! \return `true` if the snapshot could be created, `false` otherwise with
|
|
|
|
|
//! an appropriate message logged.
|
|
|
|
|
bool Initialize(task_t task);
|
|
|
|
|
|
|
|
|
|
//! \brief Initializes the object’s exception.
|
|
|
|
|
//!
|
|
|
|
|
//! This populates the data to be returned by Exception(). The parameters may
|
|
|
|
|
//! be passed directly through from a Mach exception handler.
|
|
|
|
|
//!
|
|
|
|
|
//! This method must not be called until after a successful call to
|
|
|
|
|
//! Initialize().
|
|
|
|
|
//!
|
|
|
|
|
//! \return `true` if the exception information could be initialized, `false`
|
|
|
|
|
//! otherwise with an appropriate message logged. When this method returns
|
|
|
|
|
//! `false`, the ProcessSnapshotMac object’s validity remains unchanged.
|
2015-04-02 15:49:51 -04:00
|
|
|
|
bool InitializeException(exception_behavior_t behavior,
|
|
|
|
|
thread_t exception_thread,
|
2014-10-17 14:00:58 -04:00
|
|
|
|
exception_type_t exception,
|
|
|
|
|
const mach_exception_data_type_t* code,
|
|
|
|
|
mach_msg_type_number_t code_count,
|
|
|
|
|
thread_state_flavor_t flavor,
|
2015-04-02 15:28:28 -04:00
|
|
|
|
ConstThreadState state,
|
2014-10-17 14:00:58 -04:00
|
|
|
|
mach_msg_type_number_t state_count);
|
|
|
|
|
|
2015-03-13 13:00:56 -04:00
|
|
|
|
//! \brief Sets the value to be returned by ReportID().
|
|
|
|
|
//!
|
2016-11-07 09:01:20 -05:00
|
|
|
|
//! On macOS, the crash report ID is under the control of the snapshot
|
2015-03-13 13:00:56 -04:00
|
|
|
|
//! producer, which may call this method to set the report ID. If this is not
|
|
|
|
|
//! done, ReportID() will return an identifier consisting entirely of zeroes.
|
|
|
|
|
void SetReportID(const UUID& report_id) { report_id_ = report_id; }
|
|
|
|
|
|
2015-03-11 17:10:50 -04:00
|
|
|
|
//! \brief Sets the value to be returned by ClientID().
|
|
|
|
|
//!
|
2016-11-07 09:01:20 -05:00
|
|
|
|
//! On macOS, the client ID is under the control of the snapshot producer,
|
2015-03-11 17:10:50 -04:00
|
|
|
|
//! which may call this method to set the client ID. If this is not done,
|
|
|
|
|
//! ClientID() will return an identifier consisting entirely of zeroes.
|
|
|
|
|
void SetClientID(const UUID& client_id) { client_id_ = client_id; }
|
|
|
|
|
|
2015-02-17 17:38:02 -05:00
|
|
|
|
//! \brief Sets the value to be returned by AnnotationsSimpleMap().
|
|
|
|
|
//!
|
2016-11-07 09:01:20 -05:00
|
|
|
|
//! On macOS, all process annotations are under the control of the snapshot
|
2015-02-17 17:38:02 -05:00
|
|
|
|
//! producer, which may call this method to establish these annotations.
|
|
|
|
|
//! Contrast this with module annotations, which are under the control of the
|
|
|
|
|
//! process being snapshotted.
|
|
|
|
|
void SetAnnotationsSimpleMap(
|
|
|
|
|
const std::map<std::string, std::string>& annotations_simple_map) {
|
|
|
|
|
annotations_simple_map_ = annotations_simple_map;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 17:07:11 -04:00
|
|
|
|
//! \brief Returns options from CrashpadInfo structures found in modules in
|
|
|
|
|
//! the process.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[out] options Options set in CrashpadInfo structures in modules in
|
|
|
|
|
//! the process.
|
|
|
|
|
void GetCrashpadOptions(CrashpadInfoClientOptions* options);
|
|
|
|
|
|
2014-10-17 14:00:58 -04:00
|
|
|
|
// ProcessSnapshot:
|
|
|
|
|
|
|
|
|
|
pid_t ProcessID() const override;
|
|
|
|
|
pid_t ParentProcessID() const override;
|
|
|
|
|
void SnapshotTime(timeval* snapshot_time) const override;
|
|
|
|
|
void ProcessStartTime(timeval* start_time) const override;
|
|
|
|
|
void ProcessCPUTimes(timeval* user_time, timeval* system_time) const override;
|
2015-03-13 13:00:56 -04:00
|
|
|
|
void ReportID(UUID* report_id) const override;
|
2015-03-11 17:10:50 -04:00
|
|
|
|
void ClientID(UUID* client_id) const override;
|
2015-02-17 17:38:02 -05:00
|
|
|
|
const std::map<std::string, std::string>& AnnotationsSimpleMap()
|
|
|
|
|
const override;
|
2014-10-17 14:00:58 -04:00
|
|
|
|
const SystemSnapshot* System() const override;
|
|
|
|
|
std::vector<const ThreadSnapshot*> Threads() const override;
|
|
|
|
|
std::vector<const ModuleSnapshot*> Modules() const override;
|
2016-02-11 17:19:30 -08:00
|
|
|
|
std::vector<UnloadedModuleSnapshot> UnloadedModules() const override;
|
2014-10-17 14:00:58 -04:00
|
|
|
|
const ExceptionSnapshot* Exception() const override;
|
2015-10-13 12:37:44 -07:00
|
|
|
|
std::vector<const MemoryMapRegionSnapshot*> MemoryMap() const override;
|
2015-10-16 16:33:40 -07:00
|
|
|
|
std::vector<HandleSnapshot> Handles() const override;
|
2015-09-25 10:31:02 -07:00
|
|
|
|
std::vector<const MemorySnapshot*> ExtraMemory() const override;
|
2018-11-14 10:20:20 -08:00
|
|
|
|
const ProcessMemory* Memory() const override;
|
2014-10-17 14:00:58 -04:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Initializes threads_ on behalf of Initialize().
|
|
|
|
|
void InitializeThreads();
|
|
|
|
|
|
|
|
|
|
// Initializes modules_ on behalf of Initialize().
|
|
|
|
|
void InitializeModules();
|
|
|
|
|
|
|
|
|
|
internal::SystemSnapshotMac system_;
|
2017-10-19 00:26:38 -04:00
|
|
|
|
std::vector<std::unique_ptr<internal::ThreadSnapshotMac>> threads_;
|
|
|
|
|
std::vector<std::unique_ptr<internal::ModuleSnapshotMac>> modules_;
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<internal::ExceptionSnapshotMac> exception_;
|
2018-02-22 12:12:26 -08:00
|
|
|
|
ProcessReaderMac process_reader_;
|
2015-03-13 13:00:56 -04:00
|
|
|
|
UUID report_id_;
|
2015-03-11 17:10:50 -04:00
|
|
|
|
UUID client_id_;
|
2015-02-17 17:38:02 -05:00
|
|
|
|
std::map<std::string, std::string> annotations_simple_map_;
|
2014-10-17 14:00:58 -04:00
|
|
|
|
timeval snapshot_time_;
|
|
|
|
|
InitializationStateDcheck initialized_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
|
|
#endif // CRASHPAD_SNAPSHOT_MAC_PROCESS_SNAPSHOT_MAC_H_
|