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

Side by Side Diff: minidump/minidump_thread_writer.h

Issue 637503006: Add MinidumpThreadWriter, MinidumpThreadListWriter, and their test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_memory_writer_test_util
Patch Set: Address review feedback 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 | « minidump/minidump_memory_writer_test_util.cc ('k') | minidump/minidump_thread_writer.cc » ('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 #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 MinidumpThreadListWriter in
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
134 //! MinidumpMemoryWriter object that contains a snapshot of its stack memory.
135 //! In the overall tree of internal::MinidumpWritable objects, these
136 //! MinidumpMemoryWriter objects are considered children of their
137 //! MINIDUMP_THREAD, and are referenced by a MINIDUMP_MEMORY_DESCRIPTOR
138 //! contained in the MINIDUMP_THREAD. It is also possible for the same memory
139 //! regions to have MINIDUMP_MEMORY_DESCRIPTOR objects present in a
140 //! MINIDUMP_MEMORY_LIST stream. This is accomplished by calling this method,
141 //! which informs a MinidumpThreadListWriter that it should call
142 //! MinidumpMemoryListWriter::AddExtraMemory() for each extant thread stack
143 //! while the thread is being added in AddThread(). When this is done, the
144 //! MinidumpMemoryListWriter will contain a MINIDUMP_MEMORY_DESCRIPTOR
145 //! pointing to the thread’s stack memory in its MINIDUMP_MEMORY_LIST. Note
146 //! that the actual contents of the memory is only written once, as a child of
147 //! the MinidumpThreadWriter. The MINIDUMP_MEMORY_DESCRIPTOR objects in both
148 //! the MINIDUMP_THREAD and MINIDUMP_MEMORY_LIST will point to the same copy
149 //! of the memory’s contents.
150 //!
151 //! \note This method must be called before AddThread() is called. Threads
152 //! added by AddThread() prior to this method being called will not have
153 //! their stacks added to \a memory_list_writer as extra memory.
154 //! \note Valid in #kStateMutable.
155 void SetMemoryListWriter(MinidumpMemoryListWriter* memory_list_writer);
156
157 //! \brief Adds a MinidumpThreadWriter to the MINIDUMP_THREAD_LIST.
158 //!
159 //! \a thread will become a child of this object in the overall tree of
160 //! internal::MinidumpWritable objects.
161 //!
162 //! \note Valid in #kStateMutable.
163 void AddThread(MinidumpThreadWriter* thread);
164
165 protected:
166 // MinidumpWritable:
167 virtual bool Freeze() override;
168 virtual size_t SizeOfObject() override;
169 virtual std::vector<MinidumpWritable*> Children() override;
170 virtual bool WriteObject(FileWriterInterface* file_writer) override;
171
172 // MinidumpStreamWriter:
173 virtual MinidumpStreamType StreamType() const override;
174
175 private:
176 MINIDUMP_THREAD_LIST thread_list_base_;
177 std::vector<MinidumpThreadWriter*> threads_; // weak
178 MinidumpMemoryListWriter* memory_list_writer_; // weak
179
180 DISALLOW_COPY_AND_ASSIGN(MinidumpThreadListWriter);
181 };
182
183 } // namespace crashpad
184
185 #endif // CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_
OLDNEW
« no previous file with comments | « minidump/minidump_memory_writer_test_util.cc ('k') | minidump/minidump_thread_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698