mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-20 02:23:47 +00:00
Refactor MemorySnapshotGeneric to use ProcessMemory instead of ProcessReader
Also remove MemorySnapshotWin since the code is identical to MemorySnapshotGeneric now. Bug: crashpad:95 Change-Id: I9a631f8eb206dd72a69158021db87e8db41c5913 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1642148 Reviewed-by: Mark Mentovai <mark@chromium.org> Reviewed-by: Vlad Tsyrklevich <vtsyrklevich@chromium.org> Commit-Queue: Clark DuVall <cduvall@chromium.org>
This commit is contained in:
parent
e0e83ad18a
commit
d85f898a69
@ -170,8 +170,6 @@ static_library("snapshot") {
|
|||||||
"win/exception_snapshot_win.h",
|
"win/exception_snapshot_win.h",
|
||||||
"win/memory_map_region_snapshot_win.cc",
|
"win/memory_map_region_snapshot_win.cc",
|
||||||
"win/memory_map_region_snapshot_win.h",
|
"win/memory_map_region_snapshot_win.h",
|
||||||
"win/memory_snapshot_win.cc",
|
|
||||||
"win/memory_snapshot_win.h",
|
|
||||||
"win/module_snapshot_win.cc",
|
"win/module_snapshot_win.cc",
|
||||||
"win/module_snapshot_win.h",
|
"win/module_snapshot_win.h",
|
||||||
"win/pe_image_annotations_reader.cc",
|
"win/pe_image_annotations_reader.cc",
|
||||||
|
@ -52,9 +52,9 @@ bool ThreadSnapshotFuchsia::Initialize(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (thread.stack_regions.empty()) {
|
if (thread.stack_regions.empty()) {
|
||||||
stack_.Initialize(process_reader, 0, 0);
|
stack_.Initialize(process_reader->Memory(), 0, 0);
|
||||||
} else {
|
} else {
|
||||||
stack_.Initialize(process_reader,
|
stack_.Initialize(process_reader->Memory(),
|
||||||
thread.stack_regions[0].base(),
|
thread.stack_regions[0].base(),
|
||||||
thread.stack_regions[0].size());
|
thread.stack_regions[0].size());
|
||||||
// TODO(scottmg): Handle split stack by adding other parts to ExtraMemory().
|
// TODO(scottmg): Handle split stack by adding other parts to ExtraMemory().
|
||||||
|
@ -67,7 +67,7 @@ class ThreadSnapshotFuchsia final : public ThreadSnapshot {
|
|||||||
#error Port.
|
#error Port.
|
||||||
#endif
|
#endif
|
||||||
CPUContext context_;
|
CPUContext context_;
|
||||||
MemorySnapshotGeneric<ProcessReaderFuchsia> stack_;
|
MemorySnapshotGeneric stack_;
|
||||||
zx_koid_t thread_id_;
|
zx_koid_t thread_id_;
|
||||||
zx_vaddr_t thread_specific_data_address_;
|
zx_vaddr_t thread_specific_data_address_;
|
||||||
InitializationStateDcheck initialized_;
|
InitializationStateDcheck initialized_;
|
||||||
|
@ -190,8 +190,9 @@ bool ThreadSnapshotLinux::Initialize(ProcessReaderLinux* process_reader,
|
|||||||
#error Port.
|
#error Port.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
stack_.Initialize(
|
stack_.Initialize(process_reader->Memory(),
|
||||||
process_reader, thread.stack_region_address, thread.stack_region_size);
|
thread.stack_region_address,
|
||||||
|
thread.stack_region_size);
|
||||||
|
|
||||||
thread_specific_data_address_ =
|
thread_specific_data_address_ =
|
||||||
thread.thread_info.thread_specific_data_address;
|
thread.thread_info.thread_specific_data_address;
|
||||||
|
@ -73,7 +73,7 @@ class ThreadSnapshotLinux final : public ThreadSnapshot {
|
|||||||
#endif // ARCH_CPU_X86_FAMILY
|
#endif // ARCH_CPU_X86_FAMILY
|
||||||
} context_union_;
|
} context_union_;
|
||||||
CPUContext context_;
|
CPUContext context_;
|
||||||
MemorySnapshotGeneric<ProcessReaderLinux> stack_;
|
MemorySnapshotGeneric stack_;
|
||||||
LinuxVMAddress thread_specific_data_address_;
|
LinuxVMAddress thread_specific_data_address_;
|
||||||
pid_t thread_id_;
|
pid_t thread_id_;
|
||||||
int priority_;
|
int priority_;
|
||||||
|
@ -49,7 +49,7 @@ bool ThreadSnapshotMac::Initialize(
|
|||||||
thread_specific_data_address_ =
|
thread_specific_data_address_ =
|
||||||
process_reader_thread.thread_specific_data_address;
|
process_reader_thread.thread_specific_data_address;
|
||||||
|
|
||||||
stack_.Initialize(process_reader,
|
stack_.Initialize(process_reader->Memory(),
|
||||||
process_reader_thread.stack_region_address,
|
process_reader_thread.stack_region_address,
|
||||||
process_reader_thread.stack_region_size);
|
process_reader_thread.stack_region_size);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class ThreadSnapshotMac final : public ThreadSnapshot {
|
|||||||
} context_union_;
|
} context_union_;
|
||||||
#endif
|
#endif
|
||||||
CPUContext context_;
|
CPUContext context_;
|
||||||
MemorySnapshotGeneric<ProcessReaderMac> stack_;
|
MemorySnapshotGeneric stack_;
|
||||||
uint64_t thread_id_;
|
uint64_t thread_id_;
|
||||||
uint64_t thread_specific_data_address_;
|
uint64_t thread_specific_data_address_;
|
||||||
thread_t thread_;
|
thread_t thread_;
|
||||||
|
@ -111,31 +111,6 @@ bool DetermineMergedRange(const MemorySnapshot* a,
|
|||||||
const MemorySnapshot* b,
|
const MemorySnapshot* b,
|
||||||
CheckedRange<uint64_t, size_t>* merged);
|
CheckedRange<uint64_t, size_t>* merged);
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
//! \brief A standard implementation of MemorySnapshot::MergeWithOtherSnapshot()
|
|
||||||
//! for concrete MemorySnapshot implementations that use a
|
|
||||||
//! `process_reader_`.
|
|
||||||
template <class T>
|
|
||||||
const MemorySnapshot* MergeWithOtherSnapshotImpl(const T* self,
|
|
||||||
const MemorySnapshot* other) {
|
|
||||||
const T* other_as_memory_snapshot_concrete =
|
|
||||||
reinterpret_cast<const T*>(other);
|
|
||||||
if (self->process_reader_ !=
|
|
||||||
other_as_memory_snapshot_concrete->process_reader_) {
|
|
||||||
LOG(ERROR) << "different process_reader_ for snapshots";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
CheckedRange<uint64_t, size_t> merged(0, 0);
|
|
||||||
if (!LoggingDetermineMergedRange(self, other, &merged))
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
std::unique_ptr<T> result(new T());
|
|
||||||
result->Initialize(self->process_reader_, merged.base(), merged.size());
|
|
||||||
return result.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
} // namespace crashpad
|
} // namespace crashpad
|
||||||
|
|
||||||
#endif // CRASHPAD_SNAPSHOT_MEMORY_SNAPSHOT_H_
|
#endif // CRASHPAD_SNAPSHOT_MEMORY_SNAPSHOT_H_
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
|
#include "base/numerics/safe_math.h"
|
||||||
#include "snapshot/memory_snapshot.h"
|
#include "snapshot/memory_snapshot.h"
|
||||||
#include "util/misc/address_types.h"
|
#include "util/misc/address_types.h"
|
||||||
#include "util/misc/initialization_state_dcheck.h"
|
#include "util/misc/initialization_state_dcheck.h"
|
||||||
@ -30,7 +31,6 @@ namespace internal {
|
|||||||
//! \brief A MemorySnapshot of a memory region in a process on the running
|
//! \brief A MemorySnapshot of a memory region in a process on the running
|
||||||
//! system. Used on Mac, Linux, Android, and Fuchsia, templated on the
|
//! system. Used on Mac, Linux, Android, and Fuchsia, templated on the
|
||||||
//! platform-specific ProcessReader type.
|
//! platform-specific ProcessReader type.
|
||||||
template <class ProcessReaderType>
|
|
||||||
class MemorySnapshotGeneric final : public MemorySnapshot {
|
class MemorySnapshotGeneric final : public MemorySnapshot {
|
||||||
public:
|
public:
|
||||||
MemorySnapshotGeneric() = default;
|
MemorySnapshotGeneric() = default;
|
||||||
@ -42,25 +42,25 @@ class MemorySnapshotGeneric final : public MemorySnapshot {
|
|||||||
//! until Read() is called, and the memory snapshot data is discared when
|
//! until Read() is called, and the memory snapshot data is discared when
|
||||||
//! Read() returns.
|
//! Read() returns.
|
||||||
//!
|
//!
|
||||||
//! \param[in] process_reader A reader for the process being snapshotted.
|
//! \param[in] process_memory A reader for the process being snapshotted.
|
||||||
//! \param[in] address The base address of the memory region to snapshot, in
|
//! \param[in] address The base address of the memory region to snapshot, in
|
||||||
//! the snapshot process’ address space.
|
//! the snapshot process’ address space.
|
||||||
//! \param[in] size The size of the memory region to snapshot.
|
//! \param[in] size The size of the memory region to snapshot.
|
||||||
void Initialize(ProcessReaderType* process_reader,
|
void Initialize(const ProcessMemory* process_memory,
|
||||||
VMAddress address,
|
VMAddress address,
|
||||||
VMSize size) {
|
VMSize size) {
|
||||||
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
||||||
process_reader_ = process_reader;
|
process_memory_ = process_memory;
|
||||||
address_ = address;
|
address_ = address;
|
||||||
size_ = size;
|
size_ = base::checked_cast<size_t>(size);
|
||||||
INITIALIZATION_STATE_SET_VALID(initialized_);
|
INITIALIZATION_STATE_SET_VALID(initialized_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemorySnapshot:
|
// MemorySnapshot:
|
||||||
|
|
||||||
uint64_t Address() const override {
|
uint64_t Address() const override {
|
||||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||||
return address_;
|
return address_;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Size() const override {
|
size_t Size() const override {
|
||||||
@ -76,7 +76,7 @@ class MemorySnapshotGeneric final : public MemorySnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size_]);
|
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size_]);
|
||||||
if (!process_reader_->Memory()->Read(address_, size_, buffer.get())) {
|
if (!process_memory_->Read(address_, size_, buffer.get())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return delegate->MemorySnapshotDelegateRead(buffer.get(), size_);
|
return delegate->MemorySnapshotDelegateRead(buffer.get(), size_);
|
||||||
@ -84,7 +84,19 @@ class MemorySnapshotGeneric final : public MemorySnapshot {
|
|||||||
|
|
||||||
const MemorySnapshot* MergeWithOtherSnapshot(
|
const MemorySnapshot* MergeWithOtherSnapshot(
|
||||||
const MemorySnapshot* other) const override {
|
const MemorySnapshot* other) const override {
|
||||||
return MergeWithOtherSnapshotImpl(this, other);
|
const MemorySnapshotGeneric* other_as_memory_snapshot_concrete =
|
||||||
|
reinterpret_cast<const MemorySnapshotGeneric*>(other);
|
||||||
|
if (process_memory_ != other_as_memory_snapshot_concrete->process_memory_) {
|
||||||
|
LOG(ERROR) << "different process_memory_ for snapshots";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
CheckedRange<uint64_t, size_t> merged(0, 0);
|
||||||
|
if (!LoggingDetermineMergedRange(this, other, &merged))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto result = std::make_unique<MemorySnapshotGeneric>();
|
||||||
|
result->Initialize(process_memory_, merged.base(), merged.size());
|
||||||
|
return result.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -93,9 +105,9 @@ class MemorySnapshotGeneric final : public MemorySnapshot {
|
|||||||
const T* self,
|
const T* self,
|
||||||
const MemorySnapshot* other);
|
const MemorySnapshot* other);
|
||||||
|
|
||||||
ProcessReaderType* process_reader_; // weak
|
const ProcessMemory* process_memory_; // weak
|
||||||
uint64_t address_;
|
VMAddress address_;
|
||||||
uint64_t size_;
|
size_t size_;
|
||||||
InitializationStateDcheck initialized_;
|
InitializationStateDcheck initialized_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(MemorySnapshotGeneric);
|
DISALLOW_COPY_AND_ASSIGN(MemorySnapshotGeneric);
|
||||||
|
@ -155,8 +155,6 @@
|
|||||||
'win/capture_memory_delegate_win.h',
|
'win/capture_memory_delegate_win.h',
|
||||||
'win/memory_map_region_snapshot_win.cc',
|
'win/memory_map_region_snapshot_win.cc',
|
||||||
'win/memory_map_region_snapshot_win.h',
|
'win/memory_map_region_snapshot_win.h',
|
||||||
'win/memory_snapshot_win.cc',
|
|
||||||
'win/memory_snapshot_win.h',
|
|
||||||
'win/module_snapshot_win.cc',
|
'win/module_snapshot_win.cc',
|
||||||
'win/module_snapshot_win.h',
|
'win/module_snapshot_win.h',
|
||||||
'win/pe_image_annotations_reader.cc',
|
'win/pe_image_annotations_reader.cc',
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "base/numerics/safe_conversions.h"
|
#include "base/numerics/safe_conversions.h"
|
||||||
#include "snapshot/win/memory_snapshot_win.h"
|
#include "snapshot/memory_snapshot_generic.h"
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -25,7 +25,7 @@ namespace internal {
|
|||||||
CaptureMemoryDelegateWin::CaptureMemoryDelegateWin(
|
CaptureMemoryDelegateWin::CaptureMemoryDelegateWin(
|
||||||
ProcessReaderWin* process_reader,
|
ProcessReaderWin* process_reader,
|
||||||
const ProcessReaderWin::Thread& thread,
|
const ProcessReaderWin::Thread& thread,
|
||||||
std::vector<std::unique_ptr<MemorySnapshotWin>>* snapshots,
|
std::vector<std::unique_ptr<MemorySnapshotGeneric>>* snapshots,
|
||||||
uint32_t* budget_remaining)
|
uint32_t* budget_remaining)
|
||||||
: stack_(thread.stack_region_address, thread.stack_region_size),
|
: stack_(thread.stack_region_address, thread.stack_region_size),
|
||||||
process_reader_(process_reader),
|
process_reader_(process_reader),
|
||||||
@ -57,9 +57,9 @@ void CaptureMemoryDelegateWin::AddNewMemorySnapshot(
|
|||||||
return;
|
return;
|
||||||
if (budget_remaining_ && *budget_remaining_ == 0)
|
if (budget_remaining_ && *budget_remaining_ == 0)
|
||||||
return;
|
return;
|
||||||
snapshots_->push_back(std::make_unique<internal::MemorySnapshotWin>());
|
snapshots_->push_back(std::make_unique<internal::MemorySnapshotGeneric>());
|
||||||
internal::MemorySnapshotWin* snapshot = snapshots_->back().get();
|
internal::MemorySnapshotGeneric* snapshot = snapshots_->back().get();
|
||||||
snapshot->Initialize(process_reader_, range.base(), range.size());
|
snapshot->Initialize(process_reader_->Memory(), range.base(), range.size());
|
||||||
if (budget_remaining_) {
|
if (budget_remaining_) {
|
||||||
if (!base::IsValueInRangeForNumericType<int64_t>(range.size())) {
|
if (!base::IsValueInRangeForNumericType<int64_t>(range.size())) {
|
||||||
*budget_remaining_ = 0;
|
*budget_remaining_ = 0;
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
class MemorySnapshotWin;
|
class MemorySnapshotGeneric;
|
||||||
|
|
||||||
class CaptureMemoryDelegateWin : public CaptureMemory::Delegate {
|
class CaptureMemoryDelegateWin : public CaptureMemory::Delegate {
|
||||||
public:
|
public:
|
||||||
@ -38,15 +38,15 @@ class CaptureMemoryDelegateWin : public CaptureMemory::Delegate {
|
|||||||
//! \param[in] thread The thread being inspected. Memory ranges overlapping
|
//! \param[in] thread The thread being inspected. Memory ranges overlapping
|
||||||
//! this thread's stack will be ignored on the assumption that they're
|
//! this thread's stack will be ignored on the assumption that they're
|
||||||
//! already captured elsewhere.
|
//! already captured elsewhere.
|
||||||
//! \param[in] snapshots A vector of MemorySnapshotWin to which the captured
|
//! \param[in] snapshots A vector of MemorySnapshotGeneric to which the
|
||||||
//! memory will be added.
|
//! captured memory will be added.
|
||||||
//! \param[in] budget_remaining If non-null, a pointer to the remaining number
|
//! \param[in] budget_remaining If non-null, a pointer to the remaining number
|
||||||
//! of bytes to capture. If this is `0`, no further memory will be
|
//! of bytes to capture. If this is `0`, no further memory will be
|
||||||
//! captured.
|
//! captured.
|
||||||
CaptureMemoryDelegateWin(
|
CaptureMemoryDelegateWin(
|
||||||
ProcessReaderWin* process_reader,
|
ProcessReaderWin* process_reader,
|
||||||
const ProcessReaderWin::Thread& thread,
|
const ProcessReaderWin::Thread& thread,
|
||||||
std::vector<std::unique_ptr<MemorySnapshotWin>>* snapshots,
|
std::vector<std::unique_ptr<MemorySnapshotGeneric>>* snapshots,
|
||||||
uint32_t* budget_remaining);
|
uint32_t* budget_remaining);
|
||||||
|
|
||||||
// MemoryCaptureDelegate:
|
// MemoryCaptureDelegate:
|
||||||
@ -60,7 +60,7 @@ class CaptureMemoryDelegateWin : public CaptureMemory::Delegate {
|
|||||||
private:
|
private:
|
||||||
CheckedRange<uint64_t, uint64_t> stack_;
|
CheckedRange<uint64_t, uint64_t> stack_;
|
||||||
ProcessReaderWin* process_reader_; // weak
|
ProcessReaderWin* process_reader_; // weak
|
||||||
std::vector<std::unique_ptr<MemorySnapshotWin>>* snapshots_; // weak
|
std::vector<std::unique_ptr<MemorySnapshotGeneric>>* snapshots_; // weak
|
||||||
uint32_t* budget_remaining_;
|
uint32_t* budget_remaining_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
#include "client/crashpad_client.h"
|
#include "client/crashpad_client.h"
|
||||||
#include "snapshot/capture_memory.h"
|
#include "snapshot/capture_memory.h"
|
||||||
#include "snapshot/memory_snapshot.h"
|
#include "snapshot/memory_snapshot.h"
|
||||||
#include "snapshot/win/cpu_context_win.h"
|
#include "snapshot/memory_snapshot_generic.h"
|
||||||
#include "snapshot/win/capture_memory_delegate_win.h"
|
#include "snapshot/win/capture_memory_delegate_win.h"
|
||||||
#include "snapshot/win/memory_snapshot_win.h"
|
#include "snapshot/win/cpu_context_win.h"
|
||||||
#include "snapshot/win/process_reader_win.h"
|
#include "snapshot/win/process_reader_win.h"
|
||||||
#include "util/win/nt_internals.h"
|
#include "util/win/nt_internals.h"
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class ProcessReaderWin;
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
class MemorySnapshotWin;
|
class MemorySnapshotGeneric;
|
||||||
|
|
||||||
union CPUContextUnion {
|
union CPUContextUnion {
|
||||||
#if defined(ARCH_CPU_X86_FAMILY)
|
#if defined(ARCH_CPU_X86_FAMILY)
|
||||||
@ -96,7 +96,7 @@ class ExceptionSnapshotWin final : public ExceptionSnapshot {
|
|||||||
CPUContextUnion context_union_;
|
CPUContextUnion context_union_;
|
||||||
CPUContext context_;
|
CPUContext context_;
|
||||||
std::vector<uint64_t> codes_;
|
std::vector<uint64_t> codes_;
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>> extra_memory_;
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>> extra_memory_;
|
||||||
uint64_t thread_id_;
|
uint64_t thread_id_;
|
||||||
uint64_t exception_address_;
|
uint64_t exception_address_;
|
||||||
uint32_t exception_flags_;
|
uint32_t exception_flags_;
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
// Copyright 2015 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 <memory>
|
|
||||||
|
|
||||||
#include "snapshot/win/memory_snapshot_win.h"
|
|
||||||
|
|
||||||
namespace crashpad {
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
MemorySnapshotWin::MemorySnapshotWin()
|
|
||||||
: MemorySnapshot(),
|
|
||||||
process_reader_(nullptr),
|
|
||||||
address_(0),
|
|
||||||
size_(0),
|
|
||||||
initialized_() {
|
|
||||||
}
|
|
||||||
|
|
||||||
MemorySnapshotWin::~MemorySnapshotWin() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemorySnapshotWin::Initialize(ProcessReaderWin* process_reader,
|
|
||||||
uint64_t address,
|
|
||||||
uint64_t size) {
|
|
||||||
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
|
||||||
process_reader_ = process_reader;
|
|
||||||
address_ = address;
|
|
||||||
DLOG_IF(WARNING, size >= std::numeric_limits<size_t>::max())
|
|
||||||
<< "size overflow";
|
|
||||||
size_ = static_cast<size_t>(size);
|
|
||||||
INITIALIZATION_STATE_SET_VALID(initialized_);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t MemorySnapshotWin::Address() const {
|
|
||||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
||||||
return address_;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t MemorySnapshotWin::Size() const {
|
|
||||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
||||||
return size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MemorySnapshotWin::Read(Delegate* delegate) const {
|
|
||||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
|
||||||
|
|
||||||
if (size_ == 0) {
|
|
||||||
return delegate->MemorySnapshotDelegateRead(nullptr, size_);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size_]);
|
|
||||||
if (!process_reader_->Memory()->Read(address_, size_, buffer.get())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return delegate->MemorySnapshotDelegateRead(buffer.get(), size_);
|
|
||||||
}
|
|
||||||
|
|
||||||
const MemorySnapshot* MemorySnapshotWin::MergeWithOtherSnapshot(
|
|
||||||
const MemorySnapshot* other) const {
|
|
||||||
return MergeWithOtherSnapshotImpl(this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
} // namespace crashpad
|
|
@ -1,75 +0,0 @@
|
|||||||
// Copyright 2015 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_WIN_MEMORY_SNAPSHOT_WIN_H_
|
|
||||||
#define CRASHPAD_SNAPSHOT_WIN_MEMORY_SNAPSHOT_WIN_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include "base/macros.h"
|
|
||||||
#include "snapshot/memory_snapshot.h"
|
|
||||||
#include "snapshot/win/process_reader_win.h"
|
|
||||||
#include "util/misc/initialization_state_dcheck.h"
|
|
||||||
|
|
||||||
namespace crashpad {
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
//! \brief A MemorySnapshot of a memory region in a process on the running
|
|
||||||
//! system, when the system runs Windows.
|
|
||||||
class MemorySnapshotWin final : public MemorySnapshot {
|
|
||||||
public:
|
|
||||||
MemorySnapshotWin();
|
|
||||||
~MemorySnapshotWin() override;
|
|
||||||
|
|
||||||
//! \brief Initializes the object.
|
|
||||||
//!
|
|
||||||
//! Memory is read lazily. No attempt is made to read the memory snapshot data
|
|
||||||
//! until Read() is called, and the memory snapshot data is discared when
|
|
||||||
//! Read() returns.
|
|
||||||
//!
|
|
||||||
//! \param[in] process_reader A reader for the process being snapshotted.
|
|
||||||
//! \param[in] address The base address of the memory region to snapshot, in
|
|
||||||
//! the snapshot process' address space.
|
|
||||||
//! \param[in] size The size of the memory region to snapshot.
|
|
||||||
void Initialize(ProcessReaderWin* process_reader,
|
|
||||||
uint64_t address,
|
|
||||||
uint64_t size);
|
|
||||||
|
|
||||||
// MemorySnapshot:
|
|
||||||
|
|
||||||
uint64_t Address() const override;
|
|
||||||
size_t Size() const override;
|
|
||||||
bool Read(Delegate* delegate) const override;
|
|
||||||
const MemorySnapshot* MergeWithOtherSnapshot(
|
|
||||||
const MemorySnapshot* other) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
template <class T>
|
|
||||||
friend const MemorySnapshot* MergeWithOtherSnapshotImpl(
|
|
||||||
const T* self,
|
|
||||||
const MemorySnapshot* other);
|
|
||||||
|
|
||||||
ProcessReaderWin* process_reader_; // weak
|
|
||||||
uint64_t address_;
|
|
||||||
size_t size_;
|
|
||||||
InitializationStateDcheck initialized_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(MemorySnapshotWin);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
} // namespace crashpad
|
|
||||||
|
|
||||||
#endif // CRASHPAD_SNAPSHOT_WIN_MEMORY_SNAPSHOT_WIN_H_
|
|
@ -19,7 +19,7 @@
|
|||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "client/crashpad_info.h"
|
#include "client/crashpad_info.h"
|
||||||
#include "client/simple_address_range_bag.h"
|
#include "client/simple_address_range_bag.h"
|
||||||
#include "snapshot/win/memory_snapshot_win.h"
|
#include "snapshot/memory_snapshot_generic.h"
|
||||||
#include "snapshot/win/pe_image_annotations_reader.h"
|
#include "snapshot/win/pe_image_annotations_reader.h"
|
||||||
#include "snapshot/win/pe_image_reader.h"
|
#include "snapshot/win/pe_image_reader.h"
|
||||||
#include "util/misc/tri_state.h"
|
#include "util/misc/tri_state.h"
|
||||||
@ -327,10 +327,10 @@ void ModuleSnapshotWin::GetCrashpadUserMinidumpStreams(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (list_entry.size != 0) {
|
if (list_entry.size != 0) {
|
||||||
std::unique_ptr<internal::MemorySnapshotWin> memory(
|
std::unique_ptr<internal::MemorySnapshotGeneric> memory(
|
||||||
new internal::MemorySnapshotWin());
|
new internal::MemorySnapshotGeneric());
|
||||||
memory->Initialize(
|
memory->Initialize(
|
||||||
process_reader_, list_entry.base_address, list_entry.size);
|
process_reader_->Memory(), list_entry.base_address, list_entry.size);
|
||||||
streams->push_back(std::make_unique<UserMinidumpStream>(
|
streams->push_back(std::make_unique<UserMinidumpStream>(
|
||||||
list_entry.stream_type, memory.release()));
|
list_entry.stream_type, memory.release()));
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,7 @@ void ProcessSnapshotWin::InitializePebData(
|
|||||||
void ProcessSnapshotWin::AddMemorySnapshot(
|
void ProcessSnapshotWin::AddMemorySnapshot(
|
||||||
WinVMAddress address,
|
WinVMAddress address,
|
||||||
WinVMSize size,
|
WinVMSize size,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into) {
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into) {
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -480,14 +480,14 @@ void ProcessSnapshotWin::AddMemorySnapshot(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
into->push_back(std::make_unique<internal::MemorySnapshotWin>());
|
into->push_back(std::make_unique<internal::MemorySnapshotGeneric>());
|
||||||
into->back()->Initialize(&process_reader_, address, size);
|
into->back()->Initialize(process_reader_.Memory(), address, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Traits>
|
template <class Traits>
|
||||||
void ProcessSnapshotWin::AddMemorySnapshotForUNICODE_STRING(
|
void ProcessSnapshotWin::AddMemorySnapshotForUNICODE_STRING(
|
||||||
const process_types::UNICODE_STRING<Traits>& us,
|
const process_types::UNICODE_STRING<Traits>& us,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into) {
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into) {
|
||||||
AddMemorySnapshot(us.Buffer, us.Length, into);
|
AddMemorySnapshot(us.Buffer, us.Length, into);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +495,7 @@ template <class Traits>
|
|||||||
void ProcessSnapshotWin::AddMemorySnapshotForLdrLIST_ENTRY(
|
void ProcessSnapshotWin::AddMemorySnapshotForLdrLIST_ENTRY(
|
||||||
const process_types::LIST_ENTRY<Traits>& le,
|
const process_types::LIST_ENTRY<Traits>& le,
|
||||||
size_t offset_of_member,
|
size_t offset_of_member,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into) {
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into) {
|
||||||
// Walk the doubly-linked list of entries, adding the list memory itself, as
|
// Walk the doubly-linked list of entries, adding the list memory itself, as
|
||||||
// well as pointed-to strings.
|
// well as pointed-to strings.
|
||||||
typename Traits::Pointer last = le.Blink;
|
typename Traits::Pointer last = le.Blink;
|
||||||
@ -545,7 +545,7 @@ WinVMSize ProcessSnapshotWin::DetermineSizeOfEnvironmentBlock(
|
|||||||
template <class Traits>
|
template <class Traits>
|
||||||
void ProcessSnapshotWin::ReadLock(
|
void ProcessSnapshotWin::ReadLock(
|
||||||
WinVMAddress start,
|
WinVMAddress start,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into) {
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into) {
|
||||||
// We're walking the RTL_CRITICAL_SECTION_DEBUG ProcessLocksList, but starting
|
// We're walking the RTL_CRITICAL_SECTION_DEBUG ProcessLocksList, but starting
|
||||||
// from an actual RTL_CRITICAL_SECTION, so start by getting to the first
|
// from an actual RTL_CRITICAL_SECTION, so start by getting to the first
|
||||||
// RTL_CRITICAL_SECTION_DEBUG.
|
// RTL_CRITICAL_SECTION_DEBUG.
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "snapshot/exception_snapshot.h"
|
#include "snapshot/exception_snapshot.h"
|
||||||
#include "snapshot/memory_map_region_snapshot.h"
|
#include "snapshot/memory_map_region_snapshot.h"
|
||||||
#include "snapshot/memory_snapshot.h"
|
#include "snapshot/memory_snapshot.h"
|
||||||
|
#include "snapshot/memory_snapshot_generic.h"
|
||||||
#include "snapshot/module_snapshot.h"
|
#include "snapshot/module_snapshot.h"
|
||||||
#include "snapshot/process_snapshot.h"
|
#include "snapshot/process_snapshot.h"
|
||||||
#include "snapshot/system_snapshot.h"
|
#include "snapshot/system_snapshot.h"
|
||||||
@ -38,7 +39,6 @@
|
|||||||
#include "snapshot/unloaded_module_snapshot.h"
|
#include "snapshot/unloaded_module_snapshot.h"
|
||||||
#include "snapshot/win/exception_snapshot_win.h"
|
#include "snapshot/win/exception_snapshot_win.h"
|
||||||
#include "snapshot/win/memory_map_region_snapshot_win.h"
|
#include "snapshot/win/memory_map_region_snapshot_win.h"
|
||||||
#include "snapshot/win/memory_snapshot_win.h"
|
|
||||||
#include "snapshot/win/module_snapshot_win.h"
|
#include "snapshot/win/module_snapshot_win.h"
|
||||||
#include "snapshot/win/system_snapshot_win.h"
|
#include "snapshot/win/system_snapshot_win.h"
|
||||||
#include "snapshot/win/thread_snapshot_win.h"
|
#include "snapshot/win/thread_snapshot_win.h"
|
||||||
@ -154,18 +154,18 @@ class ProcessSnapshotWin final : public ProcessSnapshot {
|
|||||||
void AddMemorySnapshot(
|
void AddMemorySnapshot(
|
||||||
WinVMAddress address,
|
WinVMAddress address,
|
||||||
WinVMSize size,
|
WinVMSize size,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into);
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into);
|
||||||
|
|
||||||
template <class Traits>
|
template <class Traits>
|
||||||
void AddMemorySnapshotForUNICODE_STRING(
|
void AddMemorySnapshotForUNICODE_STRING(
|
||||||
const process_types::UNICODE_STRING<Traits>& us,
|
const process_types::UNICODE_STRING<Traits>& us,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into);
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into);
|
||||||
|
|
||||||
template <class Traits>
|
template <class Traits>
|
||||||
void AddMemorySnapshotForLdrLIST_ENTRY(
|
void AddMemorySnapshotForLdrLIST_ENTRY(
|
||||||
const process_types::LIST_ENTRY<Traits>& le,
|
const process_types::LIST_ENTRY<Traits>& le,
|
||||||
size_t offset_of_member,
|
size_t offset_of_member,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into);
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into);
|
||||||
|
|
||||||
WinVMSize DetermineSizeOfEnvironmentBlock(
|
WinVMSize DetermineSizeOfEnvironmentBlock(
|
||||||
WinVMAddress start_of_environment_block);
|
WinVMAddress start_of_environment_block);
|
||||||
@ -175,10 +175,10 @@ class ProcessSnapshotWin final : public ProcessSnapshot {
|
|||||||
template <class Traits>
|
template <class Traits>
|
||||||
void ReadLock(
|
void ReadLock(
|
||||||
WinVMAddress start,
|
WinVMAddress start,
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into);
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>>* into);
|
||||||
|
|
||||||
internal::SystemSnapshotWin system_;
|
internal::SystemSnapshotWin system_;
|
||||||
std::vector<std::unique_ptr<internal::MemorySnapshotWin>> extra_memory_;
|
std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>> extra_memory_;
|
||||||
std::vector<std::unique_ptr<internal::ThreadSnapshotWin>> threads_;
|
std::vector<std::unique_ptr<internal::ThreadSnapshotWin>> threads_;
|
||||||
std::vector<std::unique_ptr<internal::ModuleSnapshotWin>> modules_;
|
std::vector<std::unique_ptr<internal::ModuleSnapshotWin>> modules_;
|
||||||
std::vector<UnloadedModuleSnapshot> unloaded_modules_;
|
std::vector<UnloadedModuleSnapshot> unloaded_modules_;
|
||||||
|
@ -48,19 +48,20 @@ bool ThreadSnapshotWin::Initialize(
|
|||||||
if (process_reader->GetProcessInfo().LoggingRangeIsFullyReadable(
|
if (process_reader->GetProcessInfo().LoggingRangeIsFullyReadable(
|
||||||
CheckedRange<WinVMAddress, WinVMSize>(thread_.stack_region_address,
|
CheckedRange<WinVMAddress, WinVMSize>(thread_.stack_region_address,
|
||||||
thread_.stack_region_size))) {
|
thread_.stack_region_size))) {
|
||||||
stack_.Initialize(process_reader,
|
stack_.Initialize(process_reader->Memory(),
|
||||||
thread_.stack_region_address,
|
thread_.stack_region_address,
|
||||||
thread_.stack_region_size);
|
thread_.stack_region_size);
|
||||||
} else {
|
} else {
|
||||||
stack_.Initialize(process_reader, 0, 0);
|
stack_.Initialize(process_reader->Memory(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process_reader->GetProcessInfo().LoggingRangeIsFullyReadable(
|
if (process_reader->GetProcessInfo().LoggingRangeIsFullyReadable(
|
||||||
CheckedRange<WinVMAddress, WinVMSize>(thread_.teb_address,
|
CheckedRange<WinVMAddress, WinVMSize>(thread_.teb_address,
|
||||||
thread_.teb_size))) {
|
thread_.teb_size))) {
|
||||||
teb_.Initialize(process_reader, thread_.teb_address, thread_.teb_size);
|
teb_.Initialize(
|
||||||
|
process_reader->Memory(), thread_.teb_address, thread_.teb_size);
|
||||||
} else {
|
} else {
|
||||||
teb_.Initialize(process_reader, 0, 0);
|
teb_.Initialize(process_reader->Memory(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ARCH_CPU_X86)
|
#if defined(ARCH_CPU_X86)
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
#include "snapshot/cpu_context.h"
|
#include "snapshot/cpu_context.h"
|
||||||
#include "snapshot/memory_snapshot.h"
|
#include "snapshot/memory_snapshot.h"
|
||||||
|
#include "snapshot/memory_snapshot_generic.h"
|
||||||
#include "snapshot/thread_snapshot.h"
|
#include "snapshot/thread_snapshot.h"
|
||||||
#include "snapshot/win/memory_snapshot_win.h"
|
|
||||||
#include "snapshot/win/process_reader_win.h"
|
#include "snapshot/win/process_reader_win.h"
|
||||||
#include "util/misc/initialization_state_dcheck.h"
|
#include "util/misc/initialization_state_dcheck.h"
|
||||||
|
|
||||||
@ -82,11 +82,11 @@ class ThreadSnapshotWin final : public ThreadSnapshot {
|
|||||||
#endif
|
#endif
|
||||||
} context_union_;
|
} context_union_;
|
||||||
CPUContext context_;
|
CPUContext context_;
|
||||||
MemorySnapshotWin stack_;
|
MemorySnapshotGeneric stack_;
|
||||||
MemorySnapshotWin teb_;
|
MemorySnapshotGeneric teb_;
|
||||||
ProcessReaderWin::Thread thread_;
|
ProcessReaderWin::Thread thread_;
|
||||||
InitializationStateDcheck initialized_;
|
InitializationStateDcheck initialized_;
|
||||||
std::vector<std::unique_ptr<MemorySnapshotWin>> pointed_to_memory_;
|
std::vector<std::unique_ptr<MemorySnapshotGeneric>> pointed_to_memory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ThreadSnapshotWin);
|
DISALLOW_COPY_AND_ASSIGN(ThreadSnapshotWin);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user