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

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: . Created 5 years, 7 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 namespace {
26
cpu_(ooo_6.6-7.5) 2015/05/15 01:24:13 I must mention this somewhere but unrelated to thi
scottmg 2015/08/18 05:08:40 Noted. I tried to use PLOG/LOG correctly, it's pos
27 // ::GetThreadId is not available on XP, so get the thread id via
28 // NtQueryInformationThread.
29 template <class Traits>
30 uint64_t GetThreadId(HANDLE handle) {
31 process_types::THREAD_BASIC_INFORMATION<Traits> basic_information;
32 if (!NT_SUCCESS(crashpad::NtQueryInformationThread(
33 handle,
34 static_cast<THREADINFOCLASS>(ThreadBasicInformation),
35 &basic_information,
36 sizeof(basic_information),
37 nullptr))) {
38 LOG(ERROR) << "could not retrieve ThreadBasicInformation";
39 return 0;
40 }
41 return basic_information.ClientId.UniqueThread;
cpu_(ooo_6.6-7.5) 2015/05/15 01:24:12 is it really the same as ::GetThreadId() ? I mean
scottmg 2015/08/18 05:08:40 It is by testing (and ProcessHacker-ing, and it's
42 }
43
44 uint64_t GetThreadId(ProcessReaderWin* process_reader, HANDLE handle) {
45 if (process_reader->Is64Bit())
46 return GetThreadId<process_types::internal::Traits64>(handle);
47 else
48 return GetThreadId<process_types::internal::Traits32>(handle);
49 }
50
51 } // namespace
52
53 ExceptionSnapshotWin::ExceptionSnapshotWin()
54 : ExceptionSnapshot(),
55 context_union_(),
56 context_(),
57 codes_(),
58 thread_id_(0),
59 exception_address_(0),
60 exception_flags_(0),
61 exception_(0),
62 initialized_() {
63 }
64
65 ExceptionSnapshotWin::~ExceptionSnapshotWin() {
66 }
67
68 bool ExceptionSnapshotWin::Initialize(ProcessReaderWin* process_reader,
69 HANDLE thread_handle,
70 EXCEPTION_POINTERS* exception_pointers) {
71 INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
72 DCHECK(exception_pointers);
73 if (!exception_pointers->ExceptionRecord) {
74 LOG(WARNING) << "null ExceptionRecord";
75 return false;
76 }
77 const EXCEPTION_RECORD& first_record = *exception_pointers->ExceptionRecord;
78 exception_ = first_record.ExceptionCode;
79 exception_flags_ = first_record.ExceptionFlags;
80 exception_address_ =
81 reinterpret_cast<uint64_t>(first_record.ExceptionAddress);
82 for (DWORD i = 0; i < first_record.NumberParameters; ++i)
83 codes_.push_back(first_record.ExceptionInformation[i]);
84
85 thread_id_ = GetThreadId(process_reader, thread_handle);
86
87 bool found_thread = false;
88 for (const auto& loop_thread : process_reader->Threads()) {
89 if (thread_id_ == loop_thread.id) {
90 found_thread = true;
91 break;
92 }
93 }
94
95 if (!found_thread) {
96 LOG(ERROR) << "thread_handle not found in process";
97 return false;
98 }
99
100 #if defined(ARCH_CPU_X86_FAMILY)
101 if (process_reader->Is64Bit()) {
102 context_.architecture = kCPUArchitectureX86_64;
103 context_.x86_64 = &context_union_.x86_64;
104 InitializeX64Context(*exception_pointers->ContextRecord, context_.x86_64);
105 } else {
106 context_.architecture = kCPUArchitectureX86;
107 context_.x86 = &context_union_.x86;
108 InitializeX86Context(*exception_pointers->ContextRecord, context_.x86);
109 }
110 #endif
111
112 if (first_record.ExceptionRecord)
113 LOG(WARNING) << "dropping chained ExceptionRecord";
114
115 INITIALIZATION_STATE_SET_VALID(initialized_);
116 return true;
117 }
118
119 const CPUContext* ExceptionSnapshotWin::Context() const {
120 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
121 return &context_;
122 }
123
124 uint64_t ExceptionSnapshotWin::ThreadID() const {
125 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
126 return thread_id_;
127 }
128
129 uint32_t ExceptionSnapshotWin::Exception() const {
130 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
131 return exception_;
132 }
133
134 uint32_t ExceptionSnapshotWin::ExceptionInfo() const {
135 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
136 return exception_flags_;
137 }
138
139 uint64_t ExceptionSnapshotWin::ExceptionAddress() const {
140 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
141 return exception_address_;
142 }
143
144 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const {
145 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
146 return codes_;
147 }
148
149 } // namespace internal
150 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698