Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: minidump/minidump_memory_writer.cc

Issue 641603006: Add MinidumpMemoryListWriter::AddFromSnapshot(), everything downstream and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Correctly look for the last memory range at EOF Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « minidump/minidump_memory_writer.h ('k') | minidump/minidump_memory_writer_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: minidump/minidump_memory_writer.cc
diff --git a/minidump/minidump_memory_writer.cc b/minidump/minidump_memory_writer.cc
index 30977a9ec0fd26731224b10b057d6f33d2fcae39..434515e99db5ae2a275c308d66a793155069ad73 100644
--- a/minidump/minidump_memory_writer.cc
+++ b/minidump/minidump_memory_writer.cc
@@ -14,15 +14,76 @@
#include "minidump/minidump_memory_writer.h"
+#include "base/auto_reset.h"
#include "base/logging.h"
+#include "snapshot/memory_snapshot.h"
#include "util/file/file_writer.h"
#include "util/numeric/safe_assignment.h"
namespace crashpad {
+namespace {
+
+class SnapshotMinidumpMemoryWriter final : public MinidumpMemoryWriter,
+ public MemorySnapshot::Delegate {
+ public:
+ explicit SnapshotMinidumpMemoryWriter(const MemorySnapshot* memory_snapshot)
+ : MinidumpMemoryWriter(),
+ MemorySnapshot::Delegate(),
+ memory_snapshot_(memory_snapshot),
+ file_writer_(nullptr) {
+ }
+
+ ~SnapshotMinidumpMemoryWriter() override {}
+
+ // MemorySnapshot::Delegate:
+
+ bool MemorySnapshotDelegateRead(void* data, size_t size) override {
+ DCHECK_EQ(state(), kStateWritable);
+ DCHECK_EQ(size, MemoryRangeSize());
+ return file_writer_->Write(data, size);
+ }
+
+ protected:
+ // MinidumpMemoryWriter:
+
+ bool WriteObject(FileWriterInterface* file_writer) override {
+ DCHECK_EQ(state(), kStateWritable);
+ DCHECK(!file_writer_);
+
+ base::AutoReset<FileWriterInterface*> file_writer_reset(&file_writer_,
+ file_writer);
+
+ // This will result in MemorySnapshotDelegateRead() being called.
+ return memory_snapshot_->Read(this);
+ }
+
+ uint64_t MemoryRangeBaseAddress() const override {
+ DCHECK_EQ(state(), kStateFrozen);
+ return memory_snapshot_->Address();
+ }
+
+ size_t MemoryRangeSize() const override {
+ DCHECK_GE(state(), kStateFrozen);
+ return memory_snapshot_->Size();
+ }
+
+ private:
+ const MemorySnapshot* memory_snapshot_;
+ FileWriterInterface* file_writer_;
+
+ DISALLOW_COPY_AND_ASSIGN(SnapshotMinidumpMemoryWriter);
+};
+
+} // namespace
MinidumpMemoryWriter::~MinidumpMemoryWriter() {
}
+scoped_ptr<MinidumpMemoryWriter> MinidumpMemoryWriter::CreateFromSnapshot(
+ const MemorySnapshot* memory_snapshot) {
+ return make_scoped_ptr(new SnapshotMinidumpMemoryWriter(memory_snapshot));
+}
+
const MINIDUMP_MEMORY_DESCRIPTOR*
MinidumpMemoryWriter::MinidumpMemoryDescriptor() const {
DCHECK_EQ(state(), kStateWritable);
@@ -109,6 +170,17 @@ MinidumpMemoryListWriter::MinidumpMemoryListWriter()
MinidumpMemoryListWriter::~MinidumpMemoryListWriter() {
}
+void MinidumpMemoryListWriter::AddFromSnapshot(
+ const std::vector<const MemorySnapshot*>& memory_snapshots) {
+ DCHECK_EQ(state(), kStateMutable);
+
+ for (const MemorySnapshot* memory_snapshot : memory_snapshots) {
+ scoped_ptr<MinidumpMemoryWriter> memory =
+ MinidumpMemoryWriter::CreateFromSnapshot(memory_snapshot);
+ AddMemory(memory.Pass());
+ }
+}
+
void MinidumpMemoryListWriter::AddMemory(
scoped_ptr<MinidumpMemoryWriter> memory_writer) {
DCHECK_EQ(state(), kStateMutable);
« no previous file with comments | « minidump/minidump_memory_writer.h ('k') | minidump/minidump_memory_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698