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 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ | |
16 #define CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ | |
17 | |
18 #include <dbghelp.h> | |
19 #include <stdint.h> | |
20 #include <sys/types.h> | |
21 | |
22 #include <vector> | |
23 | |
24 #include "base/basictypes.h" | |
25 #include "minidump/minidump_stream_writer.h" | |
26 #include "minidump/minidump_writable.h" | |
27 #include "util/file/file_writer.h" | |
28 | |
29 namespace crashpad { | |
30 | |
31 class MinidumpContextWriter; | |
32 class MinidumpMemoryListWriter; | |
33 class MinidumpMemoryWriter; | |
34 | |
35 //! \brief The writer for a MINIDUMP_THREAD object in a minidump file. | |
36 //! | |
37 //! Because MINIDUMP_THREAD objects only appear as elements of | |
38 //! MINIDUMP_THREAD_LIST objects, this class does not write any data on its own. | |
39 //! It makes its MINIDUMP_THREAD data available to its MinidumpThreadListWriter | |
40 //! parent, which writes it as part of a MINIDUMP_THREAD_LIST. | |
41 class MinidumpThreadWriter final : public internal::MinidumpWritable { | |
42 public: | |
43 MinidumpThreadWriter(); | |
44 ~MinidumpThreadWriter() {} | |
45 | |
46 //! \brief Returns a MINIDUMP_THREAD referencing this object’s data. | |
47 //! | |
48 //! This method is expected to be called by a MinidumpModuleListWriter in | |
Robert Sesek
2014/10/08 21:49:31
MinidumpThreadListWriter?
| |
49 //! order to obtain a MINIDUMP_THREAD to include in its list. | |
50 //! | |
51 //! \note Valid in #kStateWritable. | |
52 const MINIDUMP_THREAD* MinidumpThread() const; | |
53 | |
54 //! \brief Returns a MinidumpMemoryWriter that will write the memory region | |
55 //! corresponding to this object’s stack. | |
56 //! | |
57 //! If the thread does not have a stack, or its stack could not be determined, | |
58 //! this will return NULL. | |
59 //! | |
60 //! This method is provided so that MinidumpThreadListWriter can obtain thread | |
61 //! stack memory regions for the purposes of adding them to a | |
62 //! MinidumpMemoryListWriter (configured by calling | |
63 //! MinidumpThreadListWriter::SetMemoryListWriter()) by calling | |
64 //! MinidumpMemoryListWriter::AddExtraMemory(). | |
65 //! | |
66 //! \note Valid in any state. | |
67 MinidumpMemoryWriter* Stack() const { return stack_; } | |
68 | |
69 //! \brief Arranges for MINIDUMP_THREAD::Stack to point to the MINIDUMP_MEMORY | |
70 //! object to be written by \a stack. | |
71 //! | |
72 //! \a stack will become a child of this object in the overall tree of | |
73 //! internal::MinidumpWritable objects. | |
74 //! | |
75 //! \note Valid in #kStateMutable. | |
76 void SetStack(MinidumpMemoryWriter* stack); | |
77 | |
78 //! \brief Arranges for MINIDUMP_THREAD::ThreadContext to point to the CPU | |
79 //! context to be written by \a context. | |
80 //! | |
81 //! A context is required in all MINIDUMP_THREAD objects. | |
82 //! | |
83 //! \a context will become a child of this object in the overall tree of | |
84 //! internal::MinidumpWritable objects. | |
85 //! | |
86 //! \note Valid in #kStateMutable. | |
87 void SetContext(MinidumpContextWriter* context); | |
88 | |
89 //! \brief Sets MINIDUMP_THREAD::ThreadId. | |
90 void SetThreadID(uint32_t thread_id) { thread_.ThreadId = thread_id; } | |
91 | |
92 //! \brief Sets MINIDUMP_THREAD::SuspendCount. | |
93 void SetSuspendCount(uint32_t suspend_count) { | |
94 thread_.SuspendCount = suspend_count; | |
95 } | |
96 | |
97 //! \brief Sets MINIDUMP_THREAD::PriorityClass. | |
98 void SetPriorityClass(uint32_t priority_class) { | |
99 thread_.PriorityClass = priority_class; | |
100 } | |
101 | |
102 //! \brief Sets MINIDUMP_THREAD::Priority. | |
103 void SetPriority(uint32_t priority) { thread_.Priority = priority; } | |
104 | |
105 //! \brief Sets MINIDUMP_THREAD::Teb. | |
106 void SetTEB(uint64_t teb) { thread_.Teb = teb; } | |
107 | |
108 protected: | |
109 // MinidumpWritable: | |
110 virtual bool Freeze() override; | |
111 virtual size_t SizeOfObject() override; | |
112 virtual std::vector<MinidumpWritable*> Children() override; | |
113 virtual bool WriteObject(FileWriterInterface* file_writer) override; | |
114 | |
115 private: | |
116 MINIDUMP_THREAD thread_; | |
117 MinidumpMemoryWriter* stack_; // weak | |
118 MinidumpContextWriter* context_; // weak | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(MinidumpThreadWriter); | |
121 }; | |
122 | |
123 //! \brief The writer for a MINIDUMP_THREAD_LIST stream in a minidump file, | |
124 //! containing a list of MINIDUMP_THREAD objects. | |
125 class MinidumpThreadListWriter final : public internal::MinidumpStreamWriter { | |
126 public: | |
127 MinidumpThreadListWriter(); | |
128 ~MinidumpThreadListWriter(); | |
129 | |
130 //! \brief Sets the MinidumpMemoryListWriter that each thread’s stack memory | |
131 //! region should be added to as extra memory. | |
132 //! | |
133 //! Each MINIDUMP_THREAD object can contain a reference to a MINIDUMP_MEMORY | |
134 //! object that contains a snapshot of its stack memory. In the overall tree | |
135 //! of internal::MinidumpWritable objects, these MINIDUMP_MEMORY objects are | |
136 //! considered children of their MINIDUMP_THREAD. It is also possible for | |
Robert Sesek
2014/10/08 21:49:31
It's possible but when is it the right thing to do
Mark Mentovai
2014/10/08 22:41:03
Robert Sesek wrote:
| |
137 //! the same memory regions to have MINIDUMP_MEMORY objects present in a | |
138 //! MINIDUMP_MEMORY_LIST stream. This is accomplished by calling this method, | |
139 //! which informs a MinidumpThreadListWriter that it should call | |
140 //! MinidumpMemoryListWriter::AddExtraMemory() for each extant thread stack | |
141 //! while the thread is being added in AddThread(). | |
142 //! | |
143 //! \note This method must be called before AddThread() is called. Threads | |
144 //! added by AddThread() prior to this method being called will not have | |
145 //! their stacks added to \a memory_list_writer as extra memory. | |
146 //! \note Valid in #kStateMutable. | |
147 void SetMemoryListWriter(MinidumpMemoryListWriter* memory_list_writer); | |
148 | |
149 //! \brief Adds a MinidumpThreadWriter to the MINIDUMP_THREAD_LIST. | |
150 //! | |
151 //! \a thread will become a child of this object in the overall tree of | |
152 //! internal::MinidumpWritable objects. | |
153 //! | |
154 //! \note Valid in #kStateMutable. | |
155 void AddThread(MinidumpThreadWriter* thread); | |
156 | |
157 protected: | |
158 // MinidumpWritable: | |
159 virtual bool Freeze() override; | |
160 virtual size_t SizeOfObject() override; | |
161 virtual std::vector<MinidumpWritable*> Children() override; | |
162 virtual bool WriteObject(FileWriterInterface* file_writer) override; | |
163 | |
164 // MinidumpStreamWriter: | |
165 virtual MinidumpStreamType StreamType() const override; | |
166 | |
167 private: | |
168 MINIDUMP_THREAD_LIST thread_list_base_; | |
169 std::vector<MinidumpThreadWriter*> threads_; // weak | |
170 MinidumpMemoryListWriter* memory_list_writer_; // weak | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(MinidumpThreadListWriter); | |
173 }; | |
174 | |
175 } // namespace crashpad | |
176 | |
177 #endif // CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ | |
OLD | NEW |