Remove PointerVector<> and replace with std::vector<std::unique_ptr<>>

As mentioned at
https://chromium-review.googlesource.com/c/crashpad/crashpad/+/721978/13/tools/crashpad_http_upload.cc#90
Change-Id: I4820346cc0b0bf26633e1de598c884af8af19983
Reviewed-on: https://chromium-review.googlesource.com/724744
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Mark Mentovai 2017-10-19 00:26:38 -04:00 committed by Commit Bot
parent 68a0e736c6
commit 419f25eac8
49 changed files with 207 additions and 244 deletions

View File

@ -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<internal::MinidumpWritable*> MinidumpFileWriter::Children() {
DCHECK_EQ(streams_.size(), stream_types_.size());
std::vector<MinidumpWritable*> 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<WritableIoVec> 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);

View File

@ -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<internal::MinidumpStreamWriter> streams_;
std::vector<std::unique_ptr<internal::MinidumpStreamWriter>> streams_;
// Protects against multiple streams with the same ID being added.
std::set<MinidumpStreamType> stream_types_;

View File

@ -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<internal::MinidumpWritable*> MinidumpMemoryListWriter::Children() {
DCHECK_LE(children_.size(), memory_writers_.size());
std::vector<MinidumpWritable*> children;
for (SnapshotMinidumpMemoryWriter* child : children_) {
children.push_back(child);
for (const auto& child : children_) {
children.push_back(child.get());
}
return children;

View File

@ -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<SnapshotMinidumpMemoryWriter*> memory_writers_; // weak
PointerVector<SnapshotMinidumpMemoryWriter> children_;
std::vector<std::unique_ptr<SnapshotMinidumpMemoryWriter>> children_;
MINIDUMP_MEMORY_LIST memory_list_base_;
DISALLOW_COPY_AND_ASSIGN(MinidumpMemoryListWriter);

View File

@ -313,13 +313,13 @@ TEST(MinidumpMemoryWriter, AddFromSnapshot) {
expect_memory_descriptors[2].Memory.DataSize = 0x800;
values[2] = 0xa9;
PointerVector<TestMemorySnapshot> memory_snapshots_owner;
std::vector<std::unique_ptr<TestMemorySnapshot>> memory_snapshots_owner;
std::vector<const MemorySnapshot*> 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>());
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);

View File

@ -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<MinidumpWritable*> 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;

View File

@ -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<MinidumpModuleCrashpadInfoWriter> module_crashpad_infos_;
std::vector<std::unique_ptr<MinidumpModuleCrashpadInfoWriter>>
module_crashpad_infos_;
std::vector<MinidumpModuleCrashpadInfoLink> module_crashpad_info_links_;
MinidumpModuleCrashpadInfoList module_crashpad_info_list_base_;

View File

@ -394,7 +394,7 @@ void MinidumpModuleListWriter::AddModule(
std::unique_ptr<MinidumpModuleWriter> 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<internal::MinidumpWritable*> MinidumpModuleListWriter::Children() {
DCHECK_GE(state(), kStateFrozen);
std::vector<MinidumpWritable*> 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<WritableIoVec> 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);

View File

@ -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<MinidumpModuleWriter> modules_;
std::vector<std::unique_ptr<MinidumpModuleWriter>> modules_;
MINIDUMP_MODULE_LIST module_list_base_;
DISALLOW_COPY_AND_ASSIGN(MinidumpModuleListWriter);

View File

@ -703,11 +703,11 @@ TEST(MinidumpModuleWriter, InitializeFromSnapshot) {
uuids[2].InitializeFromBytes(kUUIDBytes2);
ages[2] = 30;
PointerVector<TestModuleSnapshot> module_snapshots_owner;
std::vector<std::unique_ptr<TestModuleSnapshot>> module_snapshots_owner;
std::vector<const ModuleSnapshot*> 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>());
TestModuleSnapshot* module_snapshot = module_snapshots_owner.back().get();
InitializeTestModuleSnapshotFromMinidumpModule(module_snapshot,
expect_modules[index],
module_paths[index],

View File

@ -14,6 +14,8 @@
#include "minidump/minidump_rva_list_writer.h"
#include <utility>
#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<MinidumpWritable> 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<MinidumpWritable*> MinidumpRVAListWriter::Children() {
DCHECK_GE(state(), kStateFrozen);
std::vector<MinidumpWritable*> children;
for (MinidumpWritable* child : children_) {
children.push_back(child);
for (const auto& child : children_) {
children.push_back(child.get());
}
return children;

View File

@ -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<MinidumpRVAList> rva_list_base_;
PointerVector<MinidumpWritable> children_;
std::vector<std::unique_ptr<MinidumpWritable>> children_;
std::vector<RVA> child_rvas_;
DISALLOW_COPY_AND_ASSIGN(MinidumpRVAListWriter);

View File

@ -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<internal::MinidumpWritable*> MinidumpThreadListWriter::Children() {
DCHECK_GE(state(), kStateFrozen);
std::vector<MinidumpWritable*> 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<WritableIoVec> 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);

View File

@ -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<MinidumpThreadWriter> threads_;
std::vector<std::unique_ptr<MinidumpThreadWriter>> threads_;
MinidumpMemoryListWriter* memory_list_writer_; // weak
MINIDUMP_THREAD_LIST thread_list_base_;

View File

@ -585,11 +585,11 @@ void RunInitializeFromSnapshotTest(bool thread_id_collision) {
expect_threads[2].ThreadId = static_cast<uint32_t>(thread_ids[2]);
}
PointerVector<TestThreadSnapshot> thread_snapshots_owner;
std::vector<std::unique_ptr<TestThreadSnapshot>> thread_snapshots_owner;
std::vector<const ThreadSnapshot*> 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>());
TestThreadSnapshot* thread_snapshot = thread_snapshots_owner.back().get();
thread_snapshot->SetThreadID(thread_ids[index]);
thread_snapshot->SetSuspendCount(expect_threads[index].SuspendCount);

View File

@ -15,6 +15,7 @@
#include "minidump/minidump_unloaded_module_writer.h"
#include <limits>
#include <utility>
#include "minidump/minidump_writer_util.h"
#include "util/file/file_writer.h"
@ -133,7 +134,7 @@ void MinidumpUnloadedModuleListWriter::AddUnloadedModule(
std::unique_ptr<MinidumpUnloadedModuleWriter> 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<MinidumpWritable*> 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<WritableIoVec> 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);

View File

@ -143,7 +143,7 @@ class MinidumpUnloadedModuleListWriter final
MinidumpStreamType StreamType() const override;
private:
PointerVector<MinidumpUnloadedModuleWriter> unloaded_modules_;
std::vector<std::unique_ptr<MinidumpUnloadedModuleWriter>> unloaded_modules_;
MINIDUMP_UNLOADED_MODULE_LIST unloaded_module_list_base_;
DISALLOW_COPY_AND_ASSIGN(MinidumpUnloadedModuleListWriter);

View File

@ -25,6 +25,7 @@
#include <map>
#include <string>
#include <utility>
#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* 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<Thread> threads_;
std::vector<std::unique_ptr<Thread>> threads_;
DISALLOW_COPY_AND_ASSIGN(TestThreadPool);
};

View File

@ -20,7 +20,6 @@
#include <limits>
#include <utility>
#include <vector>
#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>());
MachOImageSegmentReader* segment = segments_.back().get();
if (!segment->Initialize(process_reader_,
load_command_address,

View File

@ -22,12 +22,12 @@
#include <map>
#include <memory>
#include <string>
#include <vector>
#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<MachOImageSegmentReader> segments_;
std::vector<std::unique_ptr<MachOImageSegmentReader>> segments_;
std::map<std::string, size_t> segment_map_;
std::string module_name_;
std::string module_info_;

View File

@ -19,6 +19,7 @@
#include <mach-o/loader.h>
#include <algorithm>
#include <utility>
#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 cant be determined.
module_readers_.push_back(reader.release());
module_readers_.push_back(std::move(reader));
modules_.push_back(module);
}
}

View File

@ -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<Thread> threads_; // owns send rights
std::vector<Module> modules_;
PointerVector<MachOImageReader> module_readers_;
std::vector<std::unique_ptr<MachOImageReader>> module_readers_;
std::unique_ptr<TaskMemory> task_memory_;
task_t task_; // weak
InitializationStateDcheck initialized_;

View File

@ -23,8 +23,7 @@
#include <sys/stat.h>
#include <map>
#include <string>
#include <vector>
#include <utility>
#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 threads 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>());
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 threads ThreadMain(), so they cannot move around in memory.
PointerVector<ThreadInfo> thread_infos_;
std::vector<std::unique_ptr<ThreadInfo>> thread_infos_;
DISALLOW_COPY_AND_ASSIGN(TestThreadPool);
};

View File

@ -14,6 +14,8 @@
#include "snapshot/mac/process_snapshot_mac.h"
#include <utility>
#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<const ThreadSnapshot*> ProcessSnapshotMac::Threads() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
std::vector<const ThreadSnapshot*> 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<const ThreadSnapshot*> ProcessSnapshotMac::Threads() const {
std::vector<const ModuleSnapshot*> ProcessSnapshotMac::Modules() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
std::vector<const ModuleSnapshot*> 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<internal::ThreadSnapshotMac>();
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<internal::ModuleSnapshotMac>();
if (module->Initialize(&process_reader_, process_reader_module)) {
modules_.push_back(module.release());
modules_.push_back(std::move(module));
}
}
}

