Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "minidump/minidump_handle_writer.h" | |
| 16 | |
| 17 #include <string> | |
| 18 | |
| 19 #include "base/logging.h" | |
| 20 #include "minidump/minidump_extensions.h" | |
| 21 #include "util/file/file_writer.h" | |
| 22 | |
| 23 namespace crashpad { | |
| 24 | |
| 25 MinidumpHandleDataWriter::MinidumpHandleDataWriter() | |
| 26 : handle_data_stream_base_(), handle_descriptors_(), strings_() { | |
| 27 } | |
| 28 | |
| 29 MinidumpHandleDataWriter::~MinidumpHandleDataWriter() { | |
| 30 } | |
| 31 | |
| 32 void MinidumpHandleDataWriter::InitializeFromSnapshot( | |
| 33 const std::vector<HandleSnapshot>& handle_snapshots) { | |
| 34 DCHECK_EQ(state(), kStateMutable); | |
| 35 | |
| 36 DCHECK(handle_descriptors_.empty()); | |
| 37 handle_descriptors_.resize(handle_snapshots.size()); | |
| 38 strings_.reserve(handle_snapshots.size()); | |
| 39 for (size_t i = 0; i < handle_snapshots.size(); ++i) { | |
| 40 const HandleSnapshot& handle_snapshot = handle_snapshots[i]; | |
| 41 MINIDUMP_HANDLE_DESCRIPTOR& descriptor = handle_descriptors_[i]; | |
| 42 | |
| 43 descriptor.Handle = handle_snapshot.handle; | |
| 44 | |
| 45 if (handle_snapshot.type_name.empty()) { | |
| 46 descriptor.TypeNameRva = 0; | |
| 47 } else { | |
| 48 // Because we RegisterRVA() on the string writer below, we preallocate | |
| 49 // and never resize the handle_descriptors_ vector. | |
|
Mark Mentovai
2015/10/21 00:04:21
Doesn’t this comment belong on the handle_descript
scottmg
2015/10/21 00:14:15
Done.
| |
| 50 strings_.push_back(new internal::MinidumpUTF16StringWriter()); | |
| 51 strings_.back()->SetUTF16(handle_snapshot.type_name); | |
|
Mark Mentovai
2015/10/21 00:04:21
There’s probably a lot of duplication in these str
scottmg
2015/10/21 00:14:15
Yeah, you're right. I'll do that in a follow up.
| |
| 52 strings_.back()->RegisterRVA(&descriptor.TypeNameRva); | |
| 53 } | |
| 54 | |
| 55 descriptor.ObjectNameRva = 0; | |
| 56 descriptor.Attributes = handle_snapshot.attributes; | |
| 57 descriptor.GrantedAccess = handle_snapshot.granted_access; | |
| 58 descriptor.HandleCount = handle_snapshot.handle_count; | |
| 59 descriptor.PointerCount = handle_snapshot.pointer_count; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 bool MinidumpHandleDataWriter::Freeze() { | |
| 64 DCHECK_EQ(state(), kStateMutable); | |
| 65 | |
| 66 if (!MinidumpStreamWriter::Freeze()) | |
| 67 return false; | |
| 68 | |
| 69 handle_data_stream_base_.SizeOfHeader = sizeof(MINIDUMP_HANDLE_DATA_STREAM); | |
|
Mark Mentovai
2015/10/21 00:04:21
Use the member.
scottmg
2015/10/21 00:14:15
Done.
| |
| 70 handle_data_stream_base_.SizeOfDescriptor = | |
| 71 sizeof(MINIDUMP_HANDLE_DESCRIPTOR); | |
|
Mark Mentovai
2015/10/21 00:04:21
Here too, handle_descriptors_[0]
scottmg
2015/10/21 00:14:15
Done.
| |
| 72 handle_data_stream_base_.NumberOfDescriptors = handle_descriptors_.size(); | |
| 73 handle_data_stream_base_.Reserved = 0; | |
| 74 | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 size_t MinidumpHandleDataWriter::SizeOfObject() { | |
| 79 DCHECK_GE(state(), kStateFrozen); | |
| 80 return sizeof(handle_data_stream_base_) + | |
| 81 sizeof(handle_descriptors_[0]) * handle_descriptors_.size(); | |
| 82 } | |
| 83 | |
| 84 std::vector<internal::MinidumpWritable*> MinidumpHandleDataWriter::Children() { | |
| 85 DCHECK_GE(state(), kStateFrozen); | |
| 86 | |
| 87 std::vector<MinidumpWritable*> children; | |
| 88 for (auto* string : strings_) | |
| 89 children.push_back(string); | |
| 90 return children; | |
| 91 } | |
| 92 | |
| 93 bool MinidumpHandleDataWriter::WriteObject(FileWriterInterface* file_writer) { | |
| 94 DCHECK_EQ(state(), kStateWritable); | |
| 95 | |
| 96 WritableIoVec iov; | |
| 97 iov.iov_base = &handle_data_stream_base_; | |
| 98 iov.iov_len = sizeof(handle_data_stream_base_); | |
| 99 std::vector<WritableIoVec> iovecs(1, iov); | |
| 100 | |
| 101 for (const auto& descriptor : handle_descriptors_) { | |
| 102 iov.iov_base = &descriptor; | |
| 103 iov.iov_len = sizeof(descriptor); | |
| 104 iovecs.push_back(iov); | |
| 105 } | |
| 106 | |
| 107 return file_writer->WriteIoVec(&iovecs); | |
| 108 } | |
| 109 | |
| 110 MinidumpStreamType MinidumpHandleDataWriter::StreamType() const { | |
| 111 return kMinidumpStreamTypeHandleData; | |
| 112 } | |
| 113 | |
| 114 } // namespace crashpad | |
| OLD | NEW |