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

Side by Side Diff: snapshot/win/exception_snapshot_win.cc

Issue 1349313003: win: support x64 reading x86 (wow64) (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: mac Created 5 years, 3 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
« no previous file with comments | « snapshot/win/exception_snapshot_win.h ('k') | snapshot/win/exception_snapshot_win_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 #if defined(ARCH_CPU_32_BITS)
61 if (!process_reader->ReadMemory(exception_pointers_address, 60 const bool is_64_bit = false;
62 sizeof(EXCEPTION_POINTERS), 61 using Context32 = CONTEXT;
63 &exception_pointers)) { 62 #elif defined(ARCH_CPU_64_BITS)
64 LOG(ERROR) << "EXCEPTION_POINTERS read failed"; 63 const bool is_64_bit = process_reader->Is64Bit();
65 return false; 64 using Context32 = WOW64_CONTEXT;
66 } 65 if (is_64_bit) {
67 if (!exception_pointers.ExceptionRecord) {
68 LOG(ERROR) << "null ExceptionRecord";
69 return false;
70 }
71
72 #if defined(ARCH_CPU_64_BITS)
73 if (process_reader->Is64Bit()) {
74 CONTEXT context_record; 66 CONTEXT context_record;
75 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD64>( 67 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD64,
76 *process_reader, exception_pointers, &context_record)) { 68 process_types::EXCEPTION_POINTERS64>(
69 *process_reader, exception_pointers_address, &context_record)) {
77 return false; 70 return false;
78 } 71 }
79 context_.architecture = kCPUArchitectureX86_64; 72 context_.architecture = kCPUArchitectureX86_64;
80 context_.x86_64 = &context_union_.x86_64; 73 context_.x86_64 = &context_union_.x86_64;
81 InitializeX64Context(context_record, context_.x86_64); 74 InitializeX64Context(context_record, context_.x86_64);
82 } else {
83 CHECK(false) << "TODO(scottmg) WOW64";
84 return false;
85 } 75 }
86 #else 76 #endif
87 CONTEXT context_record; 77 if (!is_64_bit) {
88 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD32>( 78 Context32 context_record;
89 *process_reader, exception_pointers, &context_record)) { 79 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD32,
90 return false; 80 process_types::EXCEPTION_POINTERS32>(
81 *process_reader, exception_pointers_address, &context_record)) {
82 return false;
83 }
84 context_.architecture = kCPUArchitectureX86;
85 context_.x86 = &context_union_.x86;
86 InitializeX86Context(context_record, context_.x86);
91 } 87 }
92 context_.architecture = kCPUArchitectureX86;
93 context_.x86 = &context_union_.x86;
94 InitializeX86Context(context_record, context_.x86);
95 #endif // ARCH_CPU_64_BITS
96 88
97 INITIALIZATION_STATE_SET_VALID(initialized_); 89 INITIALIZATION_STATE_SET_VALID(initialized_);
98 return true; 90 return true;
99 } 91 }
100 92
101 const CPUContext* ExceptionSnapshotWin::Context() const { 93 const CPUContext* ExceptionSnapshotWin::Context() const {
102 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 94 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
103 return &context_; 95 return &context_;
104 } 96 }
105 97
(...skipping 15 matching lines...) Expand all
121 uint64_t ExceptionSnapshotWin::ExceptionAddress() const { 113 uint64_t ExceptionSnapshotWin::ExceptionAddress() const {
122 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 114 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
123 return exception_address_; 115 return exception_address_;
124 } 116 }
125 117
126 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const { 118 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const {
127 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 119 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
128 return codes_; 120 return codes_;
129 } 121 }
130 122
131 template <class ExceptionRecordType, class ContextType> 123 template <class ExceptionRecordType,
124 class ExceptionPointersType,
125 class ContextType>
132 bool ExceptionSnapshotWin::InitializeFromExceptionPointers( 126 bool ExceptionSnapshotWin::InitializeFromExceptionPointers(
133 const ProcessReaderWin& process_reader, 127 const ProcessReaderWin& process_reader,
134 const EXCEPTION_POINTERS& exception_pointers, 128 WinVMAddress exception_pointers_address,
135 ContextType* context_record) { 129 ContextType* context_record) {
130 ExceptionPointersType exception_pointers;
131 if (!process_reader.ReadMemory(exception_pointers_address,
132 sizeof(exception_pointers),
133 &exception_pointers)) {
134 LOG(ERROR) << "EXCEPTION_POINTERS read failed";
135 return false;
136 }
137 if (!exception_pointers.ExceptionRecord) {
138 LOG(ERROR) << "null ExceptionRecord";
139 return false;
140 }
141
136 ExceptionRecordType first_record; 142 ExceptionRecordType first_record;
137 if (!process_reader.ReadMemory( 143 if (!process_reader.ReadMemory(
138 reinterpret_cast<WinVMAddress>(exception_pointers.ExceptionRecord), 144 static_cast<WinVMAddress>(exception_pointers.ExceptionRecord),
139 sizeof(first_record), 145 sizeof(first_record),
140 &first_record)) { 146 &first_record)) {
141 LOG(ERROR) << "ExceptionRecord"; 147 LOG(ERROR) << "ExceptionRecord";
142 return false; 148 return false;
143 } 149 }
144 exception_code_ = first_record.ExceptionCode; 150 exception_code_ = first_record.ExceptionCode;
145 exception_flags_ = first_record.ExceptionFlags; 151 exception_flags_ = first_record.ExceptionFlags;
146 exception_address_ = first_record.ExceptionAddress; 152 exception_address_ = first_record.ExceptionAddress;
147 for (DWORD i = 0; i < first_record.NumberParameters; ++i) 153 for (DWORD i = 0; i < first_record.NumberParameters; ++i)
148 codes_.push_back(first_record.ExceptionInformation[i]); 154 codes_.push_back(first_record.ExceptionInformation[i]);
149 if (first_record.ExceptionRecord) { 155 if (first_record.ExceptionRecord) {
150 // https://code.google.com/p/crashpad/issues/detail?id=43 156 // https://code.google.com/p/crashpad/issues/detail?id=43
151 LOG(WARNING) << "dropping chained ExceptionRecord"; 157 LOG(WARNING) << "dropping chained ExceptionRecord";
152 } 158 }
153 159
154 if (!process_reader.ReadMemory( 160 if (!process_reader.ReadMemory(
155 reinterpret_cast<WinVMAddress>(exception_pointers.ContextRecord), 161 static_cast<WinVMAddress>(exception_pointers.ContextRecord),
156 sizeof(*context_record), 162 sizeof(*context_record),
157 context_record)) { 163 context_record)) {
158 LOG(ERROR) << "ContextRecord"; 164 LOG(ERROR) << "ContextRecord";
159 return false; 165 return false;
160 } 166 }
161 167
162 return true; 168 return true;
163 } 169 }
164 170
165 } // namespace internal 171 } // namespace internal
166 } // namespace crashpad 172 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/exception_snapshot_win.h ('k') | snapshot/win/exception_snapshot_win_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698