Add MemorySnapshotLinux

Bug: crashpad:30
Change-Id: Iddd100c3806178f6d20dd903e3f41926904696d4
Reviewed-on: https://chromium-review.googlesource.com/577977
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Joshua Peraza 2017-07-19 14:31:15 -07:00
parent 7be6b8ea1d
commit bde35ca918
3 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,68 @@
// Copyright 2017 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/linux/memory_snapshot_linux.h"
#include <memory>
namespace crashpad {
namespace internal {
MemorySnapshotLinux::MemorySnapshotLinux()
: MemorySnapshot(),
process_reader_(nullptr),
address_(0),
size_(0),
initialized_() {
}
MemorySnapshotLinux::~MemorySnapshotLinux() {
}
void MemorySnapshotLinux::Initialize(ProcessReader* process_reader,
LinuxVMAddress address,
size_t size) {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
process_reader_ = process_reader;
address_ = address;
size_ = size;
INITIALIZATION_STATE_SET_VALID(initialized_);
}
uint64_t MemorySnapshotLinux::Address() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
return address_;
}
size_t MemorySnapshotLinux::Size() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
return size_;
}
bool MemorySnapshotLinux::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_);
}
} // namespace internal
} // namespace crashpad

View File

@ -0,0 +1,69 @@
// Copyright 2017 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_LINUX_MEMORY_SNAPSHOT_LINUX_H_
#define CRASHPAD_SNAPSHOT_LINUX_MEMORY_SNAPSHOT_LINUX_H_
#include <stddef.h>
#include <stdint.h>
#include "base/macros.h"
#include "snapshot/linux/process_reader.h"
#include "snapshot/memory_snapshot.h"
#include "util/linux/address_types.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 Linux.
class MemorySnapshotLinux final : public MemorySnapshot {
public:
MemorySnapshotLinux();
~MemorySnapshotLinux() 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(ProcessReader* process_reader,
LinuxVMAddress address,
size_t size);
// MemorySnapshot:
uint64_t Address() const override;
size_t Size() const override;
bool Read(Delegate* delegate) const override;
private:
ProcessReader* process_reader_; // weak
uint64_t address_;
size_t size_;
InitializationStateDcheck initialized_;
DISALLOW_COPY_AND_ASSIGN(MemorySnapshotLinux);
};
} // namespace internal
} // namespace crashpad
#endif // CRASHPAD_SNAPSHOT_LINUX_MEMORY_SNAPSHOT_LINUX_H_

View File

@ -50,6 +50,8 @@
'linux/elf_image_reader.h',
'linux/elf_symbol_table_reader.cc',
'linux/elf_symbol_table_reader.h',
'linux/memory_snapshot_linux.cc',
'linux/memory_snapshot_linux.h',
'linux/process_reader.cc',
'linux/process_reader.h',
'mac/cpu_context_mac.cc',