mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-26 23:01:05 +08:00
Add ModuleSnapshotMac.
R=rsesek@chromium.org Review URL: https://codereview.chromium.org/649633004
This commit is contained in:
parent
b43f510a52
commit
6584361343
152
snapshot/mac/module_snapshot_mac.cc
Normal file
152
snapshot/mac/module_snapshot_mac.cc
Normal file
@ -0,0 +1,152 @@
|
||||
// Copyright 2014 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 "snapshot/mac/module_snapshot_mac.h"
|
||||
|
||||
#include <mach/mach.h>
|
||||
#include <mach-o/loader.h>
|
||||
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "snapshot/mac/mach_o_image_annotations_reader.h"
|
||||
#include "snapshot/mac/mach_o_image_reader.h"
|
||||
#include "util/misc/uuid.h"
|
||||
#include "util/stdlib/strnlen.h"
|
||||
|
||||
namespace crashpad {
|
||||
namespace internal {
|
||||
|
||||
ModuleSnapshotMac::ModuleSnapshotMac()
|
||||
: ModuleSnapshot(),
|
||||
name_(),
|
||||
timestamp_(0),
|
||||
mach_o_image_reader_(nullptr),
|
||||
process_reader_(nullptr),
|
||||
initialized_() {
|
||||
}
|
||||
|
||||
ModuleSnapshotMac::~ModuleSnapshotMac() {
|
||||
}
|
||||
|
||||
bool ModuleSnapshotMac::Initialize(
|
||||
ProcessReader* process_reader,
|
||||
const ProcessReader::Module& process_reader_module) {
|
||||
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
||||
|
||||
process_reader_ = process_reader;
|
||||
name_ = process_reader_module.name;
|
||||
timestamp_ = process_reader_module.timestamp;
|
||||
mach_o_image_reader_ = process_reader_module.reader;
|
||||
if (!mach_o_image_reader_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
INITIALIZATION_STATE_SET_VALID(initialized_);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string ModuleSnapshotMac::Name() const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
return name_;
|
||||
}
|
||||
|
||||
uint64_t ModuleSnapshotMac::Address() const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
return mach_o_image_reader_->Address();
|
||||
}
|
||||
|
||||
uint64_t ModuleSnapshotMac::Size() const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
return mach_o_image_reader_->Size();
|
||||
}
|
||||
|
||||
time_t ModuleSnapshotMac::Timestamp() const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
return timestamp_;
|
||||
}
|
||||
|
||||
void ModuleSnapshotMac::FileVersion(uint16_t* version_0,
|
||||
uint16_t* version_1,
|
||||
uint16_t* version_2,
|
||||
uint16_t* version_3) const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
if (mach_o_image_reader_->FileType() == MH_DYLIB) {
|
||||
uint32_t dylib_version = mach_o_image_reader_->DylibVersion();
|
||||
*version_0 = (dylib_version & 0xffff0000) >> 16;
|
||||
*version_1 = (dylib_version & 0x0000ff00) >> 8;
|
||||
*version_2 = (dylib_version & 0x000000ff);
|
||||
*version_3 = 0;
|
||||
} else {
|
||||
*version_0 = 0;
|
||||
*version_1 = 0;
|
||||
*version_2 = 0;
|
||||
*version_3 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleSnapshotMac::SourceVersion(uint16_t* version_0,
|
||||
uint16_t* version_1,
|
||||
uint16_t* version_2,
|
||||
uint16_t* version_3) const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
|
||||
// LC_SOURCE_VERSION is supposed to be interpreted as a 5-component version
|
||||
// number, 24 bits for the first component and 10 for the others, per
|
||||
// <mach-o/loader.h>. To preserve the full range of possible version numbers
|
||||
// without data loss, map it to the 4 16-bit fields mandated by the interface
|
||||
// here, which was informed by the minidump file format.
|
||||
uint64_t source_version = mach_o_image_reader_->SourceVersion();
|
||||
*version_0 = (source_version & 0xffff000000000000u) >> 48;
|
||||
*version_1 = (source_version & 0x0000ffff00000000u) >> 32;
|
||||
*version_2 = (source_version & 0x00000000ffff0000u) >> 16;
|
||||
*version_3 = source_version & 0x000000000000ffffu;
|
||||
}
|
||||
|
||||
ModuleSnapshot::ModuleType ModuleSnapshotMac::GetModuleType() const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
|
||||
uint32_t file_type = mach_o_image_reader_->FileType();
|
||||
switch (file_type) {
|
||||
case MH_EXECUTE:
|
||||
return kModuleTypeExecutable;
|
||||
case MH_DYLIB:
|
||||
return kModuleTypeSharedLibrary;
|
||||
case MH_DYLINKER:
|
||||
return kModuleTypeDynamicLoader;
|
||||
case MH_BUNDLE:
|
||||
return kModuleTypeLoadableModule;
|
||||
default:
|
||||
return kModuleTypeUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleSnapshotMac::UUID(crashpad::UUID* uuid) const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
return mach_o_image_reader_->UUID(uuid);
|
||||
}
|
||||
|
||||
std::vector<std::string> ModuleSnapshotMac::AnnotationsVector() const {
|
||||
MachOImageAnnotationsReader annotations_reader(
|
||||
process_reader_, mach_o_image_reader_, name_);
|
||||
return annotations_reader.Vector();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> ModuleSnapshotMac::AnnotationsSimpleMap()
|
||||
const {
|
||||
MachOImageAnnotationsReader annotations_reader(
|
||||
process_reader_, mach_o_image_reader_, name_);
|
||||
return annotations_reader.SimpleMap();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace crashpad
|
88
snapshot/mac/module_snapshot_mac.h
Normal file
88
snapshot/mac/module_snapshot_mac.h
Normal file
@ -0,0 +1,88 @@
|
||||
// Copyright 2014 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_SNAPSHOT_MAC_MODULE_SNAPSHOT_MAC_H_
|
||||
#define CRASHPAD_SNAPSHOT_MAC_MODULE_SNAPSHOT_MAC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "snapshot/mac/process_reader.h"
|
||||
#include "snapshot/module_snapshot.h"
|
||||
#include "util/misc/initialization_state_dcheck.h"
|
||||
|
||||
namespace crashpad {
|
||||
|
||||
class MachOImageReader;
|
||||
struct UUID;
|
||||
|
||||
namespace internal {
|
||||
|
||||
//! \brief A ModuleSnapshot of a code module (binary image) loaded into a
|
||||
//! running (or crashed) process on a Mac OS X system.
|
||||
class ModuleSnapshotMac final : public ModuleSnapshot {
|
||||
public:
|
||||
ModuleSnapshotMac();
|
||||
~ModuleSnapshotMac();
|
||||
|
||||
//! \brief Initializes the object.
|
||||
//!
|
||||
//! \param[in] process_reader A ProcessReader for the task containing the
|
||||
//! module.
|
||||
//! \param[in] process_reader_module The module within the ProcessReader for
|
||||
//! which the snapshot should be created.
|
||||
//!
|
||||
//! \return `true` if the snapshot could be created, `false` otherwise with
|
||||
//! an appropriate message logged.
|
||||
bool Initialize(ProcessReader* process_reader,
|
||||
const ProcessReader::Module& process_reader_module);
|
||||
|
||||
// ModuleSnapshot:
|
||||
|
||||
std::string Name() const override;
|
||||
uint64_t Address() const override;
|
||||
uint64_t Size() const override;
|
||||
time_t Timestamp() const override;
|
||||
void FileVersion(uint16_t* version_0,
|
||||
uint16_t* version_1,
|
||||
uint16_t* version_2,
|
||||
uint16_t* version_3) const override;
|
||||
void SourceVersion(uint16_t* version_0,
|
||||
uint16_t* version_1,
|
||||
uint16_t* version_2,
|
||||
uint16_t* version_3) const override;
|
||||
ModuleType GetModuleType() const override;
|
||||
void UUID(crashpad::UUID* uuid) const override;
|
||||
std::vector<std::string> AnnotationsVector() const override;
|
||||
std::map<std::string, std::string> AnnotationsSimpleMap() const override;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
time_t timestamp_;
|
||||
const MachOImageReader* mach_o_image_reader_; // weak
|
||||
ProcessReader* process_reader_; // weak
|
||||
InitializationStateDcheck initialized_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ModuleSnapshotMac);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace crashpad
|
||||
|
||||
#endif // CRASHPAD_SNAPSHOT_MAC_MODULE_SNAPSHOT_MAC_H_
|
@ -43,8 +43,8 @@ class ThreadSnapshotMac final : public ThreadSnapshot {
|
||||
//!
|
||||
//! \param[in] process_reader A ProcessReader for the task containing the
|
||||
//! thread.
|
||||
//! \param[in] process_reader_thread The thread within the ProcessReader that
|
||||
//! for which the snapshot should be created.
|
||||
//! \param[in] process_reader_thread The thread within the ProcessReader for
|
||||
//! which the snapshot should be created.
|
||||
//!
|
||||
//! \return `true` if the snapshot could be created, `false` otherwise with
|
||||
//! an appropriate message logged.
|
||||
|
@ -113,32 +113,38 @@ class ModuleSnapshot {
|
||||
//! module does not have a UUID, the \a uuid parameter will be zeroed out.
|
||||
virtual void UUID(crashpad::UUID* uuid) const = 0;
|
||||
|
||||
//! \brief Returns diagnostic messages recorded in the module.
|
||||
//! \brief Returns string annotations recorded in the module.
|
||||
//!
|
||||
//! This method retrieves diagnostic messages recorded in a module. These
|
||||
//! messages are intended for diagnostic use, including crash analysis. A
|
||||
//! module may contain multiple diagnostic messages.
|
||||
//! This method retrieves annotations recorded in a module. These annotations
|
||||
//! are intended for diagnostic use, including crash analysis. A module may
|
||||
//! contain multiple annotations, so they are returned in a vector.
|
||||
//!
|
||||
//! For Mac OS X snapshots, the diagnostic messages are found by interpreting
|
||||
//! the module’s `__DATA, __crash_info` section as
|
||||
//! `crashreporter_annotations_t`. System libraries using the crash reporter
|
||||
//! client interface may reference diagnostic messages in this structure.
|
||||
//! Additional diagnostic messages may be found in other locations, which may
|
||||
//! be module-specific. The dynamic linker (`dyld`) can provide a diagnostic
|
||||
//! message at its `_error_string` symbol.
|
||||
virtual std::vector<std::string> DiagnosticMessages() const = 0;
|
||||
//! For Mac OS X snapshots, these annotations are found by interpreting the
|
||||
//! module’s `__DATA, __crash_info` section as `crashreporter_annotations_t`.
|
||||
//! System libraries using the crash reporter client interface may reference
|
||||
//! annotations in this structure. Additional annotations messages may be
|
||||
//! found in other locations, which may be module-specific. The dynamic linker
|
||||
//! (`dyld`) can provide an annotation at its `_error_string` symbol.
|
||||
//!
|
||||
//! The annotations returned by this method do not duplicate those returned by
|
||||
//! AnnotationsSimpleMap().
|
||||
virtual std::vector<std::string> AnnotationsVector() const = 0;
|
||||
|
||||
//! \brief Returns simple annotations recorded in the module.
|
||||
//! \brief Returns key-value string annotations recorded in the module.
|
||||
//!
|
||||
//! This method retrieves simple annotations recorded in a module. These
|
||||
//! annotations are intended for diagnostic use, including crash analysis.
|
||||
//! Simple annotations are structured as a sequence of key-value pairs. These
|
||||
//! are referred to in Chrome as “crash keys.”
|
||||
//! This method retrieves annotations recorded in a module. These annotations
|
||||
//! are intended for diagnostic use, including crash analysis. “Simple
|
||||
//! annotations” are structured as a sequence of key-value pairs, where all
|
||||
//! keys and values are strings. These are referred to in Chrome as “crash
|
||||
//! keys.”
|
||||
//!
|
||||
//! For Mac OS X snapshots, simple annotations are found by interpreting
|
||||
//! the `__DATA, __crashpad_info` section as `CrashpadInfo`. Clients can use
|
||||
//! the Crashpad client interface to store annotations in this structure.
|
||||
virtual std::map<std::string, std::string> SimpleAnnotations() const = 0;
|
||||
//! For Mac OS X snapshots, these annotations are found by interpreting the
|
||||
//! `__DATA, __crashpad_info` section as `CrashpadInfo`. Clients can use the
|
||||
//! Crashpad client interface to store annotations in this structure.
|
||||
//!
|
||||
//! The annotations returned by this method do not duplicate those returned by
|
||||
//! AnnotationsVector().
|
||||
virtual std::map<std::string, std::string> AnnotationsSimpleMap() const = 0;
|
||||
|
||||
protected:
|
||||
~ModuleSnapshot() {}
|
||||
|
@ -45,6 +45,8 @@
|
||||
'mac/mach_o_image_symbol_table_reader.h',
|
||||
'mac/memory_snapshot_mac.cc',
|
||||
'mac/memory_snapshot_mac.h',
|
||||
'mac/module_snapshot_mac.cc',
|
||||
'mac/module_snapshot_mac.h',
|
||||
'mac/process_reader.cc',
|
||||
'mac/process_reader.h',
|
||||
'mac/process_types.cc',
|
||||
|
Loading…
x
Reference in New Issue
Block a user