aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorbenchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-01-11 01:31:35 +0000
committerbenchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e>2012-01-11 01:31:35 +0000
commit577304f02af6be71c1587d3b880b2a55ac96145b (patch)
treec666d9cb5bbe02ed41a047cc816af4fd283028a9 /src/common
parentClear error state flags in binarystream::rewind(). (diff)
downloadbreakpad-577304f02af6be71c1587d3b880b2a55ac96145b.tar.xz
Refactor LinuxDumper and MinidumpWriter.
This patch is part of a bigger patch that helps merging the breakpad code with the modified version in Chromium OS. Specifically, this patch makes the following changes: 1. Add two convenient methods, back() and empty(), to the wasteful_vector class. 2. Refactor the LinuxDumper class such that it can later be splitted into a base class and two derived classes, one uses the current ptrace implementation and one uses a core file. 3. Refactor the MinidumpWriter class such that it can later use different derived implementations of LinuxDumper. BUG=455 TEST=Tested the following: 1. Build on 32-bit and 64-bit Linux with gcc 4.4.3 and gcc 4.6. 2. Build on Mac OS X 10.6.8 with gcc 4.2 and clang 3.0 (with latest gmock). 3. All unit tests pass. Review URL: http://breakpad.appspot.com/340001 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@902 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common')
-rw-r--r--src/common/memory.h12
-rw-r--r--src/common/memory_unittest.cc7
2 files changed, 18 insertions, 1 deletions
diff --git a/src/common/memory.h b/src/common/memory.h
index a02ac578..e90bd52c 100644
--- a/src/common/memory.h
+++ b/src/common/memory.h
@@ -145,6 +145,18 @@ class wasteful_vector {
used_(0) {
}
+ T& back() {
+ return a_[used_ - 1];
+ }
+
+ const T& back() const {
+ return a_[used_ - 1];
+ }
+
+ bool empty() const {
+ return used_ == 0;
+ }
+
void push_back(const T& new_element) {
if (used_ == allocated_)
Realloc(allocated_ * 2);
diff --git a/src/common/memory_unittest.cc b/src/common/memory_unittest.cc
index 8b2ec410..d580c1fe 100644
--- a/src/common/memory_unittest.cc
+++ b/src/common/memory_unittest.cc
@@ -69,6 +69,7 @@ typedef testing::Test WastefulVectorTest;
TEST(WastefulVectorTest, Setup) {
PageAllocator allocator_;
wasteful_vector<int> v(&allocator_);
+ ASSERT_TRUE(v.empty());
ASSERT_EQ(v.size(), 0u);
}
@@ -76,8 +77,12 @@ TEST(WastefulVectorTest, Simple) {
PageAllocator allocator_;
wasteful_vector<unsigned> v(&allocator_);
- for (unsigned i = 0; i < 256; ++i)
+ for (unsigned i = 0; i < 256; ++i) {
v.push_back(i);
+ ASSERT_EQ(i, v.back());
+ ASSERT_EQ(&v.back(), &v[i]);
+ }
+ ASSERT_FALSE(v.empty());
ASSERT_EQ(v.size(), 256u);
for (unsigned i = 0; i < 256; ++i)
ASSERT_EQ(v[i], i);