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

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

Issue 1533183002: win: Capture some memory pointed at by context (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: mac Created 4 years, 11 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/thread_snapshot_win.h » ('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/memory_snapshot.h"
18 #include "snapshot/win/capture_context_memory.h"
17 #include "snapshot/win/cpu_context_win.h" 19 #include "snapshot/win/cpu_context_win.h"
20 #include "snapshot/win/memory_snapshot_win.h"
18 #include "snapshot/win/process_reader_win.h" 21 #include "snapshot/win/process_reader_win.h"
19 #include "util/win/nt_internals.h" 22 #include "util/win/nt_internals.h"
20 23
21 namespace crashpad { 24 namespace crashpad {
22 namespace internal { 25 namespace internal {
23 26
24 ExceptionSnapshotWin::ExceptionSnapshotWin() 27 ExceptionSnapshotWin::ExceptionSnapshotWin()
25 : ExceptionSnapshot(), 28 : ExceptionSnapshot(),
26 context_union_(), 29 context_union_(),
27 context_(), 30 context_(),
28 codes_(), 31 codes_(),
29 thread_id_(0), 32 thread_id_(0),
30 exception_address_(0), 33 exception_address_(0),
31 exception_flags_(0), 34 exception_flags_(0),
32 exception_code_(0), 35 exception_code_(0),
33 initialized_() { 36 initialized_() {
34 } 37 }
35 38
36 ExceptionSnapshotWin::~ExceptionSnapshotWin() { 39 ExceptionSnapshotWin::~ExceptionSnapshotWin() {
37 } 40 }
38 41
39 bool ExceptionSnapshotWin::Initialize(ProcessReaderWin* process_reader, 42 bool ExceptionSnapshotWin::Initialize(ProcessReaderWin* process_reader,
40 DWORD thread_id, 43 DWORD thread_id,
41 WinVMAddress exception_pointers_address) { 44 WinVMAddress exception_pointers_address) {
42 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); 45 INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
43 46
44 bool found_thread = false; 47 const ProcessReaderWin::Thread* thread = nullptr;
45 for (const auto& loop_thread : process_reader->Threads()) { 48 for (const auto& loop_thread : process_reader->Threads()) {
46 if (thread_id == loop_thread.id) { 49 if (thread_id == loop_thread.id) {
47 found_thread = true; 50 thread = &loop_thread;
48 break; 51 break;
49 } 52 }
50 } 53 }
51 54
52 if (!found_thread) { 55 if (!thread) {
53 LOG(ERROR) << "thread ID " << thread_id << " not found in process"; 56 LOG(ERROR) << "thread ID " << thread_id << " not found in process";
54 return false; 57 return false;
55 } else { 58 } else {
56 thread_id_ = thread_id; 59 thread_id_ = thread_id;
57 } 60 }
58 61
59 #if defined(ARCH_CPU_32_BITS) 62 #if defined(ARCH_CPU_32_BITS)
60 const bool is_64_bit = false; 63 const bool is_64_bit = false;
61 using Context32 = CONTEXT; 64 using Context32 = CONTEXT;
62 #elif defined(ARCH_CPU_64_BITS) 65 #elif defined(ARCH_CPU_64_BITS)
(...skipping 16 matching lines...) Expand all
79 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD32, 82 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD32,
80 process_types::EXCEPTION_POINTERS32>( 83 process_types::EXCEPTION_POINTERS32>(
81 *process_reader, exception_pointers_address, &context_record)) { 84 *process_reader, exception_pointers_address, &context_record)) {
82 return false; 85 return false;
83 } 86 }
84 context_.architecture = kCPUArchitectureX86; 87 context_.architecture = kCPUArchitectureX86;
85 context_.x86 = &context_union_.x86; 88 context_.x86 = &context_union_.x86;
86 InitializeX86Context(context_record, context_.x86); 89 InitializeX86Context(context_record, context_.x86);
87 } 90 }
88 91
92 CaptureMemoryPointedToByContext(
93 context_, process_reader, *thread, &extra_memory_);
94
89 INITIALIZATION_STATE_SET_VALID(initialized_); 95 INITIALIZATION_STATE_SET_VALID(initialized_);
90 return true; 96 return true;
91 } 97 }
92 98
93 const CPUContext* ExceptionSnapshotWin::Context() const { 99 const CPUContext* ExceptionSnapshotWin::Context() const {
94 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 100 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
95 return &context_; 101 return &context_;
96 } 102 }
97 103
98 uint64_t ExceptionSnapshotWin::ThreadID() const { 104 uint64_t ExceptionSnapshotWin::ThreadID() const {
(...skipping 14 matching lines...) Expand all
113 uint64_t ExceptionSnapshotWin::ExceptionAddress() const { 119 uint64_t ExceptionSnapshotWin::ExceptionAddress() const {
114 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 120 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
115 return exception_address_; 121 return exception_address_;
116 } 122 }
117 123
118 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const { 124 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const {
119 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 125 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
120 return codes_; 126 return codes_;
121 } 127 }
122 128
129 std::vector<const MemorySnapshot*> ExceptionSnapshotWin::ExtraMemory() const {
130 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
131 std::vector<const MemorySnapshot*> result;
132 result.reserve(extra_memory_.size());
133 for (const auto& em : extra_memory_)
134 result.push_back(em);
135 return result;
136 }
137
123 template <class ExceptionRecordType, 138 template <class ExceptionRecordType,
124 class ExceptionPointersType, 139 class ExceptionPointersType,
125 class ContextType> 140 class ContextType>
126 bool ExceptionSnapshotWin::InitializeFromExceptionPointers( 141 bool ExceptionSnapshotWin::InitializeFromExceptionPointers(
127 const ProcessReaderWin& process_reader, 142 const ProcessReaderWin& process_reader,
128 WinVMAddress exception_pointers_address, 143 WinVMAddress exception_pointers_address,
129 ContextType* context_record) { 144 ContextType* context_record) {
130 ExceptionPointersType exception_pointers; 145 ExceptionPointersType exception_pointers;
131 if (!process_reader.ReadMemory(exception_pointers_address, 146 if (!process_reader.ReadMemory(exception_pointers_address,
132 sizeof(exception_pointers), 147 sizeof(exception_pointers),
(...skipping 30 matching lines...) Expand all
163 context_record)) { 178 context_record)) {
164 LOG(ERROR) << "ContextRecord"; 179 LOG(ERROR) << "ContextRecord";
165 return false; 180 return false;
166 } 181 }
167 182
168 return true; 183 return true;
169 } 184 }
170 185
171 } // namespace internal 186 } // namespace internal
172 } // namespace crashpad 187 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/exception_snapshot_win.h ('k') | snapshot/win/thread_snapshot_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698