View File

@ -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<internal::ThreadSnapshotMac> threads_;
PointerVector<internal::ModuleSnapshotMac> modules_;
std::vector<std::unique_ptr<internal::ThreadSnapshotMac>> threads_;
std::vector<std::unique_ptr<internal::ModuleSnapshotMac>> modules_;
std::unique_ptr<internal::ExceptionSnapshotMac> exception_;
ProcessReader process_reader_;
UUID report_id_;

View File

@ -14,7 +14,6 @@
#include "snapshot/minidump/process_snapshot_minidump.h"
#include <memory>
#include <utility>
#include "snapshot/minidump/minidump_simple_string_dictionary_reader.h"
@ -166,8 +165,8 @@ std::vector<const ThreadSnapshot*> ProcessSnapshotMinidump::Threads() const {
std::vector<const ModuleSnapshot*> ProcessSnapshotMinidump::Modules() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
std::vector<const ModuleSnapshot*> 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;

View File

@ -21,6 +21,7 @@
#include <sys/time.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
@ -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<MINIDUMP_DIRECTORY> stream_directory_;
std::map<MinidumpStreamType, const MINIDUMP_LOCATION_DESCRIPTOR*> stream_map_;
PointerVector<internal::ModuleSnapshotMinidump> modules_;
std::vector<std::unique_ptr<internal::ModuleSnapshotMinidump>> modules_;
std::vector<UnloadedModuleSnapshot> unloaded_modules_;
MinidumpCrashpadInfo crashpad_info_;
std::map<std::string, std::string> annotations_simple_map_;

View File

@ -57,8 +57,9 @@ const std::vector<uint64_t>& TestExceptionSnapshot::Codes() const {
std::vector<const MemorySnapshot*> TestExceptionSnapshot::ExtraMemory() const {
std::vector<const MemorySnapshot*> 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;
}

View File

@ -18,12 +18,12 @@
#include <stdint.h>
#include <memory>
#include <utility>
#include <vector>
#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<uint64_t>& codes) { codes_ = codes; }
void AddExtraMemory(std::unique_ptr<MemorySnapshot> 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<uint64_t> codes_;
PointerVector<MemorySnapshot> extra_memory_;
std::vector<std::unique_ptr<MemorySnapshot>> extra_memory_;
DISALLOW_COPY_AND_ASSIGN(TestExceptionSnapshot);
};

View File

@ -100,7 +100,7 @@ std::set<CheckedRange<uint64_t>> TestModuleSnapshot::ExtraMemoryRanges() const {
std::vector<const UserMinidumpStream*>
TestModuleSnapshot::CustomMinidumpStreams() const {
return custom_minidump_streams_;
return std::vector<const UserMinidumpStream*>();
}
} // namespace test

View File

@ -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<CheckedRange<uint64_t>>& 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<std::string> annotations_vector_;
std::map<std::string, std::string> annotations_simple_map_;
std::set<CheckedRange<uint64_t>> extra_memory_ranges_;
PointerVector<const UserMinidumpStream> custom_minidump_streams_;
DISALLOW_COPY_AND_ASSIGN(TestModuleSnapshot);
};

View File

@ -82,16 +82,16 @@ const SystemSnapshot* TestProcessSnapshot::System() const {
std::vector<const ThreadSnapshot*> TestProcessSnapshot::Threads() const {
std::vector<const ThreadSnapshot*> threads;
for (const ThreadSnapshot* thread : threads_) {
threads.push_back(thread);
for (const auto& thread : threads_) {
threads.push_back(thread.get());
}
return threads;
}
std::vector<const ModuleSnapshot*> TestProcessSnapshot::Modules() const {
std::vector<const ModuleSnapshot*> 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<const MemoryMapRegionSnapshot*> TestProcessSnapshot::MemoryMap()
const {
std::vector<const MemoryMapRegionSnapshot*> 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<HandleSnapshot> TestProcessSnapshot::Handles() const {
std::vector<const MemorySnapshot*> TestProcessSnapshot::ExtraMemory() const {
std::vector<const MemorySnapshot*> 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;
}

View File

@ -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<ThreadSnapshot> 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<ModuleSnapshot> 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<MemoryMapRegionSnapshot> 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<MemorySnapshot> 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<std::string, std::string> annotations_simple_map_;
std::unique_ptr<SystemSnapshot> system_;
PointerVector<ThreadSnapshot> threads_;
PointerVector<ModuleSnapshot> modules_;
std::vector<std::unique_ptr<ThreadSnapshot>> threads_;
std::vector<std::unique_ptr<ModuleSnapshot>> modules_;
std::vector<UnloadedModuleSnapshot> unloaded_modules_;
std::unique_ptr<ExceptionSnapshot> exception_;
PointerVector<MemoryMapRegionSnapshot> memory_map_;
std::vector<std::unique_ptr<MemoryMapRegionSnapshot>> memory_map_;
std::vector<HandleSnapshot> handles_;
PointerVector<MemorySnapshot> extra_memory_;
std::vector<std::unique_ptr<MemorySnapshot>> extra_memory_;
DISALLOW_COPY_AND_ASSIGN(TestProcessSnapshot);
};

View File

@ -57,8 +57,9 @@ uint64_t TestThreadSnapshot::ThreadSpecificDataAddress() const {
std::vector<const MemorySnapshot*> TestThreadSnapshot::ExtraMemory() const {
std::vector<const MemorySnapshot*> 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;
}

View File

@ -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<MemorySnapshot> 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<MemorySnapshot> extra_memory_;
std::vector<std::unique_ptr<MemorySnapshot>> extra_memory_;
DISALLOW_COPY_AND_ASSIGN(TestThreadSnapshot);
};

View File

@ -14,6 +14,8 @@
#include "snapshot/win/capture_memory_delegate_win.h"
#include <utility>
#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<MemorySnapshotWin>* snapshots,
std::vector<std::unique_ptr<MemorySnapshotWin>>* 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>());
internal::MemorySnapshotWin* snapshot = snapshots_->back().get();
snapshot->Initialize(process_reader_, range.base(), range.size());
snapshots_->push_back(snapshot);
if (budget_remaining_) {
if (!base::IsValueInRangeForNumericType<int64_t>(range.size())) {
*budget_remaining_ = 0;

View File

@ -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 <stdint.h>
#include <memory>
#include <vector>
#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<MemorySnapshotWin>* snapshots,
uint32_t* budget_remaining);
CaptureMemoryDelegateWin(
ProcessReaderWin* process_reader,
const ProcessReaderWin::Thread& thread,
std::vector<std::unique_ptr<MemorySnapshotWin>>* snapshots,
uint32_t* budget_remaining);
// MemoryCaptureDelegate:
bool Is64Bit() const override;
@ -52,8 +58,8 @@ class CaptureMemoryDelegateWin : public CaptureMemory::Delegate {
private:
CheckedRange<uint64_t, uint64_t> stack_;
ProcessReaderWin* process_reader_;
PointerVector<MemorySnapshotWin>* snapshots_;
ProcessReaderWin* process_reader_; // weak
std::vector<std::unique_ptr<MemorySnapshotWin>>* snapshots_; // weak
uint32_t* budget_remaining_;
};

View File

@ -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<const MemorySnapshot*> ExceptionSnapshotWin::ExtraMemory() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
std::vector<const MemorySnapshot*> 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;
}

View File

@ -18,13 +18,15 @@
#include <windows.h>
#include <stdint.h>
#include <memory>
#include <vector>
#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<uint64_t> codes_;
PointerVector<internal::MemorySnapshotWin> extra_memory_;
std::vector<std::unique_ptr<internal::MemorySnapshotWin>> extra_memory_;
uint64_t thread_id_;
uint64_t exception_address_;
uint32_t exception_flags_;

View File

@ -14,6 +14,8 @@
#include "snapshot/win/module_snapshot_win.h"
#include <utility>
#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<const UserMinidumpStream*> 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 <class Traits>
void ModuleSnapshotWin::GetCrashpadUserMinidumpStreams(
PointerVector<const UserMinidumpStream>* streams) const {
std::vector<std::unique_ptr<const UserMinidumpStream>>* streams) const {
process_types::CrashpadInfo<Traits> 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<UserMinidumpStream>(
list_entry.stream_type, memory.release()));
}
cur = list_entry.next;

View File

@ -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 <class Traits>
void GetCrashpadUserMinidumpStreams(
PointerVector<const UserMinidumpStream>* streams) const;
std::vector<std::unique_ptr<const UserMinidumpStream>>* 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<const UserMinidumpStream> streams_;
mutable std::vector<std::unique_ptr<const UserMinidumpStream>> streams_;
InitializationStateDcheck initialized_;
// VSFixedFileInfo() is logically const, but updates these members on the

View File

@ -18,6 +18,7 @@
#include <wchar.h>
#include <algorithm>
#include <utility>
#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<internal::MemoryMapRegionSnapshotWin>(mbi));
}
for (const auto& module : modules_) {
@ -169,8 +171,8 @@ const SystemSnapshot* ProcessSnapshotWin::System() const {
std::vector<const ThreadSnapshot*> ProcessSnapshotWin::Threads() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
std::vector<const ThreadSnapshot*> 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<const ThreadSnapshot*> ProcessSnapshotWin::Threads() const {
std::vector<const ModuleSnapshot*> ProcessSnapshotWin::Modules() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
std::vector<const ModuleSnapshot*> 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<const MemoryMapRegionSnapshot*> ProcessSnapshotWin::MemoryMap()
const {
std::vector<const MemoryMapRegionSnapshot*> 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<HandleSnapshot> ProcessSnapshotWin::Handles() const {
std::vector<const MemorySnapshot*> ProcessSnapshotWin::ExtraMemory() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
std::vector<const MemorySnapshot*> 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<internal::ModuleSnapshotWin>();
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<internal::MemorySnapshotWin>* into) {
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* 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<internal::MemorySnapshotWin>());
into->back()->Initialize(&process_reader_, address, size);
}
template <class Traits>
void ProcessSnapshotWin::AddMemorySnapshotForUNICODE_STRING(
const process_types::UNICODE_STRING<Traits>& us,
PointerVector<internal::MemorySnapshotWin>* into) {
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into) {
AddMemorySnapshot(us.Buffer, us.Length, into);
}
template <class Traits>
void ProcessSnapshotWin::AddMemorySnapshotForLdrLIST_ENTRY(
const process_types::LIST_ENTRY<Traits>& le, size_t offset_of_member,
PointerVector<internal::MemorySnapshotWin>* into) {
const process_types::LIST_ENTRY<Traits>& le,
size_t offset_of_member,
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* 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 <class Traits>
void ProcessSnapshotWin::ReadLock(
WinVMAddress start,
PointerVector<internal::MemorySnapshotWin>* into) {
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* 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.

View File

@ -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 <class Traits>
void InitializePebData(WinVMAddress debug_critical_section_address);
void AddMemorySnapshot(WinVMAddress address,
WinVMSize size,
PointerVector<internal::MemorySnapshotWin>* into);
void AddMemorySnapshot(
WinVMAddress address,
WinVMSize size,
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into);
template <class Traits>
void AddMemorySnapshotForUNICODE_STRING(
const process_types::UNICODE_STRING<Traits>& us,
PointerVector<internal::MemorySnapshotWin>* into);
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into);
template <class Traits>
void AddMemorySnapshotForLdrLIST_ENTRY(
const process_types::LIST_ENTRY<Traits>& le,
size_t offset_of_member,
PointerVector<internal::MemorySnapshotWin>* into);
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* 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 <class Traits>
void ReadLock(WinVMAddress start,
PointerVector<internal::MemorySnapshotWin>* into);
void ReadLock(
WinVMAddress start,
std::vector<std::unique_ptr<internal::MemorySnapshotWin>>* into);
internal::SystemSnapshotWin system_;
PointerVector<internal::MemorySnapshotWin> extra_memory_;
PointerVector<internal::ThreadSnapshotWin> threads_;
PointerVector<internal::ModuleSnapshotWin> modules_;
std::vector<std::unique_ptr<internal::MemorySnapshotWin>> extra_memory_;
std::vector<std::unique_ptr<internal::ThreadSnapshotWin>> threads_;
std::vector<std::unique_ptr<internal::ModuleSnapshotWin>> modules_;
std::vector<UnloadedModuleSnapshot> unloaded_modules_;
std::unique_ptr<internal::ExceptionSnapshotWin> exception_;
PointerVector<internal::MemoryMapRegionSnapshotWin> memory_map_;
std::vector<std::unique_ptr<internal::MemoryMapRegionSnapshotWin>>
memory_map_;
ProcessReaderWin process_reader_;
UUID report_id_;
UUID client_id_;

View File

@ -128,9 +128,9 @@ std::vector<const MemorySnapshot*> ThreadSnapshotWin::ExtraMemory() const {
std::vector<const MemorySnapshot*> 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;
}

View File

@ -17,6 +17,7 @@
#include <stdint.h>
#include <memory>
#include <vector>
#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<MemorySnapshotWin> pointed_to_memory_;
std::vector<std::unique_ptr<MemorySnapshotWin>> pointed_to_memory_;
DISALLOW_COPY_AND_ASSIGN(ThreadSnapshotWin);
};

View File

@ -14,7 +14,7 @@
#include "util/linux/direct_ptrace_connection.h"
#include <memory>
#include <utility>
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;
}

View File

@ -17,12 +17,14 @@
#include <sys/types.h>
#include <memory>
#include <vector>
#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<ScopedPtraceAttach> attachments_;
std::vector<std::unique_ptr<ScopedPtraceAttach>> attachments_;
pid_t pid_;
Ptracer ptracer_;
InitializationStateDcheck initialized_;

View File

@ -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 <vector>
#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 <typename T>
class PointerVector : public std::vector<T*> {
public:
PointerVector() : std::vector<T*>() {}
~PointerVector() {
for (T* item : *this)
delete item;
}
private:
DISALLOW_COPY_AND_ASSIGN(PointerVector);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_STDLIB_POINTER_CONTAINER_H_

View File

@ -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',