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

Side by Side Diff: minidump/minidump_system_info_writer.cc

Issue 435243002: Add MinidumpSystemInfoWriter and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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_system_info_writer.h"
16
17 #include <string.h>
18
19 #include "base/logging.h"
20
21 namespace crashpad {
22
23 MinidumpSystemInfoWriter::MinidumpSystemInfoWriter()
24 : MinidumpStreamWriter(), system_info_(), csd_version_() {
25 system_info_.ProcessorArchitecture = kMinidumpCPUArchitectureUnknown;
26 }
27
28 MinidumpSystemInfoWriter::~MinidumpSystemInfoWriter() {
29 }
30
31 void MinidumpSystemInfoWriter::SetCSDVersion(const std::string& csd_version) {
32 DCHECK_EQ(state(), kStateMutable);
33
34 if (!csd_version_) {
35 csd_version_.reset(new internal::MinidumpUTF16StringWriter());
36 }
37
38 csd_version_->SetUTF8(csd_version);
39 }
40
41 void MinidumpSystemInfoWriter::SetCPUX86Vendor(uint32_t ebx,
42 uint32_t edx,
43 uint32_t ecx) {
44 DCHECK_EQ(state(), kStateMutable);
45 DCHECK(system_info_.ProcessorArchitecture == kMinidumpCPUArchitectureX86 ||
Robert Sesek 2014/08/06 17:35:46 Not kMinidumpCPUArchitectureAMD64 here or the othe
Mark Mentovai 2014/08/06 18:14:02 rsesek wrote:
Robert Sesek 2014/08/07 16:48:14 The only thing I can think of would maybe explicit
46 system_info_.ProcessorArchitecture ==
47 kMinidumpCPUArchitectureX86Win64);
48
49 COMPILE_ASSERT(arraysize(system_info_.Cpu.X86CpuInfo.VendorId) == 3,
50 vendor_id_must_have_3_elements);
51
52 system_info_.Cpu.X86CpuInfo.VendorId[0] = ebx;
53 system_info_.Cpu.X86CpuInfo.VendorId[1] = edx;
54 system_info_.Cpu.X86CpuInfo.VendorId[2] = ecx;
55 }
56
57 void MinidumpSystemInfoWriter::SetCPUX86VendorString(
58 const std::string& vendor) {
59 DCHECK_EQ(state(), kStateMutable);
60 CHECK_EQ(vendor.size(), sizeof(system_info_.Cpu.X86CpuInfo.VendorId));
61
62 uint32_t registers[3];
63 COMPILE_ASSERT(
64 sizeof(registers) == sizeof(system_info_.Cpu.X86CpuInfo.VendorId),
65 vendor_id_sizes_must_be_equal);
66
67 for (size_t index = 0; index < arraysize(registers); ++index) {
68 memcpy(&registers[index],
69 &vendor[index * sizeof(*registers)],
70 sizeof(*registers));
71 }
72
73 SetCPUX86Vendor(registers[0], registers[1], registers[2]);
74 }
75
76 void MinidumpSystemInfoWriter::SetCPUX86VersionAndFeatures(uint32_t version,
77 uint32_t features) {
78 DCHECK_EQ(state(), kStateMutable);
79 DCHECK(system_info_.ProcessorArchitecture == kMinidumpCPUArchitectureX86 ||
80 system_info_.ProcessorArchitecture ==
81 kMinidumpCPUArchitectureX86Win64);
82
83 system_info_.Cpu.X86CpuInfo.VersionInformation = version;
84 system_info_.Cpu.X86CpuInfo.FeatureInformation = features;
85 }
86
87 void MinidumpSystemInfoWriter::SetCPUX86AMDExtendedFeatures(
88 uint32_t extended_features) {
89 DCHECK_EQ(state(), kStateMutable);
90 DCHECK(system_info_.ProcessorArchitecture == kMinidumpCPUArchitectureX86 ||
91 system_info_.ProcessorArchitecture ==
92 kMinidumpCPUArchitectureX86Win64);
93 DCHECK(system_info_.Cpu.X86CpuInfo.VendorId[0] == 'htuA' &&
94 system_info_.Cpu.X86CpuInfo.VendorId[1] == 'itne' &&
95 system_info_.Cpu.X86CpuInfo.VendorId[2] == 'DMAc');
96
97 system_info_.Cpu.X86CpuInfo.AMDExtendedCpuFeatures = extended_features;
98 }
99
100 void MinidumpSystemInfoWriter::SetCPUOtherFeatures(uint64_t features_0,
101 uint64_t features_1) {
102 DCHECK_EQ(state(), kStateMutable);
103 DCHECK(system_info_.ProcessorArchitecture != kMinidumpCPUArchitectureX86 &&
104 system_info_.ProcessorArchitecture !=
105 kMinidumpCPUArchitectureX86Win64);
106
107 COMPILE_ASSERT(
108 arraysize(system_info_.Cpu.OtherCpuInfo.ProcessorFeatures) == 2,
109 processor_features_must_have_2_elements);
110
111 system_info_.Cpu.OtherCpuInfo.ProcessorFeatures[0] = features_0;
112 system_info_.Cpu.OtherCpuInfo.ProcessorFeatures[1] = features_1;
113 }
114
115 bool MinidumpSystemInfoWriter::Freeze() {
116 DCHECK_EQ(state(), kStateMutable);
117
118 if (!MinidumpStreamWriter::Freeze()) {
119 return false;
120 }
121
122 CHECK(csd_version_);
123
124 csd_version_->RegisterRVA(&system_info_.CSDVersionRva);
125
126 return true;
127 }
128
129 size_t MinidumpSystemInfoWriter::SizeOfObject() {
130 DCHECK_GE(state(), kStateFrozen);
131
132 return sizeof(system_info_);
133 }
134
135 std::vector<internal::MinidumpWritable*> MinidumpSystemInfoWriter::Children() {
136 DCHECK_GE(state(), kStateFrozen);
137 DCHECK(csd_version_);
138
139 std::vector<MinidumpWritable*> children(1, csd_version_.get());
Robert Sesek 2014/08/06 17:35:46 Could you use a C++11 initializer list here? http
Mark Mentovai 2014/08/06 18:14:02 rsesek wrote:
140 return children;
141 }
142
143 bool MinidumpSystemInfoWriter::WriteObject(FileWriterInterface* file_writer) {
144 DCHECK_EQ(state(), kStateWritable);
145
146 return file_writer->Write(&system_info_, sizeof(system_info_));
147 }
148
149 MinidumpStreamType MinidumpSystemInfoWriter::StreamType() const {
150 return kMinidumpStreamTypeSystemInfo;
151 }
152
153 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698