OLD | NEW |
---|---|
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "snapshot/win/exception_snapshot_win.h" | 15 #include "snapshot/win/exception_snapshot_win.h" |
16 | 16 |
17 #include "snapshot/win/cpu_context_win.h" | 17 #include "snapshot/win/cpu_context_win.h" |
18 #include "snapshot/win/process_reader_win.h" | 18 #include "snapshot/win/process_reader_win.h" |
19 #include "util/win/nt_internals.h" | 19 #include "util/win/nt_internals.h" |
20 #include "util/win/process_structs.h" | |
21 | 20 |
22 namespace crashpad { | 21 namespace crashpad { |
23 namespace internal { | 22 namespace internal { |
24 | 23 |
25 ExceptionSnapshotWin::ExceptionSnapshotWin() | 24 ExceptionSnapshotWin::ExceptionSnapshotWin() |
26 : ExceptionSnapshot(), | 25 : ExceptionSnapshot(), |
27 context_union_(), | 26 context_union_(), |
28 context_(), | 27 context_(), |
29 codes_(), | 28 codes_(), |
30 thread_id_(0), | 29 thread_id_(0), |
(...skipping 13 matching lines...) Expand all Loading... | |
44 | 43 |
45 bool found_thread = false; | 44 bool found_thread = false; |
46 for (const auto& loop_thread : process_reader->Threads()) { | 45 for (const auto& loop_thread : process_reader->Threads()) { |
47 if (thread_id == loop_thread.id) { | 46 if (thread_id == loop_thread.id) { |
48 found_thread = true; | 47 found_thread = true; |
49 break; | 48 break; |
50 } | 49 } |
51 } | 50 } |
52 | 51 |
53 if (!found_thread) { | 52 if (!found_thread) { |
54 LOG(ERROR) << "thread ID " << thread_id << "not found in process"; | 53 LOG(ERROR) << "thread ID " << thread_id << " not found in process"; |
55 return false; | 54 return false; |
56 } else { | 55 } else { |
57 thread_id_ = thread_id; | 56 thread_id_ = thread_id; |
58 } | 57 } |
59 | 58 |
60 EXCEPTION_POINTERS exception_pointers; | 59 using ExceptionPointers32 = |
61 if (!process_reader->ReadMemory(exception_pointers_address, | 60 process_types::EXCEPTION_POINTERS<process_types::internal::Traits32>; |
62 sizeof(EXCEPTION_POINTERS), | 61 using ExceptionPointers64 = |
Mark Mentovai
2015/09/18 15:44:06
Goes in ARCH_CPU_64_BITS?
scottmg
2015/09/18 19:45:26
I moved them to process_structs because they're ba
| |
63 &exception_pointers)) { | 62 process_types::EXCEPTION_POINTERS<process_types::internal::Traits64>; |
64 LOG(ERROR) << "EXCEPTION_POINTERS read failed"; | |
65 return false; | |
66 } | |
67 if (!exception_pointers.ExceptionRecord) { | |
68 LOG(ERROR) << "null ExceptionRecord"; | |
69 return false; | |
70 } | |
71 | 63 |
72 #if defined(ARCH_CPU_64_BITS) | 64 #if defined(ARCH_CPU_64_BITS) |
73 if (process_reader->Is64Bit()) { | 65 if (process_reader->Is64Bit()) { |
66 ExceptionPointers64 exception_pointers; | |
67 if (!ReadExceptionPointers( | |
68 *process_reader, exception_pointers_address, &exception_pointers)) { | |
69 return false; | |
70 } | |
74 CONTEXT context_record; | 71 CONTEXT context_record; |
75 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD64>( | 72 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD64>( |
76 *process_reader, exception_pointers, &context_record)) { | 73 *process_reader, exception_pointers, &context_record)) { |
77 return false; | 74 return false; |
78 } | 75 } |
79 context_.architecture = kCPUArchitectureX86_64; | 76 context_.architecture = kCPUArchitectureX86_64; |
80 context_.x86_64 = &context_union_.x86_64; | 77 context_.x86_64 = &context_union_.x86_64; |
81 InitializeX64Context(context_record, context_.x86_64); | 78 InitializeX64Context(context_record, context_.x86_64); |
82 } else { | 79 } else { |
83 CHECK(false) << "TODO(scottmg) WOW64"; | 80 ExceptionPointers32 exception_pointers; |
81 if (!ReadExceptionPointers( | |
82 *process_reader, exception_pointers_address, &exception_pointers)) { | |
83 return false; | |
84 } | |
85 if (!CommonX86Initialize<WOW64_CONTEXT>(*process_reader, | |
86 exception_pointers)) { | |
87 return false; | |
88 } | |
89 } | |
90 #else | |
91 ExceptionPointers32 exception_pointers; | |
Mark Mentovai
2015/09/18 15:44:06
It’s only a small amount of duplication, but it’d
scottmg
2015/09/18 19:45:26
Done, and that made it clearer how to collapse the
| |
92 if (!ReadExceptionPointers( | |
93 *process_reader, exception_pointers_address, &exception_pointers)) { | |
84 return false; | 94 return false; |
85 } | 95 } |
86 #else | 96 if (!CommonX86Initialize<CONTEXT>(*process_reader, exception_pointers)) |
87 CONTEXT context_record; | |
88 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD32>( | |
89 *process_reader, exception_pointers, &context_record)) { | |
90 return false; | 97 return false; |
91 } | |
92 context_.architecture = kCPUArchitectureX86; | |
93 context_.x86 = &context_union_.x86; | |
94 InitializeX86Context(context_record, context_.x86); | |
95 #endif // ARCH_CPU_64_BITS | 98 #endif // ARCH_CPU_64_BITS |
96 | 99 |
97 INITIALIZATION_STATE_SET_VALID(initialized_); | 100 INITIALIZATION_STATE_SET_VALID(initialized_); |
98 return true; | 101 return true; |
99 } | 102 } |
100 | 103 |
101 const CPUContext* ExceptionSnapshotWin::Context() const { | 104 const CPUContext* ExceptionSnapshotWin::Context() const { |
102 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 105 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
103 return &context_; | 106 return &context_; |
104 } | 107 } |
(...skipping 16 matching lines...) Expand all Loading... | |
121 uint64_t ExceptionSnapshotWin::ExceptionAddress() const { | 124 uint64_t ExceptionSnapshotWin::ExceptionAddress() const { |
122 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 125 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
123 return exception_address_; | 126 return exception_address_; |
124 } | 127 } |
125 | 128 |
126 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const { | 129 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const { |
127 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 130 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
128 return codes_; | 131 return codes_; |
129 } | 132 } |
130 | 133 |
131 template <class ExceptionRecordType, class ContextType> | 134 template <class ExceptionRecordType, |
135 class ExceptionPointersType, | |
136 class ContextType> | |
132 bool ExceptionSnapshotWin::InitializeFromExceptionPointers( | 137 bool ExceptionSnapshotWin::InitializeFromExceptionPointers( |
133 const ProcessReaderWin& process_reader, | 138 const ProcessReaderWin& process_reader, |
134 const EXCEPTION_POINTERS& exception_pointers, | 139 const ExceptionPointersType& exception_pointers, |
135 ContextType* context_record) { | 140 ContextType* context_record) { |
136 ExceptionRecordType first_record; | 141 ExceptionRecordType first_record; |
137 if (!process_reader.ReadMemory( | 142 if (!process_reader.ReadMemory( |
138 reinterpret_cast<WinVMAddress>(exception_pointers.ExceptionRecord), | 143 static_cast<WinVMAddress>(exception_pointers.ExceptionRecord), |
139 sizeof(first_record), | 144 sizeof(first_record), |
140 &first_record)) { | 145 &first_record)) { |
141 LOG(ERROR) << "ExceptionRecord"; | 146 LOG(ERROR) << "ExceptionRecord"; |
142 return false; | 147 return false; |
143 } | 148 } |
144 exception_code_ = first_record.ExceptionCode; | 149 exception_code_ = first_record.ExceptionCode; |
145 exception_flags_ = first_record.ExceptionFlags; | 150 exception_flags_ = first_record.ExceptionFlags; |
146 exception_address_ = first_record.ExceptionAddress; | 151 exception_address_ = first_record.ExceptionAddress; |
147 for (DWORD i = 0; i < first_record.NumberParameters; ++i) | 152 for (DWORD i = 0; i < first_record.NumberParameters; ++i) |
148 codes_.push_back(first_record.ExceptionInformation[i]); | 153 codes_.push_back(first_record.ExceptionInformation[i]); |
149 if (first_record.ExceptionRecord) { | 154 if (first_record.ExceptionRecord) { |
150 // https://code.google.com/p/crashpad/issues/detail?id=43 | 155 // https://code.google.com/p/crashpad/issues/detail?id=43 |
151 LOG(WARNING) << "dropping chained ExceptionRecord"; | 156 LOG(WARNING) << "dropping chained ExceptionRecord"; |
152 } | 157 } |
153 | 158 |
154 if (!process_reader.ReadMemory( | 159 if (!process_reader.ReadMemory( |
155 reinterpret_cast<WinVMAddress>(exception_pointers.ContextRecord), | 160 static_cast<WinVMAddress>(exception_pointers.ContextRecord), |
156 sizeof(*context_record), | 161 sizeof(*context_record), |
157 context_record)) { | 162 context_record)) { |
158 LOG(ERROR) << "ContextRecord"; | 163 LOG(ERROR) << "ContextRecord"; |
159 return false; | 164 return false; |
160 } | 165 } |
161 | 166 |
162 return true; | 167 return true; |
163 } | 168 } |
164 | 169 |
170 template <class ContextRecordType> | |
171 bool ExceptionSnapshotWin::CommonX86Initialize( | |
172 const ProcessReaderWin& process_reader, | |
173 const process_types::EXCEPTION_POINTERS<process_types::internal::Traits32>& | |
174 exception_pointers) { | |
175 ContextRecordType context_record; | |
176 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD32>( | |
177 process_reader, exception_pointers, &context_record)) { | |
178 return false; | |
179 } | |
180 context_.architecture = kCPUArchitectureX86; | |
181 context_.x86 = &context_union_.x86; | |
182 InitializeX86Context(context_record, context_.x86); | |
183 return true; | |
184 } | |
185 | |
186 template <class ExceptionPointersType> | |
187 bool ExceptionSnapshotWin::ReadExceptionPointers( | |
188 const ProcessReaderWin& process_reader, | |
189 WinVMAddress exception_pointers_address, | |
190 ExceptionPointersType* exception_pointers) { | |
191 if (!process_reader.ReadMemory(exception_pointers_address, | |
192 sizeof(EXCEPTION_POINTERS), | |
193 exception_pointers)) { | |
194 LOG(ERROR) << "EXCEPTION_POINTERS read failed"; | |
195 return false; | |
196 } | |
197 if (!exception_pointers->ExceptionRecord) { | |
198 LOG(ERROR) << "null ExceptionRecord"; | |
199 return false; | |
200 } | |
201 return true; | |
202 } | |
203 | |
165 } // namespace internal | 204 } // namespace internal |
166 } // namespace crashpad | 205 } // namespace crashpad |
OLD | NEW |