diff options
author | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2011-12-16 16:42:59 +0000 |
---|---|---|
committer | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2011-12-16 16:42:59 +0000 |
commit | f044345c23c0324942b7375e7a09558267651523 (patch) | |
tree | 55a0847ef9681e390bad9c97458c352cc1da75ed /src/tools/linux/md2core | |
parent | Fix ContextDeathTest.X86BadFlags unit test on Mac OS X. (diff) | |
download | breakpad-f044345c23c0324942b7375e7a09558267651523.tar.xz |
Refactor code in preparation of merging with the fork in Chromium OS.
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 a MemoryRange class for encapsulating and checking read access
to a contiguous range of memory.
2. Add a MemoryMappedFile class for mapping a file into memory for
read-only access.
3. Refactor other source code to use MemoryMappedFile.
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.
4. Run minidump-2-core to covnert a minidump file to a core file.
Review URL: http://breakpad.appspot.com/332001
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@895 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/tools/linux/md2core')
-rw-r--r-- | src/tools/linux/md2core/minidump-2-core.cc | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/tools/linux/md2core/minidump-2-core.cc b/src/tools/linux/md2core/minidump-2-core.cc index efec22e4..ddefecc0 100644 --- a/src/tools/linux/md2core/minidump-2-core.cc +++ b/src/tools/linux/md2core/minidump-2-core.cc @@ -35,13 +35,10 @@ #include <elf.h> #include <errno.h> -#include <fcntl.h> #include <link.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/mman.h> -#include <sys/stat.h> #include <sys/user.h> #include <unistd.h> @@ -50,6 +47,7 @@ #include <vector> #include "client/linux/minidump_writer/minidump_extension_linux.h" +#include "common/linux/memory_mapped_file.h" #include "google_breakpad/common/minidump_format.h" #include "google_breakpad/common/minidump_cpu_x86.h" #include "third_party/lss/linux_syscall_support.h" @@ -77,6 +75,8 @@ #define ELF_ARCH EM_MIPS #endif +using google_breakpad::MemoryMappedFile; + static const MDRVA kInvalidMDRVA = static_cast<MDRVA>(-1); static bool verbose; @@ -970,21 +970,13 @@ main(int argc, char** argv) { if (argc != argi + 1) return usage(argv[0]); - const int fd = open(argv[argi], O_RDONLY); - if (fd < 0) - return usage(argv[0]); - - struct stat st; - fstat(fd, &st); - - const void* bytes = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - close(fd); - if (bytes == MAP_FAILED) { - perror("Failed to mmap dump file"); + MemoryMappedFile mapped_file(argv[argi]); + if (!mapped_file.data()) { + fprintf(stderr, "Failed to mmap dump file\n"); return 1; } - MMappedRange dump(bytes, st.st_size); + MMappedRange dump(mapped_file.data(), mapped_file.size()); const MDRawHeader* header = (const MDRawHeader*) dump.GetObject(0, sizeof(MDRawHeader)); @@ -1187,7 +1179,5 @@ main(int argc, char** argv) { } } - munmap(const_cast<void*>(bytes), st.st_size); - return 0; } |