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

Side by Side Diff: snapshot/mac/process_snapshot_mac.cc

Issue 650223007: Add ProcessSnapshotMac (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@module_snapshot_mac
Patch Set: Rebase onto master Created 6 years, 2 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
« no previous file with comments | « snapshot/mac/process_snapshot_mac.h ('k') | snapshot/snapshot.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/mac/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 bool 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 DCHECK(!exception_);
64
65 exception_.reset(new internal::ExceptionSnapshotMac());
66 if (!exception_->Initialize(&process_reader_,
67 exception_thread,
68 exception,
69 code,
70 code_count,
71 flavor,
72 state,
73 state_count)) {
74 exception_.reset();
75 return false;
76 }
77
78 return true;
79 }
80
81 pid_t ProcessSnapshotMac::ProcessID() const {
82 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
83 return process_reader_.ProcessID();
84 }
85
86 pid_t ProcessSnapshotMac::ParentProcessID() const {
87 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
88 return process_reader_.ProcessID();
89 }
90
91 void ProcessSnapshotMac::SnapshotTime(timeval* snapshot_time) const {
92 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
93 *snapshot_time = snapshot_time_;
94 }
95
96 void ProcessSnapshotMac::ProcessStartTime(timeval* start_time) const {
97 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
98 process_reader_.StartTime(start_time);
99 }
100
101 void ProcessSnapshotMac::ProcessCPUTimes(timeval* user_time,
102 timeval* system_time) const {
103 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
104 process_reader_.CPUTimes(user_time, system_time);
105 }
106
107 const SystemSnapshot* ProcessSnapshotMac::System() const {
108 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
109 return &system_;
110 }
111
112 std::vector<const ThreadSnapshot*> ProcessSnapshotMac::Threads() const {
113 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
114 std::vector<const ThreadSnapshot*> threads;
115 for (internal::ThreadSnapshotMac* thread : threads_) {
116 threads.push_back(thread);
117 }
118 return threads;
119 }
120
121 std::vector<const ModuleSnapshot*> ProcessSnapshotMac::Modules() const {
122 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
123 std::vector<const ModuleSnapshot*> modules;
124 for (internal::ModuleSnapshotMac* module : modules_) {
125 modules.push_back(module);
126 }
127 return modules;
128 }
129
130 const ExceptionSnapshot* ProcessSnapshotMac::Exception() const {
131 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
132 return exception_.get();
133 }
134
135 void ProcessSnapshotMac::InitializeThreads() {
136 const std::vector<ProcessReader::Thread>& process_reader_threads =
137 process_reader_.Threads();
138 for (const ProcessReader::Thread& process_reader_thread :
139 process_reader_threads) {
140 internal::ThreadSnapshotMac* thread = new internal::ThreadSnapshotMac();
141 threads_.push_back(thread);
142 if (!thread->Initialize(&process_reader_, process_reader_thread)) {
143 threads_.pop_back();
144 }
145 }
146 }
147
148 void ProcessSnapshotMac::InitializeModules() {
149 const std::vector<ProcessReader::Module>& process_reader_modules =
150 process_reader_.Modules();
151 for (const ProcessReader::Module& process_reader_module :
152 process_reader_modules) {
153 internal::ModuleSnapshotMac* module = new internal::ModuleSnapshotMac();
154 modules_.push_back(module);
155 if (!module->Initialize(&process_reader_, process_reader_module)) {
156 modules_.pop_back();
157 }
158 }
159 }
160
161 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/mac/process_snapshot_mac.h ('k') | snapshot/snapshot.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698