diff --git a/minidump/minidump_file_writer.cc b/minidump/minidump_file_writer.cc index 519d51c4..b4f0a624 100644 --- a/minidump/minidump_file_writer.cc +++ b/minidump/minidump_file_writer.cc @@ -192,7 +192,7 @@ bool MinidumpFileWriter::AddStream( return false; } - streams_.push_back(stream.release()); + streams_.push_back(std::move(stream)); DCHECK_EQ(streams_.size(), stream_types_.size()); return true; @@ -275,8 +275,8 @@ std::vector MinidumpFileWriter::Children() { DCHECK_EQ(streams_.size(), stream_types_.size()); std::vector children; - for (internal::MinidumpStreamWriter* stream : streams_) { - children.push_back(stream); + for (const auto& stream : streams_) { + children.push_back(stream.get()); } return children; @@ -305,7 +305,7 @@ bool MinidumpFileWriter::WriteObject(FileWriterInterface* file_writer) { iov.iov_len = sizeof(header_); std::vector iovecs(1, iov); - for (internal::MinidumpStreamWriter* stream : streams_) { + for (const auto& stream : streams_) { iov.iov_base = stream->DirectoryListEntry(); iov.iov_len = sizeof(MINIDUMP_DIRECTORY); iovecs.push_back(iov); diff --git a/minidump/minidump_file_writer.h b/minidump/minidump_file_writer.h index d5e2d1a5..ce2f1d75 100644 --- a/minidump/minidump_file_writer.h +++ b/minidump/minidump_file_writer.h @@ -28,7 +28,6 @@ #include "minidump/minidump_stream_writer.h" #include "minidump/minidump_writable.h" #include "util/file/file_io.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -145,7 +144,7 @@ class MinidumpFileWriter final : public internal::MinidumpWritable { private: MINIDUMP_HEADER header_; - PointerVector streams_; + std::vector> streams_; // Protects against multiple streams with the same ID being added. std::set stream_types_; diff --git a/minidump/minidump_memory_writer.cc b/minidump/minidump_memory_writer.cc index e1bc7bb6..f6aca081 100644 --- a/minidump/minidump_memory_writer.cc +++ b/minidump/minidump_memory_writer.cc @@ -149,7 +149,7 @@ void MinidumpMemoryListWriter::AddMemory( DCHECK_EQ(state(), kStateMutable); AddExtraMemory(memory_writer.get()); - children_.push_back(memory_writer.release()); + children_.push_back(std::move(memory_writer)); } void MinidumpMemoryListWriter::AddExtraMemory( @@ -192,8 +192,8 @@ std::vector MinidumpMemoryListWriter::Children() { DCHECK_LE(children_.size(), memory_writers_.size()); std::vector children; - for (SnapshotMinidumpMemoryWriter* child : children_) { - children.push_back(child); + for (const auto& child : children_) { + children.push_back(child.get()); } return children; diff --git a/minidump/minidump_memory_writer.h b/minidump/minidump_memory_writer.h index b01505fa..95520907 100644 --- a/minidump/minidump_memory_writer.h +++ b/minidump/minidump_memory_writer.h @@ -28,7 +28,6 @@ #include "minidump/minidump_writable.h" #include "snapshot/memory_snapshot.h" #include "util/file/file_io.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -162,7 +161,7 @@ class MinidumpMemoryListWriter final : public internal::MinidumpStreamWriter { private: std::vector memory_writers_; // weak - PointerVector children_; + std::vector> children_; MINIDUMP_MEMORY_LIST memory_list_base_; DISALLOW_COPY_AND_ASSIGN(MinidumpMemoryListWriter); diff --git a/minidump/minidump_memory_writer_test.cc b/minidump/minidump_memory_writer_test.cc index 7687935c..0290b20d 100644 --- a/minidump/minidump_memory_writer_test.cc +++ b/minidump/minidump_memory_writer_test.cc @@ -313,13 +313,13 @@ TEST(MinidumpMemoryWriter, AddFromSnapshot) { expect_memory_descriptors[2].Memory.DataSize = 0x800; values[2] = 0xa9; - PointerVector memory_snapshots_owner; + std::vector> memory_snapshots_owner; std::vector memory_snapshots; for (size_t index = 0; index < arraysize(expect_memory_descriptors); ++index) { - TestMemorySnapshot* memory_snapshot = new TestMemorySnapshot(); - memory_snapshots_owner.push_back(memory_snapshot); + memory_snapshots_owner.push_back(std::make_unique()); + TestMemorySnapshot* memory_snapshot = memory_snapshots_owner.back().get(); memory_snapshot->SetAddress( expect_memory_descriptors[index].StartOfMemoryRange); memory_snapshot->SetSize(expect_memory_descriptors[index].Memory.DataSize); diff --git a/minidump/minidump_module_crashpad_info_writer.cc b/minidump/minidump_module_crashpad_info_writer.cc index 87b2bc22..a9c5e5d6 100644 --- a/minidump/minidump_module_crashpad_info_writer.cc +++ b/minidump/minidump_module_crashpad_info_writer.cc @@ -164,7 +164,7 @@ void MinidumpModuleCrashpadInfoListWriter::AddModule( } module_crashpad_info_links_.push_back(module_crashpad_info_link); - module_crashpad_infos_.push_back(module_crashpad_info.release()); + module_crashpad_infos_.push_back(std::move(module_crashpad_info)); } bool MinidumpModuleCrashpadInfoListWriter::IsUseful() const { @@ -209,8 +209,8 @@ MinidumpModuleCrashpadInfoListWriter::Children() { DCHECK_EQ(module_crashpad_infos_.size(), module_crashpad_info_links_.size()); std::vector children; - for (MinidumpModuleCrashpadInfoWriter* module : module_crashpad_infos_) { - children.push_back(module); + for (const auto& module : module_crashpad_infos_) { + children.push_back(module.get()); } return children; diff --git a/minidump/minidump_module_crashpad_info_writer.h b/minidump/minidump_module_crashpad_info_writer.h index d79ac2f4..f6a2f320 100644 --- a/minidump/minidump_module_crashpad_info_writer.h +++ b/minidump/minidump_module_crashpad_info_writer.h @@ -25,7 +25,6 @@ #include "minidump/minidump_extensions.h" #include "minidump/minidump_string_writer.h" #include "minidump/minidump_writable.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -155,7 +154,8 @@ class MinidumpModuleCrashpadInfoListWriter final bool WriteObject(FileWriterInterface* file_writer) override; private: - PointerVector module_crashpad_infos_; + std::vector> + module_crashpad_infos_; std::vector module_crashpad_info_links_; MinidumpModuleCrashpadInfoList module_crashpad_info_list_base_; diff --git a/minidump/minidump_module_writer.cc b/minidump/minidump_module_writer.cc index 735183ac..305d37c4 100644 --- a/minidump/minidump_module_writer.cc +++ b/minidump/minidump_module_writer.cc @@ -394,7 +394,7 @@ void MinidumpModuleListWriter::AddModule( std::unique_ptr module) { DCHECK_EQ(state(), kStateMutable); - modules_.push_back(module.release()); + modules_.push_back(std::move(module)); } bool MinidumpModuleListWriter::Freeze() { @@ -423,8 +423,8 @@ std::vector MinidumpModuleListWriter::Children() { DCHECK_GE(state(), kStateFrozen); std::vector children; - for (MinidumpModuleWriter* module : modules_) { - children.push_back(module); + for (const auto& module : modules_) { + children.push_back(module.get()); } return children; @@ -438,7 +438,7 @@ bool MinidumpModuleListWriter::WriteObject(FileWriterInterface* file_writer) { iov.iov_len = sizeof(module_list_base_); std::vector iovecs(1, iov); - for (const MinidumpModuleWriter* module : modules_) { + for (const auto& module : modules_) { iov.iov_base = module->MinidumpModule(); iov.iov_len = sizeof(MINIDUMP_MODULE); iovecs.push_back(iov); diff --git a/minidump/minidump_module_writer.h b/minidump/minidump_module_writer.h index 8d63866a..775a8523 100644 --- a/minidump/minidump_module_writer.h +++ b/minidump/minidump_module_writer.h @@ -30,7 +30,6 @@ #include "minidump/minidump_extensions.h" #include "minidump/minidump_stream_writer.h" #include "minidump/minidump_writable.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -342,7 +341,7 @@ class MinidumpModuleListWriter final : public internal::MinidumpStreamWriter { MinidumpStreamType StreamType() const override; private: - PointerVector modules_; + std::vector> modules_; MINIDUMP_MODULE_LIST module_list_base_; DISALLOW_COPY_AND_ASSIGN(MinidumpModuleListWriter); diff --git a/minidump/minidump_module_writer_test.cc b/minidump/minidump_module_writer_test.cc index f1a18519..f6a278e9 100644 --- a/minidump/minidump_module_writer_test.cc +++ b/minidump/minidump_module_writer_test.cc @@ -703,11 +703,11 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) { uuids[2].InitializeFromBytes(kUUIDBytes2); ages[2] = 30; - PointerVector module_snapshots_owner; + std::vector> module_snapshots_owner; std::vector module_snapshots; for (size_t index = 0; index < arraysize(expect_modules); ++index) { - TestModuleSnapshot* module_snapshot = new TestModuleSnapshot(); - module_snapshots_owner.push_back(module_snapshot); + module_snapshots_owner.push_back(std::make_unique()); + TestModuleSnapshot* module_snapshot = module_snapshots_owner.back().get(); InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot, expect_modules[index], module_paths[index], diff --git a/minidump/minidump_rva_list_writer.cc b/minidump/minidump_rva_list_writer.cc index 87eb502e..88539869 100644 --- a/minidump/minidump_rva_list_writer.cc +++ b/minidump/minidump_rva_list_writer.cc @@ -14,6 +14,8 @@ #include "minidump/minidump_rva_list_writer.h" +#include + #include "base/logging.h" #include "util/file/file_writer.h" #include "util/numeric/safe_assignment.h" @@ -34,7 +36,7 @@ MinidumpRVAListWriter::~MinidumpRVAListWriter() { void MinidumpRVAListWriter::AddChild(std::unique_ptr child) { DCHECK_EQ(state(), kStateMutable); - children_.push_back(child.release()); + children_.push_back(std::move(child)); } bool MinidumpRVAListWriter::Freeze() { @@ -69,8 +71,8 @@ std::vector MinidumpRVAListWriter::Children() { DCHECK_GE(state(), kStateFrozen); std::vector children; - for (MinidumpWritable* child : children_) { - children.push_back(child); + for (const auto& child : children_) { + children.push_back(child.get()); } return children; diff --git a/minidump/minidump_rva_list_writer.h b/minidump/minidump_rva_list_writer.h index 745b792e..af584f13 100644 --- a/minidump/minidump_rva_list_writer.h +++ b/minidump/minidump_rva_list_writer.h @@ -24,7 +24,6 @@ #include "base/macros.h" #include "minidump/minidump_extensions.h" #include "minidump/minidump_writable.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { namespace internal { @@ -67,7 +66,7 @@ class MinidumpRVAListWriter : public MinidumpWritable { private: std::unique_ptr rva_list_base_; - PointerVector children_; + std::vector> children_; std::vector child_rvas_; DISALLOW_COPY_AND_ASSIGN(MinidumpRVAListWriter); diff --git a/minidump/minidump_thread_writer.cc b/minidump/minidump_thread_writer.cc index d3d2a2df..4f390ddb 100644 --- a/minidump/minidump_thread_writer.cc +++ b/minidump/minidump_thread_writer.cc @@ -177,7 +177,7 @@ void MinidumpThreadListWriter::AddThread( } } - threads_.push_back(thread.release()); + threads_.push_back(std::move(thread)); } bool MinidumpThreadListWriter::Freeze() { @@ -206,8 +206,8 @@ std::vector MinidumpThreadListWriter::Children() { DCHECK_GE(state(), kStateFrozen); std::vector children; - for (MinidumpThreadWriter* thread : threads_) { - children.push_back(thread); + for (const auto& thread : threads_) { + children.push_back(thread.get()); } return children; @@ -221,7 +221,7 @@ bool MinidumpThreadListWriter::WriteObject(FileWriterInterface* file_writer) { iov.iov_len = sizeof(thread_list_base_); std::vector iovecs(1, iov); - for (const MinidumpThreadWriter* thread : threads_) { + for (const auto& thread : threads_) { iov.iov_base = thread->MinidumpThread(); iov.iov_len = sizeof(MINIDUMP_THREAD); iovecs.push_back(iov); diff --git a/minidump/minidump_thread_writer.h b/minidump/minidump_thread_writer.h index e34ea061..82092e2b 100644 --- a/minidump/minidump_thread_writer.h +++ b/minidump/minidump_thread_writer.h @@ -27,7 +27,6 @@ #include "minidump/minidump_stream_writer.h" #include "minidump/minidump_thread_id_map.h" #include "minidump/minidump_writable.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -203,7 +202,7 @@ class MinidumpThreadListWriter final : public internal::MinidumpStreamWriter { MinidumpStreamType StreamType() const override; private: - PointerVector threads_; + std::vector> threads_; MinidumpMemoryListWriter* memory_list_writer_; // weak MINIDUMP_THREAD_LIST thread_list_base_; diff --git a/minidump/minidump_thread_writer_test.cc b/minidump/minidump_thread_writer_test.cc index 4687953f..3e8e7de7 100644 --- a/minidump/minidump_thread_writer_test.cc +++ b/minidump/minidump_thread_writer_test.cc @@ -585,11 +585,11 @@ void RunInitializeFromSnapshotTest(bool thread_id_collision) { expect_threads[2].ThreadId = static_cast(thread_ids[2]); } - PointerVector thread_snapshots_owner; + std::vector> thread_snapshots_owner; std::vector thread_snapshots; for (size_t index = 0; index < arraysize(expect_threads); ++index) { - TestThreadSnapshot* thread_snapshot = new TestThreadSnapshot(); - thread_snapshots_owner.push_back(thread_snapshot); + thread_snapshots_owner.push_back(std::make_unique()); + TestThreadSnapshot* thread_snapshot = thread_snapshots_owner.back().get(); thread_snapshot->SetThreadID(thread_ids[index]); thread_snapshot->SetSuspendCount(expect_threads[index].SuspendCount); diff --git a/minidump/minidump_unloaded_module_writer.cc b/minidump/minidump_unloaded_module_writer.cc index 4b36c9e3..855e1967 100644 --- a/minidump/minidump_unloaded_module_writer.cc +++ b/minidump/minidump_unloaded_module_writer.cc @@ -15,6 +15,7 @@ #include "minidump/minidump_unloaded_module_writer.h" #include +#include #include "minidump/minidump_writer_util.h" #include "util/file/file_writer.h" @@ -133,7 +134,7 @@ void MinidumpUnloadedModuleListWriter::AddUnloadedModule( std::unique_ptr unloaded_module) { DCHECK_EQ(state(), kStateMutable); - unloaded_modules_.push_back(unloaded_module.release()); + unloaded_modules_.push_back(std::move(unloaded_module)); } bool MinidumpUnloadedModuleListWriter::Freeze() { @@ -170,8 +171,8 @@ MinidumpUnloadedModuleListWriter::Children() { DCHECK_GE(state(), kStateFrozen); std::vector children; - for (MinidumpUnloadedModuleWriter* unloaded_module : unloaded_modules_) { - children.push_back(unloaded_module); + for (const auto& unloaded_module : unloaded_modules_) { + children.push_back(unloaded_module.get()); } return children; @@ -186,8 +187,7 @@ bool MinidumpUnloadedModuleListWriter::WriteObject( iov.iov_len = sizeof(unloaded_module_list_base_); std::vector iovecs(1, iov); - for (const MinidumpUnloadedModuleWriter* unloaded_module : - unloaded_modules_) { + for (const auto& unloaded_module : unloaded_modules_) { iov.iov_base = unloaded_module->MinidumpUnloadedModule(); iov.iov_len = sizeof(MINIDUMP_UNLOADED_MODULE); iovecs.push_back(iov); diff --git a/minidump/minidump_unloaded_module_writer.h b/minidump/minidump_unloaded_module_writer.h index ad83aa50..97651dba 100644 --- a/minidump/minidump_unloaded_module_writer.h +++ b/minidump/minidump_unloaded_module_writer.h @@ -143,7 +143,7 @@ class MinidumpUnloadedModuleListWriter final MinidumpStreamType StreamType() const override; private: - PointerVector unloaded_modules_; + std::vector> unloaded_modules_; MINIDUMP_UNLOADED_MODULE_LIST unloaded_module_list_base_; DISALLOW_COPY_AND_ASSIGN(MinidumpUnloadedModuleListWriter); diff --git a/snapshot/linux/process_reader_test.cc b/snapshot/linux/process_reader_test.cc index 7adb3ab5..5c8b8cba 100644 --- a/snapshot/linux/process_reader_test.cc +++ b/snapshot/linux/process_reader_test.cc @@ -25,6 +25,7 @@ #include #include +#include #include "base/format_macros.h" #include "base/memory/free_deleter.h" @@ -37,7 +38,6 @@ #include "util/file/file_io.h" #include "util/linux/direct_ptrace_connection.h" #include "util/misc/from_pointer_cast.h" -#include "util/stdlib/pointer_container.h" #include "util/synchronization/semaphore.h" namespace crashpad { @@ -149,11 +149,11 @@ class TestThreadPool { TestThreadPool() : threads_() {} ~TestThreadPool() { - for (Thread* thread : threads_) { + for (const auto& thread : threads_) { thread->exit_semaphore.Signal(); } - for (const Thread* thread : threads_) { + for (const auto& thread : threads_) { EXPECT_EQ(pthread_join(thread->pthread, nullptr), 0) << ErrnoMessage("pthread_join"); } @@ -161,8 +161,8 @@ class TestThreadPool { void StartThreads(size_t thread_count, size_t stack_size = 0) { for (size_t thread_index = 0; thread_index < thread_count; ++thread_index) { - Thread* thread = new Thread(); - threads_.push_back(thread); + threads_.push_back(std::make_unique()); + Thread* thread = threads_.back().get(); pthread_attr_t attr; ASSERT_EQ(pthread_attr_init(&attr), 0) @@ -197,7 +197,7 @@ class TestThreadPool { << ErrnoMessage("pthread_create"); } - for (Thread* thread : threads_) { + for (const auto& thread : threads_) { thread->ready_semaphore.Wait(); } } @@ -206,7 +206,7 @@ class TestThreadPool { ThreadExpectation* expectation) { CHECK_LT(thread_index, threads_.size()); - const Thread* thread = threads_[thread_index]; + const Thread* thread = threads_[thread_index].get(); *expectation = thread->expectation; return thread->tid; } @@ -248,7 +248,7 @@ class TestThreadPool { return nullptr; } - PointerVector threads_; + std::vector> threads_; DISALLOW_COPY_AND_ASSIGN(TestThreadPool); }; diff --git a/snapshot/mac/mach_o_image_reader.cc b/snapshot/mac/mach_o_image_reader.cc index 7cb4040f..cd8f125e 100644 --- a/snapshot/mac/mach_o_image_reader.cc +++ b/snapshot/mac/mach_o_image_reader.cc @@ -20,7 +20,6 @@ #include #include -#include #include "base/logging.h" #include "base/strings/stringprintf.h" @@ -274,7 +273,7 @@ bool MachOImageReader::Initialize(ProcessReader* process_reader, } // Now that the slide is known, push it into the segments. - for (MachOImageSegmentReader* segment : segments_) { + for (const auto& segment : segments_) { segment->SetSlide(slide_); // This was already checked for the unslid values while the segments were @@ -321,8 +320,7 @@ const MachOImageSegmentReader* MachOImageReader::GetSegmentByName( return nullptr; } - const MachOImageSegmentReader* segment = segments_[iterator->second]; - return segment; + return segments_[iterator->second].get(); } const process_types::section* MachOImageReader::GetSectionByName( @@ -354,14 +352,14 @@ const process_types::section* MachOImageReader::GetSectionAtIndex( // Switch to a more comfortable 0-based index. size_t local_index = index - 1; - for (const MachOImageSegmentReader* segment : segments_) { + for (const auto& segment : segments_) { size_t nsects = segment->nsects(); if (local_index < nsects) { const process_types::section* section = segment->GetSectionAtIndex(local_index, address); if (containing_segment) { - *containing_segment = segment; + *containing_segment = segment.get(); } return section; @@ -522,9 +520,9 @@ bool MachOImageReader::ReadLoadCommand(mach_vm_address_t load_command_address, bool MachOImageReader::ReadSegmentCommand( mach_vm_address_t load_command_address, const std::string& load_command_info) { - MachOImageSegmentReader* segment = new MachOImageSegmentReader(); size_t segment_index = segments_.size(); - segments_.push_back(segment); // Takes ownership. + segments_.push_back(std::make_unique()); + MachOImageSegmentReader* segment = segments_.back().get(); if (!segment->Initialize(process_reader_, load_command_address, diff --git a/snapshot/mac/mach_o_image_reader.h b/snapshot/mac/mach_o_image_reader.h index 40eddc22..c16cce99 100644 --- a/snapshot/mac/mach_o_image_reader.h +++ b/snapshot/mac/mach_o_image_reader.h @@ -22,12 +22,12 @@ #include #include #include +#include #include "base/macros.h" #include "snapshot/mac/process_types.h" #include "util/misc/initialization_state_dcheck.h" #include "util/misc/uuid.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -317,7 +317,7 @@ class MachOImageReader { // will be set to the valid state, but symbol_table_ will be nullptr. void InitializeSymbolTable() const; - PointerVector segments_; + std::vector> segments_; std::map segment_map_; std::string module_name_; std::string module_info_; diff --git a/snapshot/mac/process_reader.cc b/snapshot/mac/process_reader.cc index c24b45c3..d38ab144 100644 --- a/snapshot/mac/process_reader.cc +++ b/snapshot/mac/process_reader.cc @@ -19,6 +19,7 @@ #include #include +#include #include "base/logging.h" #include "base/mac/mach_logging.h" @@ -457,7 +458,7 @@ void ProcessReader::InitializeModules() { uint32_t file_type = reader ? reader->FileType() : 0; - module_readers_.push_back(reader.release()); + module_readers_.push_back(std::move(reader)); modules_.push_back(module); if (all_image_infos.version >= 2 && all_image_infos.dyldImageLoadAddress && @@ -557,7 +558,7 @@ void ProcessReader::InitializeModules() { } // dyld is loaded in the process even if its path can’t be determined. - module_readers_.push_back(reader.release()); + module_readers_.push_back(std::move(reader)); modules_.push_back(module); } } diff --git a/snapshot/mac/process_reader.h b/snapshot/mac/process_reader.h index ddb49cb6..ecca2a5a 100644 --- a/snapshot/mac/process_reader.h +++ b/snapshot/mac/process_reader.h @@ -30,7 +30,6 @@ #include "util/mach/task_memory.h" #include "util/misc/initialization_state_dcheck.h" #include "util/posix/process_info.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -232,7 +231,7 @@ class ProcessReader { ProcessInfo process_info_; std::vector threads_; // owns send rights std::vector modules_; - PointerVector module_readers_; + std::vector> module_readers_; std::unique_ptr task_memory_; task_t task_; // weak InitializationStateDcheck initialized_; diff --git a/snapshot/mac/process_reader_test.cc b/snapshot/mac/process_reader_test.cc index 6d675057..36b372fb 100644 --- a/snapshot/mac/process_reader_test.cc +++ b/snapshot/mac/process_reader_test.cc @@ -23,8 +23,7 @@ #include #include -#include -#include +#include #include "base/logging.h" #include "base/mac/scoped_mach_port.h" @@ -41,7 +40,6 @@ #include "util/mac/mac_util.h" #include "util/mach/mach_extensions.h" #include "util/misc/from_pointer_cast.h" -#include "util/stdlib/pointer_container.h" #include "util/synchronization/semaphore.h" #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10 @@ -175,7 +173,7 @@ class TestThreadPool { // Resumes suspended threads, signals each thread’s exit semaphore asking it // to exit, and joins each thread, blocking until they have all exited. ~TestThreadPool() { - for (ThreadInfo* thread_info : thread_infos_) { + for (const auto& thread_info : thread_infos_) { thread_t thread_port = pthread_mach_thread_np(thread_info->pthread); while (thread_info->suspend_count > 0) { kern_return_t kr = thread_resume(thread_port); @@ -184,11 +182,11 @@ class TestThreadPool { } } - for (ThreadInfo* thread_info : thread_infos_) { + for (const auto& thread_info : thread_infos_) { thread_info->exit_semaphore.Signal(); } - for (const ThreadInfo* thread_info : thread_infos_) { + for (const auto& thread_info : thread_infos_) { int rv = pthread_join(thread_info->pthread, nullptr); CHECK_EQ(0, rv); } @@ -201,8 +199,8 @@ class TestThreadPool { ASSERT_TRUE(thread_infos_.empty()); for (size_t thread_index = 0; thread_index < thread_count; ++thread_index) { - ThreadInfo* thread_info = new ThreadInfo(); - thread_infos_.push_back(thread_info); + thread_infos_.push_back(std::make_unique()); + ThreadInfo* thread_info = thread_infos_.back().get(); int rv = pthread_create(&thread_info->pthread, nullptr, @@ -211,7 +209,7 @@ class TestThreadPool { ASSERT_EQ(rv, 0); } - for (ThreadInfo* thread_info : thread_infos_) { + for (const auto& thread_info : thread_infos_) { thread_info->ready_semaphore.Wait(); } @@ -238,7 +236,7 @@ class TestThreadPool { ThreadExpectation* expectation) { CHECK_LT(thread_index, thread_infos_.size()); - const ThreadInfo* thread_info = thread_infos_[thread_index]; + const auto& thread_info = thread_infos_[thread_index]; expectation->stack_address = thread_info->stack_address; expectation->suspend_count = thread_info->suspend_count; @@ -297,9 +295,9 @@ class TestThreadPool { return nullptr; } - // This is a PointerVector because the address of a ThreadInfo object is + // This is a vector of pointers because the address of a ThreadInfo object is // passed to each thread’s ThreadMain(), so they cannot move around in memory. - PointerVector thread_infos_; + std::vector> thread_infos_; DISALLOW_COPY_AND_ASSIGN(TestThreadPool); }; diff --git a/snapshot/mac/process_snapshot_mac.cc b/snapshot/mac/process_snapshot_mac.cc index f2afa731..eaaf3dca 100644 --- a/snapshot/mac/process_snapshot_mac.cc +++ b/snapshot/mac/process_snapshot_mac.cc @@ -14,6 +14,8 @@ #include "snapshot/mac/process_snapshot_mac.h" +#include + #include "base/logging.h" #include "util/misc/tri_state.h" @@ -92,7 +94,7 @@ void ProcessSnapshotMac::GetCrashpadOptions( CrashpadInfoClientOptions local_options; - for (internal::ModuleSnapshotMac* module : modules_) { + for (const auto& module : modules_) { CrashpadInfoClientOptions module_options; module->GetCrashpadOptions(&module_options); @@ -173,8 +175,8 @@ const SystemSnapshot* ProcessSnapshotMac::System() const { std::vector ProcessSnapshotMac::Threads() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); std::vector threads; - for (internal::ThreadSnapshotMac* thread : threads_) { - threads.push_back(thread); + for (const auto& thread : threads_) { + threads.push_back(thread.get()); } return threads; } @@ -182,8 +184,8 @@ std::vector ProcessSnapshotMac::Threads() const { std::vector ProcessSnapshotMac::Modules() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); std::vector modules; - for (internal::ModuleSnapshotMac* module : modules_) { - modules.push_back(module); + for (const auto& module : modules_) { + modules.push_back(module.get()); } return modules; } @@ -222,7 +224,7 @@ void ProcessSnapshotMac::InitializeThreads() { process_reader_threads) { auto thread = std::make_unique(); if (thread->Initialize(&process_reader_, process_reader_thread)) { - threads_.push_back(thread.release()); + threads_.push_back(std::move(thread)); } } } @@ -234,7 +236,7 @@ void ProcessSnapshotMac::InitializeModules() { process_reader_modules) { auto module = std::make_unique(); if (module->Initialize(&process_reader_, process_reader_module)) { - modules_.push_back(module.release()); + modules_.push_back(std::move(module)); } } } diff --git a/snapshot/mac/process_snapshot_mac.h b/snapshot/mac/process_snapshot_mac.h index d3e6eb45..e7195d94 100644 --- a/snapshot/mac/process_snapshot_mac.h +++ b/snapshot/mac/process_snapshot_mac.h @@ -42,7 +42,6 @@ #include "util/mach/mach_extensions.h" #include "util/misc/initialization_state_dcheck.h" #include "util/misc/uuid.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -141,8 +140,8 @@ class ProcessSnapshotMac final : public ProcessSnapshot { void InitializeModules(); internal::SystemSnapshotMac system_; - PointerVector threads_; - PointerVector modules_; + std::vector> threads_; + std::vector> modules_; std::unique_ptr exception_; ProcessReader process_reader_; UUID report_id_; diff --git a/snapshot/minidump/process_snapshot_minidump.cc b/snapshot/minidump/process_snapshot_minidump.cc index 2ffb2af4..90bfac54 100644 --- a/snapshot/minidump/process_snapshot_minidump.cc +++ b/snapshot/minidump/process_snapshot_minidump.cc @@ -14,7 +14,6 @@ #include "snapshot/minidump/process_snapshot_minidump.h" -#include #include #include "snapshot/minidump/minidump_simple_string_dictionary_reader.h" @@ -166,8 +165,8 @@ std::vector ProcessSnapshotMinidump::Threads() const { std::vector ProcessSnapshotMinidump::Modules() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); std::vector modules; - for (internal::ModuleSnapshotMinidump* module : modules_) { - modules.push_back(module); + for (const auto& module : modules_) { + modules.push_back(module.get()); } return modules; } @@ -283,7 +282,7 @@ bool ProcessSnapshotMinidump::InitializeModules() { return false; } - modules_.push_back(module.release()); + modules_.push_back(std::move(module)); } return true; diff --git a/snapshot/minidump/process_snapshot_minidump.h b/snapshot/minidump/process_snapshot_minidump.h index 2f6bf54c..211805e8 100644 --- a/snapshot/minidump/process_snapshot_minidump.h +++ b/snapshot/minidump/process_snapshot_minidump.h @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -37,7 +38,6 @@ #include "util/file/file_reader.h" #include "util/misc/initialization_state_dcheck.h" #include "util/misc/uuid.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -95,7 +95,7 @@ class ProcessSnapshotMinidump final : public ProcessSnapshot { MINIDUMP_HEADER header_; std::vector stream_directory_; std::map stream_map_; - PointerVector modules_; + std::vector> modules_; std::vector unloaded_modules_; MinidumpCrashpadInfo crashpad_info_; std::map annotations_simple_map_; diff --git a/snapshot/test/test_exception_snapshot.cc b/snapshot/test/test_exception_snapshot.cc index 6adfeaf8..84340671 100644 --- a/snapshot/test/test_exception_snapshot.cc +++ b/snapshot/test/test_exception_snapshot.cc @@ -57,8 +57,9 @@ const std::vector& TestExceptionSnapshot::Codes() const { std::vector TestExceptionSnapshot::ExtraMemory() const { std::vector extra_memory; - for (const auto& em : extra_memory_) - extra_memory.push_back(em); + for (const auto& em : extra_memory_) { + extra_memory.push_back(em.get()); + } return extra_memory; } diff --git a/snapshot/test/test_exception_snapshot.h b/snapshot/test/test_exception_snapshot.h index 254bff12..aa75539d 100644 --- a/snapshot/test/test_exception_snapshot.h +++ b/snapshot/test/test_exception_snapshot.h @@ -18,12 +18,12 @@ #include #include +#include #include #include "base/macros.h" #include "snapshot/cpu_context.h" #include "snapshot/exception_snapshot.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { namespace test { @@ -60,7 +60,7 @@ class TestExceptionSnapshot final : public ExceptionSnapshot { } void SetCodes(const std::vector& codes) { codes_ = codes; } void AddExtraMemory(std::unique_ptr extra_memory) { - extra_memory_.push_back(extra_memory.release()); + extra_memory_.push_back(std::move(extra_memory)); } // ExceptionSnapshot: @@ -84,7 +84,7 @@ class TestExceptionSnapshot final : public ExceptionSnapshot { uint32_t exception_info_; uint64_t exception_address_; std::vector codes_; - PointerVector extra_memory_; + std::vector> extra_memory_; DISALLOW_COPY_AND_ASSIGN(TestExceptionSnapshot); }; diff --git a/snapshot/test/test_module_snapshot.cc b/snapshot/test/test_module_snapshot.cc index 08776d65..47962ce3 100644 --- a/snapshot/test/test_module_snapshot.cc +++ b/snapshot/test/test_module_snapshot.cc @@ -100,7 +100,7 @@ std::set> TestModuleSnapshot::ExtraMemoryRanges() const { std::vector TestModuleSnapshot::CustomMinidumpStreams() const { - return custom_minidump_streams_; + return std::vector(); } } // namespace test diff --git a/snapshot/test/test_module_snapshot.h b/snapshot/test/test_module_snapshot.h index 7589d628..92b3f094 100644 --- a/snapshot/test/test_module_snapshot.h +++ b/snapshot/test/test_module_snapshot.h @@ -24,7 +24,6 @@ #include "base/macros.h" #include "snapshot/module_snapshot.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { namespace test { @@ -80,9 +79,6 @@ class TestModuleSnapshot final : public ModuleSnapshot { const std::set>& extra_memory_ranges) { extra_memory_ranges_ = extra_memory_ranges; } - void AddCustomMinidumpStream(const UserMinidumpStream* stream) { - custom_minidump_streams_.push_back(stream); - } // ModuleSnapshot: @@ -120,7 +116,6 @@ class TestModuleSnapshot final : public ModuleSnapshot { std::vector annotations_vector_; std::map annotations_simple_map_; std::set> extra_memory_ranges_; - PointerVector custom_minidump_streams_; DISALLOW_COPY_AND_ASSIGN(TestModuleSnapshot); }; diff --git a/snapshot/test/test_process_snapshot.cc b/snapshot/test/test_process_snapshot.cc index 74f9fe35..c430fd99 100644 --- a/snapshot/test/test_process_snapshot.cc +++ b/snapshot/test/test_process_snapshot.cc @@ -82,16 +82,16 @@ const SystemSnapshot* TestProcessSnapshot::System() const { std::vector TestProcessSnapshot::Threads() const { std::vector threads; - for (const ThreadSnapshot* thread : threads_) { - threads.push_back(thread); + for (const auto& thread : threads_) { + threads.push_back(thread.get()); } return threads; } std::vector TestProcessSnapshot::Modules() const { std::vector modules; - for (const ModuleSnapshot* module : modules_) { - modules.push_back(module); + for (const auto& module : modules_) { + modules.push_back(module.get()); } return modules; } @@ -108,8 +108,9 @@ const ExceptionSnapshot* TestProcessSnapshot::Exception() const { std::vector TestProcessSnapshot::MemoryMap() const { std::vector memory_map; - for (const auto& item : memory_map_) - memory_map.push_back(item); + for (const auto& item : memory_map_) { + memory_map.push_back(item.get()); + } return memory_map; } @@ -119,8 +120,9 @@ std::vector TestProcessSnapshot::Handles() const { std::vector TestProcessSnapshot::ExtraMemory() const { std::vector extra_memory; - for (const auto& em : extra_memory_) - extra_memory.push_back(em); + for (const auto& em : extra_memory_) { + extra_memory.push_back(em.get()); + } return extra_memory; } diff --git a/snapshot/test/test_process_snapshot.h b/snapshot/test/test_process_snapshot.h index 7dd31247..5c63e121 100644 --- a/snapshot/test/test_process_snapshot.h +++ b/snapshot/test/test_process_snapshot.h @@ -35,7 +35,6 @@ #include "snapshot/thread_snapshot.h" #include "snapshot/unloaded_module_snapshot.h" #include "util/misc/uuid.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { namespace test { @@ -82,7 +81,7 @@ class TestProcessSnapshot final : public ProcessSnapshot { //! \param[in] thread The thread snapshot that will be included in Threads(). //! The TestProcessSnapshot object takes ownership of \a thread. void AddThread(std::unique_ptr thread) { - threads_.push_back(thread.release()); + threads_.push_back(std::move(thread)); } //! \brief Adds a module snapshot to be returned by Modules(). @@ -90,7 +89,7 @@ class TestProcessSnapshot final : public ProcessSnapshot { //! \param[in] module The module snapshot that will be included in Modules(). //! The TestProcessSnapshot object takes ownership of \a module. void AddModule(std::unique_ptr module) { - modules_.push_back(module.release()); + modules_.push_back(std::move(module)); } //! \brief Adds an unloaded module snapshot to be returned by @@ -116,7 +115,7 @@ class TestProcessSnapshot final : public ProcessSnapshot { //! MemoryMap(). The TestProcessSnapshot object takes ownership of \a //! region. void AddMemoryMapRegion(std::unique_ptr region) { - memory_map_.push_back(region.release()); + memory_map_.push_back(std::move(region)); } //! \brief Adds a handle snapshot to be returned by Handles(). @@ -132,7 +131,7 @@ class TestProcessSnapshot final : public ProcessSnapshot { //! ExtraMemory(). The TestProcessSnapshot object takes ownership of \a //! extra_memory. void AddExtraMemory(std::unique_ptr extra_memory) { - extra_memory_.push_back(extra_memory.release()); + extra_memory_.push_back(std::move(extra_memory)); } // ProcessSnapshot: @@ -166,13 +165,13 @@ class TestProcessSnapshot final : public ProcessSnapshot { UUID client_id_; std::map annotations_simple_map_; std::unique_ptr system_; - PointerVector threads_; - PointerVector modules_; + std::vector> threads_; + std::vector> modules_; std::vector unloaded_modules_; std::unique_ptr exception_; - PointerVector memory_map_; + std::vector> memory_map_; std::vector handles_; - PointerVector extra_memory_; + std::vector> extra_memory_; DISALLOW_COPY_AND_ASSIGN(TestProcessSnapshot); }; diff --git a/snapshot/test/test_thread_snapshot.cc b/snapshot/test/test_thread_snapshot.cc index 621ff424..ed6d9fda 100644 --- a/snapshot/test/test_thread_snapshot.cc +++ b/snapshot/test/test_thread_snapshot.cc @@ -57,8 +57,9 @@ uint64_t TestThreadSnapshot::ThreadSpecificDataAddress() const { std::vector TestThreadSnapshot::ExtraMemory() const { std::vector extra_memory; - for (const auto& em : extra_memory_) - extra_memory.push_back(em); + for (const auto& em : extra_memory_) { + extra_memory.push_back(em.get()); + } return extra_memory; } diff --git a/snapshot/test/test_thread_snapshot.h b/snapshot/test/test_thread_snapshot.h index 37fce4dc..e705c164 100644 --- a/snapshot/test/test_thread_snapshot.h +++ b/snapshot/test/test_thread_snapshot.h @@ -25,7 +25,6 @@ #include "snapshot/cpu_context.h" #include "snapshot/memory_snapshot.h" #include "snapshot/thread_snapshot.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { namespace test { @@ -73,7 +72,7 @@ class TestThreadSnapshot final : public ThreadSnapshot { //! ExtraMemory(). The TestThreadSnapshot object takes ownership of \a //! extra_memory. void AddExtraMemory(std::unique_ptr extra_memory) { - extra_memory_.push_back(extra_memory.release()); + extra_memory_.push_back(std::move(extra_memory)); } // ThreadSnapshot: @@ -97,7 +96,7 @@ class TestThreadSnapshot final : public ThreadSnapshot { int suspend_count_; int priority_; uint64_t thread_specific_data_address_; - PointerVector extra_memory_; + std::vector> extra_memory_; DISALLOW_COPY_AND_ASSIGN(TestThreadSnapshot); }; diff --git a/snapshot/win/capture_memory_delegate_win.cc b/snapshot/win/capture_memory_delegate_win.cc index 889e1b20..fc1c608b 100644 --- a/snapshot/win/capture_memory_delegate_win.cc +++ b/snapshot/win/capture_memory_delegate_win.cc @@ -14,6 +14,8 @@ #include "snapshot/win/capture_memory_delegate_win.h" +#include + #include "base/numerics/safe_conversions.h" #include "snapshot/win/memory_snapshot_win.h" @@ -23,7 +25,7 @@ namespace internal { CaptureMemoryDelegateWin::CaptureMemoryDelegateWin( ProcessReaderWin* process_reader, const ProcessReaderWin::Thread& thread, - PointerVector* snapshots, + std::vector>* snapshots, uint32_t* budget_remaining) : stack_(thread.stack_region_address, thread.stack_region_size), process_reader_(process_reader), @@ -54,9 +56,9 @@ void CaptureMemoryDelegateWin::AddNewMemorySnapshot( return; if (budget_remaining_ && *budget_remaining_ == 0) return; - internal::MemorySnapshotWin* snapshot = new internal::MemorySnapshotWin(); + snapshots_->push_back(std::make_unique()); + internal::MemorySnapshotWin* snapshot = snapshots_->back().get(); snapshot->Initialize(process_reader_, range.base(), range.size()); - snapshots_->push_back(snapshot); if (budget_remaining_) { if (!base::IsValueInRangeForNumericType(range.size())) { *budget_remaining_ = 0; diff --git a/snapshot/win/capture_memory_delegate_win.h b/snapshot/win/capture_memory_delegate_win.h index ac575577..d5615aee 100644 --- a/snapshot/win/capture_memory_delegate_win.h +++ b/snapshot/win/capture_memory_delegate_win.h @@ -1,4 +1,4 @@ - // Copyright 2016 The Crashpad Authors. All rights reserved. +// Copyright 2016 The Crashpad Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,8 +17,13 @@ #include "snapshot/capture_memory.h" +#include + +#include +#include + #include "snapshot/win/process_reader_win.h" -#include "util/stdlib/pointer_container.h" +#include "util/numeric/checked_range.h" namespace crashpad { namespace internal { @@ -38,10 +43,11 @@ class CaptureMemoryDelegateWin : public CaptureMemory::Delegate { //! \param[in] budget_remaining If non-null, a pointer to the remaining number //! of bytes to capture. If this is `0`, no further memory will be //! captured. - CaptureMemoryDelegateWin(ProcessReaderWin* process_reader, - const ProcessReaderWin::Thread& thread, - PointerVector* snapshots, - uint32_t* budget_remaining); + CaptureMemoryDelegateWin( + ProcessReaderWin* process_reader, + const ProcessReaderWin::Thread& thread, + std::vector>* snapshots, + uint32_t* budget_remaining); // MemoryCaptureDelegate: bool Is64Bit() const override; @@ -52,8 +58,8 @@ class CaptureMemoryDelegateWin : public CaptureMemory::Delegate { private: CheckedRange stack_; - ProcessReaderWin* process_reader_; - PointerVector* snapshots_; + ProcessReaderWin* process_reader_; // weak + std::vector>* snapshots_; // weak uint32_t* budget_remaining_; }; diff --git a/snapshot/win/exception_snapshot_win.cc b/snapshot/win/exception_snapshot_win.cc index c0d63bad..64b53424 100644 --- a/snapshot/win/exception_snapshot_win.cc +++ b/snapshot/win/exception_snapshot_win.cc @@ -59,6 +59,7 @@ ExceptionSnapshotWin::ExceptionSnapshotWin() context_union_(), context_(), codes_(), + extra_memory_(), thread_id_(0), exception_address_(0), exception_flags_(0), @@ -158,8 +159,9 @@ std::vector ExceptionSnapshotWin::ExtraMemory() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); std::vector result; result.reserve(extra_memory_.size()); - for (const auto& em : extra_memory_) - result.push_back(em); + for (const auto& em : extra_memory_) { + result.push_back(em.get()); + } return result; } diff --git a/snapshot/win/exception_snapshot_win.h b/snapshot/win/exception_snapshot_win.h index 7aedb3a4..0d216683 100644 --- a/snapshot/win/exception_snapshot_win.h +++ b/snapshot/win/exception_snapshot_win.h @@ -18,13 +18,15 @@ #include #include +#include +#include + #include "base/macros.h" #include "build/build_config.h" #include "snapshot/cpu_context.h" #include "snapshot/exception_snapshot.h" #include "snapshot/win/thread_snapshot_win.h" #include "util/misc/initialization_state_dcheck.h" -#include "util/stdlib/pointer_container.h" #include "util/win/address_types.h" #include "util/win/process_structs.h" @@ -94,7 +96,7 @@ class ExceptionSnapshotWin final : public ExceptionSnapshot { #endif CPUContext context_; std::vector codes_; - PointerVector extra_memory_; + std::vector> extra_memory_; uint64_t thread_id_; uint64_t exception_address_; uint32_t exception_flags_; diff --git a/snapshot/win/module_snapshot_win.cc b/snapshot/win/module_snapshot_win.cc index 6dcbd7d1..ec0bab56 100644 --- a/snapshot/win/module_snapshot_win.cc +++ b/snapshot/win/module_snapshot_win.cc @@ -14,6 +14,8 @@ #include "snapshot/win/module_snapshot_win.h" +#include + #include "base/strings/utf_string_conversions.h" #include "client/crashpad_info.h" #include "client/simple_address_range_bag.h" @@ -211,8 +213,9 @@ ModuleSnapshotWin::CustomMinidumpStreams() const { } std::vector result; - for (const auto* stream : streams_) - result.push_back(stream); + for (const auto& stream : streams_) { + result.push_back(stream.get()); + } return result; } @@ -289,7 +292,7 @@ void ModuleSnapshotWin::GetCrashpadExtraMemoryRanges( template void ModuleSnapshotWin::GetCrashpadUserMinidumpStreams( - PointerVector* streams) const { + std::vector>* streams) const { process_types::CrashpadInfo crashpad_info; if (!pe_image_reader_->GetCrashpadInfo(&crashpad_info)) return; @@ -308,8 +311,8 @@ void ModuleSnapshotWin::GetCrashpadUserMinidumpStreams( new internal::MemorySnapshotWin()); memory->Initialize( process_reader_, list_entry.base_address, list_entry.size); - streams->push_back( - new UserMinidumpStream(list_entry.stream_type, memory.release())); + streams->push_back(std::make_unique( + list_entry.stream_type, memory.release())); } cur = list_entry.next; diff --git a/snapshot/win/module_snapshot_win.h b/snapshot/win/module_snapshot_win.h index 89c42b79..4cc7b842 100644 --- a/snapshot/win/module_snapshot_win.h +++ b/snapshot/win/module_snapshot_win.h @@ -29,7 +29,6 @@ #include "snapshot/win/process_reader_win.h" #include "util/misc/initialization_state.h" #include "util/misc/initialization_state_dcheck.h" -#include "util/stdlib/pointer_container.h" #include "util/win/process_info.h" namespace crashpad { @@ -99,7 +98,7 @@ class ModuleSnapshotWin final : public ModuleSnapshot { template void GetCrashpadUserMinidumpStreams( - PointerVector* streams) const; + std::vector>* streams) const; // Initializes vs_fixed_file_info_ if it has not yet been initialized, and // returns a pointer to it. Returns nullptr on failure, with a message logged @@ -114,7 +113,7 @@ class ModuleSnapshotWin final : public ModuleSnapshot { time_t timestamp_; uint32_t age_; // Too const-y: https://crashpad.chromium.org/bug/9. - mutable PointerVector streams_; + mutable std::vector> streams_; InitializationStateDcheck initialized_; // VSFixedFileInfo() is logically const, but updates these members on the diff --git a/snapshot/win/process_snapshot_win.cc b/snapshot/win/process_snapshot_win.cc index 3f733616..532527b4 100644 --- a/snapshot/win/process_snapshot_win.cc +++ b/snapshot/win/process_snapshot_win.cc @@ -18,6 +18,7 @@ #include #include +#include #include "base/logging.h" #include "base/strings/stringprintf.h" @@ -100,7 +101,8 @@ bool ProcessSnapshotWin::Initialize( for (const MEMORY_BASIC_INFORMATION64& mbi : process_reader_.GetProcessInfo().MemoryInfo()) { - memory_map_.push_back(new internal::MemoryMapRegionSnapshotWin(mbi)); + memory_map_.push_back( + std::make_unique(mbi)); } for (const auto& module : modules_) { @@ -169,8 +171,8 @@ const SystemSnapshot* ProcessSnapshotWin::System() const { std::vector ProcessSnapshotWin::Threads() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); std::vector threads; - for (internal::ThreadSnapshotWin* thread : threads_) { - threads.push_back(thread); + for (const auto& thread : threads_) { + threads.push_back(thread.get()); } return threads; } @@ -178,8 +180,8 @@ std::vector ProcessSnapshotWin::Threads() const { std::vector ProcessSnapshotWin::Modules() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); std::vector modules; - for (internal::ModuleSnapshotWin* module : modules_) { - modules.push_back(module); + for (const auto& module : modules_) { + modules.push_back(module.get()); } return modules; } @@ -197,8 +199,9 @@ const ExceptionSnapshot* ProcessSnapshotWin::Exception() const { std::vector ProcessSnapshotWin::MemoryMap() const { std::vector memory_map; - for (const auto& item : memory_map_) - memory_map.push_back(item); + for (const auto& item : memory_map_) { + memory_map.push_back(item.get()); + } return memory_map; } @@ -223,8 +226,9 @@ std::vector ProcessSnapshotWin::Handles() const { std::vector ProcessSnapshotWin::ExtraMemory() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); std::vector extra_memory; - for (const auto& em : extra_memory_) - extra_memory.push_back(em); + for (const auto& em : extra_memory_) { + extra_memory.push_back(em.get()); + } return extra_memory; } @@ -243,7 +247,7 @@ void ProcessSnapshotWin::InitializeThreads( if (thread->Initialize(&process_reader_, process_reader_thread, budget_remaining_pointer)) { - threads_.push_back(thread.release()); + threads_.push_back(std::move(thread)); } } } @@ -255,7 +259,7 @@ void ProcessSnapshotWin::InitializeModules() { process_reader_modules) { auto module = std::make_unique(); if (module->Initialize(&process_reader_, process_reader_module)) { - modules_.push_back(module.release()); + modules_.push_back(std::move(module)); } } } @@ -334,7 +338,7 @@ void ProcessSnapshotWin::GetCrashpadOptionsInternal( CrashpadInfoClientOptions* options) { CrashpadInfoClientOptions local_options; - for (internal::ModuleSnapshotWin* module : modules_) { + for (const auto& module : modules_) { CrashpadInfoClientOptions module_options; module->GetCrashpadOptions(&module_options); @@ -448,7 +452,7 @@ void ProcessSnapshotWin::InitializePebData( void ProcessSnapshotWin::AddMemorySnapshot( WinVMAddress address, WinVMSize size, - PointerVector* into) { + std::vector>* into) { if (size == 0) return; @@ -469,23 +473,22 @@ void ProcessSnapshotWin::AddMemorySnapshot( } } - internal::MemorySnapshotWin* memory_snapshot = - new internal::MemorySnapshotWin(); - memory_snapshot->Initialize(&process_reader_, address, size); - into->push_back(memory_snapshot); + into->push_back(std::make_unique()); + into->back()->Initialize(&process_reader_, address, size); } template void ProcessSnapshotWin::AddMemorySnapshotForUNICODE_STRING( const process_types::UNICODE_STRING& us, - PointerVector* into) { + std::vector>* into) { AddMemorySnapshot(us.Buffer, us.Length, into); } template void ProcessSnapshotWin::AddMemorySnapshotForLdrLIST_ENTRY( - const process_types::LIST_ENTRY& le, size_t offset_of_member, - PointerVector* into) { + const process_types::LIST_ENTRY& le, + size_t offset_of_member, + std::vector>* into) { // Walk the doubly-linked list of entries, adding the list memory itself, as // well as pointed-to strings. typename Traits::Pointer last = le.Blink; @@ -535,7 +538,7 @@ WinVMSize ProcessSnapshotWin::DetermineSizeOfEnvironmentBlock( template void ProcessSnapshotWin::ReadLock( WinVMAddress start, - PointerVector* into) { + std::vector>* into) { // We're walking the RTL_CRITICAL_SECTION_DEBUG ProcessLocksList, but starting // from an actual RTL_CRITICAL_SECTION, so start by getting to the first // RTL_CRITICAL_SECTION_DEBUG. diff --git a/snapshot/win/process_snapshot_win.h b/snapshot/win/process_snapshot_win.h index 8ae59335..9250c13c 100644 --- a/snapshot/win/process_snapshot_win.h +++ b/snapshot/win/process_snapshot_win.h @@ -44,7 +44,6 @@ #include "snapshot/win/thread_snapshot_win.h" #include "util/misc/initialization_state_dcheck.h" #include "util/misc/uuid.h" -#include "util/stdlib/pointer_container.h" #include "util/win/address_types.h" #include "util/win/process_structs.h" @@ -150,20 +149,21 @@ class ProcessSnapshotWin final : public ProcessSnapshot { template void InitializePebData(WinVMAddress debug_critical_section_address); - void AddMemorySnapshot(WinVMAddress address, - WinVMSize size, - PointerVector* into); + void AddMemorySnapshot( + WinVMAddress address, + WinVMSize size, + std::vector>* into); template void AddMemorySnapshotForUNICODE_STRING( const process_types::UNICODE_STRING& us, - PointerVector* into); + std::vector>* into); template void AddMemorySnapshotForLdrLIST_ENTRY( const process_types::LIST_ENTRY& le, size_t offset_of_member, - PointerVector* into); + std::vector>* into); WinVMSize DetermineSizeOfEnvironmentBlock( WinVMAddress start_of_environment_block); @@ -171,16 +171,18 @@ class ProcessSnapshotWin final : public ProcessSnapshot { // Starting from the address of a CRITICAL_SECTION, add a lock and, if valid, // its .DebugInfo field to the snapshot. template - void ReadLock(WinVMAddress start, - PointerVector* into); + void ReadLock( + WinVMAddress start, + std::vector>* into); internal::SystemSnapshotWin system_; - PointerVector extra_memory_; - PointerVector threads_; - PointerVector modules_; + std::vector> extra_memory_; + std::vector> threads_; + std::vector> modules_; std::vector unloaded_modules_; std::unique_ptr exception_; - PointerVector memory_map_; + std::vector> + memory_map_; ProcessReaderWin process_reader_; UUID report_id_; UUID client_id_; diff --git a/snapshot/win/thread_snapshot_win.cc b/snapshot/win/thread_snapshot_win.cc index d737c14b..3b927f92 100644 --- a/snapshot/win/thread_snapshot_win.cc +++ b/snapshot/win/thread_snapshot_win.cc @@ -128,9 +128,9 @@ std::vector ThreadSnapshotWin::ExtraMemory() const { std::vector result; result.reserve(1 + pointed_to_memory_.size()); result.push_back(&teb_); - std::copy(pointed_to_memory_.begin(), - pointed_to_memory_.end(), - std::back_inserter(result)); + for (const auto& pointed_to_memory : pointed_to_memory_) { + result.push_back(pointed_to_memory.get()); + } return result; } diff --git a/snapshot/win/thread_snapshot_win.h b/snapshot/win/thread_snapshot_win.h index 7df23ab3..273fc7f0 100644 --- a/snapshot/win/thread_snapshot_win.h +++ b/snapshot/win/thread_snapshot_win.h @@ -17,6 +17,7 @@ #include +#include #include #include "base/macros.h" @@ -27,7 +28,6 @@ #include "snapshot/win/memory_snapshot_win.h" #include "snapshot/win/process_reader_win.h" #include "util/misc/initialization_state_dcheck.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -82,7 +82,7 @@ class ThreadSnapshotWin final : public ThreadSnapshot { MemorySnapshotWin teb_; ProcessReaderWin::Thread thread_; InitializationStateDcheck initialized_; - PointerVector pointed_to_memory_; + std::vector> pointed_to_memory_; DISALLOW_COPY_AND_ASSIGN(ThreadSnapshotWin); }; diff --git a/util/linux/direct_ptrace_connection.cc b/util/linux/direct_ptrace_connection.cc index 1fead9cd..78092bb9 100644 --- a/util/linux/direct_ptrace_connection.cc +++ b/util/linux/direct_ptrace_connection.cc @@ -14,7 +14,7 @@ #include "util/linux/direct_ptrace_connection.h" -#include +#include namespace crashpad { @@ -49,7 +49,7 @@ bool DirectPtraceConnection::Attach(pid_t tid) { if (!attach->ResetAttach(tid)) { return false; } - attachments_.push_back(attach.release()); + attachments_.push_back(std::move(attach)); return true; } diff --git a/util/linux/direct_ptrace_connection.h b/util/linux/direct_ptrace_connection.h index 5f9f4f93..f1d7ab5f 100644 --- a/util/linux/direct_ptrace_connection.h +++ b/util/linux/direct_ptrace_connection.h @@ -17,12 +17,14 @@ #include +#include +#include + #include "base/macros.h" #include "util/linux/ptrace_connection.h" #include "util/linux/ptracer.h" #include "util/linux/scoped_ptrace_attach.h" #include "util/misc/initialization_state_dcheck.h" -#include "util/stdlib/pointer_container.h" namespace crashpad { @@ -52,7 +54,7 @@ class DirectPtraceConnection : public PtraceConnection { bool GetThreadInfo(pid_t tid, ThreadInfo* info) override; private: - PointerVector attachments_; + std::vector> attachments_; pid_t pid_; Ptracer ptracer_; InitializationStateDcheck initialized_; diff --git a/util/stdlib/pointer_container.h b/util/stdlib/pointer_container.h deleted file mode 100644 index 7d2d5d06..00000000 --- a/util/stdlib/pointer_container.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2014 The Crashpad Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef CRASHPAD_UTIL_STDLIB_POINTER_CONTAINER_H_ -#define CRASHPAD_UTIL_STDLIB_POINTER_CONTAINER_H_ - -#include - -#include "base/macros.h" - -namespace crashpad { - -//! \brief Allows a `std::vector` to “own” pointer elements stored in it. -//! -//! When the vector is destroyed, `delete` will be called on its pointer -//! elements. -//! -//! \note No attempt is made to `delete` elements that are removed from the -//! vector by other means, such as replacement or `clear()`. -template -class PointerVector : public std::vector { - public: - PointerVector() : std::vector() {} - - ~PointerVector() { - for (T* item : *this) - delete item; - } - - private: - DISALLOW_COPY_AND_ASSIGN(PointerVector); -}; - -} // namespace crashpad - -#endif // CRASHPAD_UTIL_STDLIB_POINTER_CONTAINER_H_ diff --git a/util/util.gyp b/util/util.gyp index 50a57726..2b463c62 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -195,7 +195,6 @@ 'stdlib/aligned_allocator.h', 'stdlib/map_insert.h', 'stdlib/objc.h', - 'stdlib/pointer_container.h', 'stdlib/string_number_conversion.cc', 'stdlib/string_number_conversion.h', 'stdlib/strlcpy.cc',