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

Unified Diff: minidump/minidump_file_writer.cc

Issue 703223003: Add MinidumpFileWriter::InitializeFromSnapshot() and its tests (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_crashpad_info_init_from_snapshot
Patch Set: Address review feedback Created 6 years, 1 month 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_file_writer.h ('k') | minidump/minidump_file_writer_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: minidump/minidump_file_writer.cc
diff --git a/minidump/minidump_file_writer.cc b/minidump/minidump_file_writer.cc
index a3a169dd4be8034ab8925f929c4da8e222353af4..ef45a660920c2963383c9565852c987727ad2f0b 100644
--- a/minidump/minidump_file_writer.cc
+++ b/minidump/minidump_file_writer.cc
@@ -15,7 +15,16 @@
#include "minidump/minidump_file_writer.h"
#include "base/logging.h"
+#include "minidump/minidump_crashpad_info_writer.h"
+#include "minidump/minidump_exception_writer.h"
+#include "minidump/minidump_memory_writer.h"
+#include "minidump/minidump_misc_info_writer.h"
+#include "minidump/minidump_module_writer.h"
+#include "minidump/minidump_system_info_writer.h"
+#include "minidump/minidump_thread_id_map.h"
+#include "minidump/minidump_thread_writer.h"
#include "minidump/minidump_writer_util.h"
+#include "snapshot/process_snapshot.h"
#include "util/file/file_writer.h"
#include "util/numeric/safe_assignment.h"
@@ -36,6 +45,63 @@ MinidumpFileWriter::MinidumpFileWriter()
MinidumpFileWriter::~MinidumpFileWriter() {
}
+void MinidumpFileWriter::InitializeFromSnapshot(
+ const ProcessSnapshot* process_snapshot) {
+ DCHECK_EQ(state(), kStateMutable);
+ DCHECK_EQ(header_.Signature, 0u);
+ DCHECK_EQ(header_.TimeDateStamp, 0u);
+ DCHECK_EQ(header_.Flags, MiniDumpNormal);
+ DCHECK(streams_.empty());
+
+ // This time is truncated to an integer number of seconds, not rounded, for
+ // compatibility with the truncation of process_snapshot->ProcessStartTime()
+ // done by MinidumpMiscInfoWriter::InitializeFromSnapshot(). Handling both
+ // timestamps in the same way allows the highest-fidelity computation of
+ // process uptime as the difference between the two values.
+ timeval snapshot_time;
+ process_snapshot->SnapshotTime(&snapshot_time);
+ SetTimestamp(snapshot_time.tv_sec);
+
+ const SystemSnapshot* system_snapshot = process_snapshot->System();
+ auto system_info = make_scoped_ptr(new MinidumpSystemInfoWriter());
+ system_info->InitializeFromSnapshot(system_snapshot);
+ AddStream(system_info.Pass());
+
+ auto misc_info = make_scoped_ptr(new MinidumpMiscInfoWriter());
+ misc_info->InitializeFromSnapshot(process_snapshot);
+ AddStream(misc_info.Pass());
+
+ auto memory_list = make_scoped_ptr(new MinidumpMemoryListWriter());
+ auto thread_list = make_scoped_ptr(new MinidumpThreadListWriter());
+ thread_list->SetMemoryListWriter(memory_list.get());
+ MinidumpThreadIDMap thread_id_map;
+ thread_list->InitializeFromSnapshot(process_snapshot->Threads(),
+ &thread_id_map);
+ AddStream(thread_list.Pass());
+
+ const ExceptionSnapshot* exception_snapshot = process_snapshot->Exception();
+ if (exception_snapshot) {
+ auto exception = make_scoped_ptr(new MinidumpExceptionWriter());
+ exception->InitializeFromSnapshot(exception_snapshot, thread_id_map);
+ AddStream(exception.Pass());
+ }
+
+ auto module_list = make_scoped_ptr(new MinidumpModuleListWriter());
+ module_list->InitializeFromSnapshot(process_snapshot->Modules());
+ AddStream(module_list.Pass());
+
+ auto crashpad_info = make_scoped_ptr(new MinidumpCrashpadInfoWriter());
+ crashpad_info->InitializeFromSnapshot(process_snapshot);
+
+ // Since the MinidumpCrashpadInfo stream is an extension, it’s safe to not add
+ // it to the minidump file if it wouldn’t carry any useful information.
+ if (crashpad_info->IsUseful()) {
+ AddStream(crashpad_info.Pass());
+ }
+
+ AddStream(memory_list.Pass());
+}
+
void MinidumpFileWriter::SetTimestamp(time_t timestamp) {
DCHECK_EQ(state(), kStateMutable);
« no previous file with comments | « minidump/minidump_file_writer.h ('k') | minidump/minidump_file_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698