OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/process_snapshot_mac.h" | |
16 | |
17 namespace crashpad { | |
18 | |
19 ProcessSnapshotMac::ProcessSnapshotMac() | |
20 : ProcessSnapshot(), | |
21 system_(), | |
22 threads_(), | |
23 modules_(), | |
24 exception_(), | |
25 process_reader_(), | |
26 snapshot_time_(), | |
27 initialized_() { | |
28 } | |
29 | |
30 ProcessSnapshotMac::~ProcessSnapshotMac() { | |
31 } | |
32 | |
33 bool ProcessSnapshotMac::Initialize(task_t task) { | |
34 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | |
35 | |
36 if (gettimeofday(&snapshot_time_, nullptr) != 0) { | |
37 PLOG(ERROR) << "gettimeofday"; | |
38 return false; | |
39 } | |
40 | |
41 if (!process_reader_.Initialize(task)) { | |
42 return false; | |
43 } | |
44 | |
45 system_.Initialize(&process_reader_, &snapshot_time_); | |
46 | |
47 InitializeThreads(); | |
48 InitializeModules(); | |
49 | |
50 INITIALIZATION_STATE_SET_VALID(initialized_); | |
51 return true; | |
52 } | |
53 | |
54 void ProcessSnapshotMac::InitializeException( | |
55 thread_t exception_thread, | |
56 exception_type_t exception, | |
57 const mach_exception_data_type_t* code, | |
58 mach_msg_type_number_t code_count, | |
59 thread_state_flavor_t flavor, | |
60 const natural_t* state, | |
61 mach_msg_type_number_t state_count) { | |
62 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
63 | |
64 exception_.reset(new internal::ExceptionSnapshotMac()); | |
65 if (!exception_->Initialize(&process_reader_, | |
Robert Sesek
2014/10/15 20:53:05
You could report the result out of this method, to
| |
66 exception_thread, | |
67 exception, | |
68 code, | |
69 code_count, | |
70 flavor, | |
71 state, | |
72 state_count)) { | |
73 exception_.reset(); | |
74 } | |
75 } | |
76 | |
77 pid_t ProcessSnapshotMac::ProcessID() const { | |
78 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
79 return process_reader_.ProcessID(); | |
80 } | |
81 | |
82 pid_t ProcessSnapshotMac::ParentProcessID() const { | |
83 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
84 return process_reader_.ProcessID(); | |
85 } | |
86 | |
87 void ProcessSnapshotMac::SnapshotTime(timeval* snapshot_time) const { | |
88 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
89 *snapshot_time = snapshot_time_; | |
90 } | |
91 | |
92 void ProcessSnapshotMac::ProcessStartTime(timeval* start_time) const { | |
93 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
94 process_reader_.StartTime(start_time); | |
95 } | |
96 | |
97 void ProcessSnapshotMac::ProcessCPUTimes(timeval* user_time, | |
98 timeval* system_time) const { | |
99 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
100 process_reader_.CPUTimes(user_time, system_time); | |
101 } | |
102 | |
103 const SystemSnapshot* ProcessSnapshotMac::System() const { | |
104 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
105 return &system_; | |
106 } | |
107 | |
108 std::vector<const ThreadSnapshot*> ProcessSnapshotMac::Threads() const { | |
109 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
110 std::vector<const ThreadSnapshot*> threads; | |
111 for (internal::ThreadSnapshotMac* thread : threads_) { | |
Robert Sesek
2014/10/15 20:53:05
You could use more auto here and in the loops belo
Mark Mentovai
2014/10/15 21:36:21
Robert Sesek wrote:
Robert Sesek
2014/10/15 22:35:50
I figured that's why you didn't, which is why I ph
| |
112 threads.push_back(thread); | |
113 } | |
114 return threads; | |
115 } | |
116 | |
117 std::vector<const ModuleSnapshot*> ProcessSnapshotMac::Modules() const { | |
118 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
119 std::vector<const ModuleSnapshot*> modules; | |
120 for (internal::ModuleSnapshotMac* module : modules_) { | |
121 modules.push_back(module); | |
122 } | |
123 return modules; | |
124 } | |
125 | |
126 const ExceptionSnapshot* ProcessSnapshotMac::Exception() const { | |
127 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
128 return exception_.get(); | |
129 } | |
130 | |
131 void ProcessSnapshotMac::InitializeThreads() { | |
132 const std::vector<ProcessReader::Thread>& process_reader_threads = | |
133 process_reader_.Threads(); | |
134 for (const ProcessReader::Thread& process_reader_thread : | |
135 process_reader_threads) { | |
136 internal::ThreadSnapshotMac* thread = new internal::ThreadSnapshotMac(); | |
137 threads_.push_back(thread); | |
138 if (!thread->Initialize(&process_reader_, process_reader_thread)) { | |
139 threads_.pop_back(); | |
140 } | |
141 } | |
142 } | |
143 | |
144 void ProcessSnapshotMac::InitializeModules() { | |
145 const std::vector<ProcessReader::Module>& process_reader_modules = | |
146 process_reader_.Modules(); | |
147 for (const ProcessReader::Module& process_reader_module : | |
148 process_reader_modules) { | |
149 internal::ModuleSnapshotMac* module = new internal::ModuleSnapshotMac(); | |
150 modules_.push_back(module); | |
151 if (!module->Initialize(&process_reader_, process_reader_module)) { | |
152 modules_.pop_back(); | |
153 } | |
154 } | |
155 } | |
156 | |
157 } // namespace crashpad | |
OLD | NEW |