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

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: fixes 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
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 LOG(WARNING) << "dropping chained ExceptionRecord";
Mark Mentovai 2015/08/18 17:52:13 Do we care? All we’d want to do at this point is f
scottmg 2015/08/18 18:18:21 I'm not familiar enough with nested exceptions to
88
89 context_.architecture = kCPUArchitectureX86_64;
90 context_.x86_64 = &context_union_.x86_64;
91 // We assume 64-on-64 here in that we're relying on the CONTEXT definition
92 // to be the x64 one.
93 CONTEXT context_record;
94 if (!process_reader->ReadMemory(
95 reinterpret_cast<WinVMAddress>(exception_pointers.ContextRecord),
96 sizeof(context_record),
97 &context_record)) {
98 LOG(ERROR) << "ContextRecord";
99 return false;
100 }
101 InitializeX64Context(context_record, context_.x86_64);
102 } else {
103 CHECK(false) << "TODO(scottmg) x86";
104 return false;
105 }
106
107 INITIALIZATION_STATE_SET_VALID(initialized_);
108 return true;
109 }
110
111 const CPUContext* ExceptionSnapshotWin::Context() const {
112 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
113 return &context_;
114 }
115
116 uint64_t ExceptionSnapshotWin::ThreadID() const {
117 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
118 return thread_id_;
119 }
120
121 uint32_t ExceptionSnapshotWin::Exception() const {
122 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
123 return exception_code_;
124 }
125
126 uint32_t ExceptionSnapshotWin::ExceptionInfo() const {
127 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
128 return exception_flags_;
129 }
130
131 uint64_t ExceptionSnapshotWin::ExceptionAddress() const {
132 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
133 return exception_address_;
134 }
135
136 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const {
137 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
138 return codes_;
139 }
140
141 } // namespace internal
142 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698