From f044345c23c0324942b7375e7a09558267651523 Mon Sep 17 00:00:00 2001 From: "benchan@chromium.org" Date: Fri, 16 Dec 2011 16:42:59 +0000 Subject: 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 --- src/tools/linux/md2core/minidump-2-core.cc | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'src/tools/linux/md2core') 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 #include -#include #include #include #include #include -#include -#include #include #include @@ -50,6 +47,7 @@ #include #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(-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(bytes), st.st_size); - return 0; } -- cgit v1.2.1