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

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

Issue 1126413008: win: Implement exception snapshot (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes2 Created 5 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
« 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
(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 "snapshot/win/exception_snapshot_win.h"
16
17 #include "snapshot/win/cpu_context_win.h"
18 #include "snapshot/win/process_reader_win.h"
19 #include "util/win/nt_internals.h"
20 #include "util/win/process_structs.h"
21
22 namespace crashpad {
23 namespace internal {
24
25 ExceptionSnapshotWin::ExceptionSnapshotWin()
26 : ExceptionSnapshot(),
27 context_union_(),
28 context_(),
29 codes_(),
30 thread_id_(0),
31 exception_address_(0),
32 exception_flags_(0),
33 exception_code_(0),
34 initialized_() {
35 }
36
37 ExceptionSnapshotWin::~ExceptionSnapshotWin() {
38 }
39
40 bool ExceptionSnapshotWin::Initialize(ProcessReaderWin* process_reader,
41 DWORD thread_id,
42 WinVMAddress exception_pointers_address) {
43 INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
44
45 bool found_thread = false;
46 for (const auto& loop_thread : process_reader->Threads()) {
47 if (thread_id == loop_thread.id) {
48 found_thread = true;
49 break;
50 }
51 }
52
53 if (!found_thread) {
54 LOG(ERROR) << "thread ID " << thread_id << "not found in process";
55 return false;
56 } else {
57 thread_id_ = thread_id;
58 }
59
60 EXCEPTION_POINTERS exception_pointers;
61 if (!process_reader->ReadMemory(exception_pointers_address,
62 sizeof(EXCEPTION_POINTERS),
63 &exception_pointers)) {
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
72 if (process_reader->Is64Bit()) {
73 EXCEPTION_RECORD64 first_record;
74 if (!process_reader->ReadMemory(
75 reinterpret_cast<WinVMAddress>(exception_pointers.ExceptionRecord),
76 sizeof(first_record),
77 &first_record)) {
78 LOG(ERROR) << "ExceptionRecord";
79 return false;
80 }
81 exception_code_ = first_record.ExceptionCode;
82 exception_flags_ = first_record.ExceptionFlags;
83 exception_address_ = first_record.ExceptionAddress;
84 for (DWORD i = 0; i < first_record.NumberParameters; ++i)
85 codes_.push_back(first_record.ExceptionInformation[i]);
86 if (first_record.ExceptionRecord) {
87 // https://code.google.com/p/crashpad/issues/detail?id=43
88 LOG(WARNING) << "dropping chained ExceptionRecord";
89 }
90
91 context_.architecture = kCPUArchitectureX86_64;
92 context_.x86_64 = &context_union_.x86_64;
93 // We assume 64-on-64 here in that we're relying on the CONTEXT definition
94 // to be the x64 one.
95 CONTEXT context_record;
96 if (!process_reader->ReadMemory(
97 reinterpret_cast<WinVMAddress>(exception_pointers.ContextRecord),
98 sizeof(context_record),
99 &context_record)) {
100 LOG(ERROR) << "ContextRecord";
101 return false;
102 }
103 InitializeX64Context(context_record, context_.x86_64);
104 } else {
105 CHECK(false) << "TODO(scottmg) x86";
106 return false;
107 }
108
109 INITIALIZATION_STATE_SET_VALID(initialized_);
110 return true;
111 }
112
113 const CPUContext* ExceptionSnapshotWin::Context() const {
114 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
115 return &context_;
116 }
117
118 uint64_t ExceptionSnapshotWin::ThreadID() const {
119 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
120 return thread_id_;
121 }
122
123 uint32_t ExceptionSnapshotWin::Exception() const {
124 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
125 return exception_code_;
126 }
127
128 uint32_t ExceptionSnapshotWin::ExceptionInfo() const {
129 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
130 return exception_flags_;
131 }
132
133 uint64_t ExceptionSnapshotWin::ExceptionAddress() const {
134 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
135 return exception_address_;
136 }
137
138 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const {
139 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
140 return codes_;
141 }
142
143 } // namespace internal
144 } // 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