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
This commit is contained in:
benchan@chromium.org 2012-01-11 01:31:35 +00:00
parent 384c078d2e
commit 577304f02a
6 changed files with 146 additions and 89 deletions

View file

@ -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);

View file

@ -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);