| OLD | NEW |
| (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/thread_snapshot_win.h" |
| 16 |
| 17 #include <vector> |
| 18 |
| 19 #include "base/logging.h" |
| 20 #include "snapshot/win/cpu_context_win.h" |
| 21 #include "snapshot/win/process_reader_win.h" |
| 22 |
| 23 namespace crashpad { |
| 24 namespace internal { |
| 25 |
| 26 ThreadSnapshotWin::ThreadSnapshotWin() |
| 27 : ThreadSnapshot(), |
| 28 context_(), |
| 29 stack_(), |
| 30 teb_(), |
| 31 thread_(), |
| 32 initialized_() { |
| 33 } |
| 34 |
| 35 ThreadSnapshotWin::~ThreadSnapshotWin() { |
| 36 } |
| 37 |
| 38 bool ThreadSnapshotWin::Initialize( |
| 39 ProcessReaderWin* process_reader, |
| 40 const ProcessReaderWin::Thread& process_reader_thread) { |
| 41 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
| 42 |
| 43 thread_ = process_reader_thread; |
| 44 if (process_reader->GetProcessInfo().LoggingRangeIsFullyReadable( |
| 45 CheckedRange<WinVMAddress, WinVMSize>(thread_.stack_region_address, |
| 46 thread_.stack_region_size))) { |
| 47 stack_.Initialize(process_reader, |
| 48 thread_.stack_region_address, |
| 49 thread_.stack_region_size); |
| 50 } else { |
| 51 stack_.Initialize(process_reader, 0, 0); |
| 52 } |
| 53 |
| 54 if (process_reader->GetProcessInfo().LoggingRangeIsFullyReadable( |
| 55 CheckedRange<WinVMAddress, WinVMSize>(thread_.teb_address, |
| 56 thread_.teb_size))) { |
| 57 teb_.Initialize(process_reader, thread_.teb_address, thread_.teb_size); |
| 58 } else { |
| 59 teb_.Initialize(process_reader, 0, 0); |
| 60 } |
| 61 |
| 62 #if defined(ARCH_CPU_X86_64) |
| 63 if (process_reader->Is64Bit()) { |
| 64 context_.architecture = kCPUArchitectureX86_64; |
| 65 context_.x86_64 = &context_union_.x86_64; |
| 66 InitializeX64Context(process_reader_thread.context.native, context_.x86_64); |
| 67 } else { |
| 68 context_.architecture = kCPUArchitectureX86; |
| 69 context_.x86 = &context_union_.x86; |
| 70 InitializeX86Context(process_reader_thread.context.wow64, context_.x86); |
| 71 } |
| 72 #else |
| 73 context_.architecture = kCPUArchitectureX86; |
| 74 context_.x86 = &context_union_.x86; |
| 75 InitializeX86Context(process_reader_thread.context.native, context_.x86); |
| 76 #endif // ARCH_CPU_X86_64 |
| 77 |
| 78 INITIALIZATION_STATE_SET_VALID(initialized_); |
| 79 return true; |
| 80 } |
| 81 |
| 82 const CPUContext* ThreadSnapshotWin::Context() const { |
| 83 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 84 return &context_; |
| 85 } |
| 86 |
| 87 const MemorySnapshot* ThreadSnapshotWin::Stack() const { |
| 88 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 89 return &stack_; |
| 90 } |
| 91 |
| 92 uint64_t ThreadSnapshotWin::ThreadID() const { |
| 93 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 94 return thread_.id; |
| 95 } |
| 96 |
| 97 int ThreadSnapshotWin::SuspendCount() const { |
| 98 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 99 return thread_.suspend_count; |
| 100 } |
| 101 |
| 102 int ThreadSnapshotWin::Priority() const { |
| 103 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 104 return thread_.priority; |
| 105 } |
| 106 |
| 107 uint64_t ThreadSnapshotWin::ThreadSpecificDataAddress() const { |
| 108 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 109 return thread_.teb_address; |
| 110 } |
| 111 |
| 112 std::vector<const MemorySnapshot*> ThreadSnapshotWin::ExtraMemory() const { |
| 113 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 114 // TODO(scottmg): Ensure this region is readable, and make sure we don't |
| 115 // discard the entire dump if it isn't. https://crashpad.chromium.org/bug/59 |
| 116 return std::vector<const MemorySnapshot*>(1, &teb_); |
| 117 } |
| 118 |
| 119 } // namespace internal |
| 120 } // namespace crashpad |
| OLD | NEW |