| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ | 15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ |
| 16 #define CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ | 16 #define CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ |
| 17 | 17 |
| 18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
| 19 #include <stdint.h> | 19 #include <stdint.h> |
| 20 | 20 |
| 21 #include <vector> | 21 #include <vector> |
| 22 | 22 |
| 23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/memory/scoped_ptr.h" |
| 24 #include "minidump/minidump_stream_writer.h" | 25 #include "minidump/minidump_stream_writer.h" |
| 25 #include "minidump/minidump_writable.h" | 26 #include "minidump/minidump_writable.h" |
| 27 #include "util/stdlib/pointer_container.h" |
| 26 | 28 |
| 27 namespace crashpad { | 29 namespace crashpad { |
| 28 | 30 |
| 29 class MinidumpContextWriter; | 31 class MinidumpContextWriter; |
| 30 class MinidumpMemoryListWriter; | 32 class MinidumpMemoryListWriter; |
| 31 class MinidumpMemoryWriter; | 33 class MinidumpMemoryWriter; |
| 32 | 34 |
| 33 //! \brief The writer for a MINIDUMP_THREAD object in a minidump file. | 35 //! \brief The writer for a MINIDUMP_THREAD object in a minidump file. |
| 34 //! | 36 //! |
| 35 //! Because MINIDUMP_THREAD objects only appear as elements of | 37 //! Because MINIDUMP_THREAD objects only appear as elements of |
| (...skipping 10 matching lines...) Expand all Loading... |
| 46 //! This method is expected to be called by a MinidumpThreadListWriter in | 48 //! This method is expected to be called by a MinidumpThreadListWriter in |
| 47 //! order to obtain a MINIDUMP_THREAD to include in its list. | 49 //! order to obtain a MINIDUMP_THREAD to include in its list. |
| 48 //! | 50 //! |
| 49 //! \note Valid in #kStateWritable. | 51 //! \note Valid in #kStateWritable. |
| 50 const MINIDUMP_THREAD* MinidumpThread() const; | 52 const MINIDUMP_THREAD* MinidumpThread() const; |
| 51 | 53 |
| 52 //! \brief Returns a MinidumpMemoryWriter that will write the memory region | 54 //! \brief Returns a MinidumpMemoryWriter that will write the memory region |
| 53 //! corresponding to this object’s stack. | 55 //! corresponding to this object’s stack. |
| 54 //! | 56 //! |
| 55 //! If the thread does not have a stack, or its stack could not be determined, | 57 //! If the thread does not have a stack, or its stack could not be determined, |
| 56 //! this will return nullptr. | 58 //! this will return `nullptr`. |
| 57 //! | 59 //! |
| 58 //! This method is provided so that MinidumpThreadListWriter can obtain thread | 60 //! This method is provided so that MinidumpThreadListWriter can obtain thread |
| 59 //! stack memory regions for the purposes of adding them to a | 61 //! stack memory regions for the purposes of adding them to a |
| 60 //! MinidumpMemoryListWriter (configured by calling | 62 //! MinidumpMemoryListWriter (configured by calling |
| 61 //! MinidumpThreadListWriter::SetMemoryListWriter()) by calling | 63 //! MinidumpThreadListWriter::SetMemoryListWriter()) by calling |
| 62 //! MinidumpMemoryListWriter::AddExtraMemory(). | 64 //! MinidumpMemoryListWriter::AddExtraMemory(). |
| 63 //! | 65 //! |
| 64 //! \note Valid in any state. | 66 //! \note Valid in any state. |
| 65 MinidumpMemoryWriter* Stack() const { return stack_; } | 67 MinidumpMemoryWriter* Stack() const { return stack_.get(); } |
| 66 | 68 |
| 67 //! \brief Arranges for MINIDUMP_THREAD::Stack to point to the MINIDUMP_MEMORY | 69 //! \brief Arranges for MINIDUMP_THREAD::Stack to point to the MINIDUMP_MEMORY |
| 68 //! object to be written by \a stack. | 70 //! object to be written by \a stack. |
| 69 //! | 71 //! |
| 70 //! \a stack will become a child of this object in the overall tree of | 72 //! This object takes ownership of \a stack and becomes its parent in the |
| 71 //! internal::MinidumpWritable objects. | 73 //! overall tree of internal::MinidumpWritable objects. |
| 72 //! | 74 //! |
| 73 //! \note Valid in #kStateMutable. | 75 //! \note Valid in #kStateMutable. |
| 74 void SetStack(MinidumpMemoryWriter* stack); | 76 void SetStack(scoped_ptr<MinidumpMemoryWriter> stack); |
| 75 | 77 |
| 76 //! \brief Arranges for MINIDUMP_THREAD::ThreadContext to point to the CPU | 78 //! \brief Arranges for MINIDUMP_THREAD::ThreadContext to point to the CPU |
| 77 //! context to be written by \a context. | 79 //! context to be written by \a context. |
| 78 //! | 80 //! |
| 79 //! A context is required in all MINIDUMP_THREAD objects. | 81 //! A context is required in all MINIDUMP_THREAD objects. |
| 80 //! | 82 //! |
| 81 //! \a context will become a child of this object in the overall tree of | 83 //! This object takes ownership of \a context and becomes its parent in the |
| 82 //! internal::MinidumpWritable objects. | 84 //! overall tree of internal::MinidumpWritable objects. |
| 83 //! | 85 //! |
| 84 //! \note Valid in #kStateMutable. | 86 //! \note Valid in #kStateMutable. |
| 85 void SetContext(MinidumpContextWriter* context); | 87 void SetContext(scoped_ptr<MinidumpContextWriter> context); |
| 86 | 88 |
| 87 //! \brief Sets MINIDUMP_THREAD::ThreadId. | 89 //! \brief Sets MINIDUMP_THREAD::ThreadId. |
| 88 void SetThreadID(uint32_t thread_id) { thread_.ThreadId = thread_id; } | 90 void SetThreadID(uint32_t thread_id) { thread_.ThreadId = thread_id; } |
| 89 | 91 |
| 90 //! \brief Sets MINIDUMP_THREAD::SuspendCount. | 92 //! \brief Sets MINIDUMP_THREAD::SuspendCount. |
| 91 void SetSuspendCount(uint32_t suspend_count) { | 93 void SetSuspendCount(uint32_t suspend_count) { |
| 92 thread_.SuspendCount = suspend_count; | 94 thread_.SuspendCount = suspend_count; |
| 93 } | 95 } |
| 94 | 96 |
| 95 //! \brief Sets MINIDUMP_THREAD::PriorityClass. | 97 //! \brief Sets MINIDUMP_THREAD::PriorityClass. |
| 96 void SetPriorityClass(uint32_t priority_class) { | 98 void SetPriorityClass(uint32_t priority_class) { |
| 97 thread_.PriorityClass = priority_class; | 99 thread_.PriorityClass = priority_class; |
| 98 } | 100 } |
| 99 | 101 |
| 100 //! \brief Sets MINIDUMP_THREAD::Priority. | 102 //! \brief Sets MINIDUMP_THREAD::Priority. |
| 101 void SetPriority(uint32_t priority) { thread_.Priority = priority; } | 103 void SetPriority(uint32_t priority) { thread_.Priority = priority; } |
| 102 | 104 |
| 103 //! \brief Sets MINIDUMP_THREAD::Teb. | 105 //! \brief Sets MINIDUMP_THREAD::Teb. |
| 104 void SetTEB(uint64_t teb) { thread_.Teb = teb; } | 106 void SetTEB(uint64_t teb) { thread_.Teb = teb; } |
| 105 | 107 |
| 106 protected: | 108 protected: |
| 107 // MinidumpWritable: | 109 // MinidumpWritable: |
| 108 bool Freeze() override; | 110 bool Freeze() override; |
| 109 size_t SizeOfObject() override; | 111 size_t SizeOfObject() override; |
| 110 std::vector<MinidumpWritable*> Children() override; | 112 std::vector<MinidumpWritable*> Children() override; |
| 111 bool WriteObject(FileWriterInterface* file_writer) override; | 113 bool WriteObject(FileWriterInterface* file_writer) override; |
| 112 | 114 |
| 113 private: | 115 private: |
| 114 MINIDUMP_THREAD thread_; | 116 MINIDUMP_THREAD thread_; |
| 115 MinidumpMemoryWriter* stack_; // weak | 117 scoped_ptr<MinidumpMemoryWriter> stack_; |
| 116 MinidumpContextWriter* context_; // weak | 118 scoped_ptr<MinidumpContextWriter> context_; |
| 117 | 119 |
| 118 DISALLOW_COPY_AND_ASSIGN(MinidumpThreadWriter); | 120 DISALLOW_COPY_AND_ASSIGN(MinidumpThreadWriter); |
| 119 }; | 121 }; |
| 120 | 122 |
| 121 //! \brief The writer for a MINIDUMP_THREAD_LIST stream in a minidump file, | 123 //! \brief The writer for a MINIDUMP_THREAD_LIST stream in a minidump file, |
| 122 //! containing a list of MINIDUMP_THREAD objects. | 124 //! containing a list of MINIDUMP_THREAD objects. |
| 123 class MinidumpThreadListWriter final : public internal::MinidumpStreamWriter { | 125 class MinidumpThreadListWriter final : public internal::MinidumpStreamWriter { |
| 124 public: | 126 public: |
| 125 MinidumpThreadListWriter(); | 127 MinidumpThreadListWriter(); |
| 126 ~MinidumpThreadListWriter(); | 128 ~MinidumpThreadListWriter() override; |
| 127 | 129 |
| 128 //! \brief Sets the MinidumpMemoryListWriter that each thread’s stack memory | 130 //! \brief Sets the MinidumpMemoryListWriter that each thread’s stack memory |
| 129 //! region should be added to as extra memory. | 131 //! region should be added to as extra memory. |
| 130 //! | 132 //! |
| 131 //! Each MINIDUMP_THREAD object can contain a reference to a | 133 //! Each MINIDUMP_THREAD object can contain a reference to a |
| 132 //! MinidumpMemoryWriter object that contains a snapshot of its stack memory. | 134 //! MinidumpMemoryWriter object that contains a snapshot of its stack memory. |
| 133 //! In the overall tree of internal::MinidumpWritable objects, these | 135 //! In the overall tree of internal::MinidumpWritable objects, these |
| 134 //! MinidumpMemoryWriter objects are considered children of their | 136 //! MinidumpMemoryWriter objects are considered children of their |
| 135 //! MINIDUMP_THREAD, and are referenced by a MINIDUMP_MEMORY_DESCRIPTOR | 137 //! MINIDUMP_THREAD, and are referenced by a MINIDUMP_MEMORY_DESCRIPTOR |
| 136 //! contained in the MINIDUMP_THREAD. It is also possible for the same memory | 138 //! contained in the MINIDUMP_THREAD. It is also possible for the same memory |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 //! of the memory’s contents. | 149 //! of the memory’s contents. |
| 148 //! | 150 //! |
| 149 //! \note This method must be called before AddThread() is called. Threads | 151 //! \note This method must be called before AddThread() is called. Threads |
| 150 //! added by AddThread() prior to this method being called will not have | 152 //! added by AddThread() prior to this method being called will not have |
| 151 //! their stacks added to \a memory_list_writer as extra memory. | 153 //! their stacks added to \a memory_list_writer as extra memory. |
| 152 //! \note Valid in #kStateMutable. | 154 //! \note Valid in #kStateMutable. |
| 153 void SetMemoryListWriter(MinidumpMemoryListWriter* memory_list_writer); | 155 void SetMemoryListWriter(MinidumpMemoryListWriter* memory_list_writer); |
| 154 | 156 |
| 155 //! \brief Adds a MinidumpThreadWriter to the MINIDUMP_THREAD_LIST. | 157 //! \brief Adds a MinidumpThreadWriter to the MINIDUMP_THREAD_LIST. |
| 156 //! | 158 //! |
| 157 //! \a thread will become a child of this object in the overall tree of | 159 //! This object takes ownership of \a thread and becomes its parent in the |
| 158 //! internal::MinidumpWritable objects. | 160 //! overall tree of internal::MinidumpWritable objects. |
| 159 //! | 161 //! |
| 160 //! \note Valid in #kStateMutable. | 162 //! \note Valid in #kStateMutable. |
| 161 void AddThread(MinidumpThreadWriter* thread); | 163 void AddThread(scoped_ptr<MinidumpThreadWriter> thread); |
| 162 | 164 |
| 163 protected: | 165 protected: |
| 164 // MinidumpWritable: | 166 // MinidumpWritable: |
| 165 bool Freeze() override; | 167 bool Freeze() override; |
| 166 size_t SizeOfObject() override; | 168 size_t SizeOfObject() override; |
| 167 std::vector<MinidumpWritable*> Children() override; | 169 std::vector<MinidumpWritable*> Children() override; |
| 168 bool WriteObject(FileWriterInterface* file_writer) override; | 170 bool WriteObject(FileWriterInterface* file_writer) override; |
| 169 | 171 |
| 170 // MinidumpStreamWriter: | 172 // MinidumpStreamWriter: |
| 171 MinidumpStreamType StreamType() const override; | 173 MinidumpStreamType StreamType() const override; |
| 172 | 174 |
| 173 private: | 175 private: |
| 174 MINIDUMP_THREAD_LIST thread_list_base_; | 176 MINIDUMP_THREAD_LIST thread_list_base_; |
| 175 std::vector<MinidumpThreadWriter*> threads_; // weak | 177 PointerVector<MinidumpThreadWriter> threads_; |
| 176 MinidumpMemoryListWriter* memory_list_writer_; // weak | 178 MinidumpMemoryListWriter* memory_list_writer_; // weak |
| 177 | 179 |
| 178 DISALLOW_COPY_AND_ASSIGN(MinidumpThreadListWriter); | 180 DISALLOW_COPY_AND_ASSIGN(MinidumpThreadListWriter); |
| 179 }; | 181 }; |
| 180 | 182 |
| 181 } // namespace crashpad | 183 } // namespace crashpad |
| 182 | 184 |
| 183 #endif // CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ | 185 #endif // CRASHPAD_MINIDUMP_MINIDUMP_THREAD_WRITER_H_ |
| OLD | NEW |