OLD | NEW |
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/thread_snapshot_win.h" | 15 #include "snapshot/win/thread_snapshot_win.h" |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "snapshot/win/process_reader_win.h" | 18 #include "snapshot/win/process_reader_win.h" |
19 | 19 |
20 namespace crashpad { | 20 namespace crashpad { |
21 namespace internal { | 21 namespace internal { |
22 | 22 |
| 23 namespace { |
| 24 |
| 25 void InitializeX64Context(const CONTEXT& context, |
| 26 CPUContextX86_64* out) { |
| 27 out->rax = context.Rax; |
| 28 out->rbx = context.Rbx; |
| 29 out->rcx = context.Rcx; |
| 30 out->rdx = context.Rdx; |
| 31 out->rdi = context.Rdi; |
| 32 out->rsi = context.Rsi; |
| 33 out->rbp = context.Rbp; |
| 34 out->rsp = context.Rsp; |
| 35 out->r8 = context.R8; |
| 36 out->r9 = context.R9; |
| 37 out->r10 = context.R10; |
| 38 out->r11 = context.R11; |
| 39 out->r12 = context.R12; |
| 40 out->r13 = context.R13; |
| 41 out->r14 = context.R14; |
| 42 out->r15 = context.R15; |
| 43 out->rip = context.Rip; |
| 44 out->rflags = context.EFlags; |
| 45 out->cs = context.SegCs; |
| 46 out->fs = context.SegFs; |
| 47 out->gs = context.SegGs; |
| 48 |
| 49 out->dr0 = context.Dr0; |
| 50 out->dr1 = context.Dr1; |
| 51 out->dr2 = context.Dr2; |
| 52 out->dr3 = context.Dr3; |
| 53 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see |
| 54 // http://en.wikipedia.org/wiki/X86_debug_register. |
| 55 out->dr4 = context.Dr6; |
| 56 out->dr5 = context.Dr7; |
| 57 out->dr6 = context.Dr6; |
| 58 out->dr7 = context.Dr7; |
| 59 |
| 60 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave), |
| 61 "types must be equivalent"); |
| 62 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave)); |
| 63 } |
| 64 |
| 65 void InitializeX86Context(const CONTEXT& context, |
| 66 CPUContextX86* out) { |
| 67 CHECK(false) << "TODO(scottmg) InitializeX86Context()"; |
| 68 } |
| 69 |
| 70 } // namespace |
| 71 |
23 ThreadSnapshotWin::ThreadSnapshotWin() | 72 ThreadSnapshotWin::ThreadSnapshotWin() |
24 : ThreadSnapshot(), context_(), stack_(), thread_(), initialized_() { | 73 : ThreadSnapshot(), context_(), stack_(), thread_(), initialized_() { |
25 } | 74 } |
26 | 75 |
27 ThreadSnapshotWin::~ThreadSnapshotWin() { | 76 ThreadSnapshotWin::~ThreadSnapshotWin() { |
28 } | 77 } |
29 | 78 |
30 bool ThreadSnapshotWin::Initialize( | 79 bool ThreadSnapshotWin::Initialize( |
31 ProcessReaderWin* process_reader, | 80 ProcessReaderWin* process_reader, |
32 const ProcessReaderWin::Thread& process_reader_thread) { | 81 const ProcessReaderWin::Thread& process_reader_thread) { |
33 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 82 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
34 | 83 |
35 thread_ = process_reader_thread; | 84 thread_ = process_reader_thread; |
36 stack_.Initialize( | 85 stack_.Initialize( |
37 process_reader, thread_.stack_region_address, thread_.stack_region_size); | 86 process_reader, thread_.stack_region_address, thread_.stack_region_size); |
38 | 87 |
| 88 #if defined(ARCH_CPU_X86_FAMILY) |
| 89 if (process_reader->Is64Bit()) { |
| 90 context_.architecture = kCPUArchitectureX86_64; |
| 91 context_.x86_64 = &context_union_.x86_64; |
| 92 InitializeX64Context(process_reader_thread.context, context_.x86_64); |
| 93 } else { |
| 94 context_.architecture = kCPUArchitectureX86; |
| 95 context_.x86 = &context_union_.x86; |
| 96 InitializeX86Context(process_reader_thread.context, context_.x86); |
| 97 } |
| 98 #endif |
| 99 |
39 INITIALIZATION_STATE_SET_VALID(initialized_); | 100 INITIALIZATION_STATE_SET_VALID(initialized_); |
40 return true; | 101 return true; |
41 } | 102 } |
42 | 103 |
43 const CPUContext* ThreadSnapshotWin::Context() const { | 104 const CPUContext* ThreadSnapshotWin::Context() const { |
44 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 105 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
45 LOG(ERROR) << "TODO(scottmg): CPUContext"; | |
46 return &context_; | 106 return &context_; |
47 } | 107 } |
48 | 108 |
49 const MemorySnapshot* ThreadSnapshotWin::Stack() const { | 109 const MemorySnapshot* ThreadSnapshotWin::Stack() const { |
50 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 110 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
51 return &stack_; | 111 return &stack_; |
52 } | 112 } |
53 | 113 |
54 uint64_t ThreadSnapshotWin::ThreadID() const { | 114 uint64_t ThreadSnapshotWin::ThreadID() const { |
55 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 115 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
(...skipping 10 matching lines...) Expand all Loading... |
66 return thread_.priority; | 126 return thread_.priority; |
67 } | 127 } |
68 | 128 |
69 uint64_t ThreadSnapshotWin::ThreadSpecificDataAddress() const { | 129 uint64_t ThreadSnapshotWin::ThreadSpecificDataAddress() const { |
70 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 130 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
71 return thread_.teb; | 131 return thread_.teb; |
72 } | 132 } |
73 | 133 |
74 } // namespace internal | 134 } // namespace internal |
75 } // namespace crashpad | 135 } // namespace crashpad |
OLD | NEW |