Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: src/processor/proc_maps_linux.cc

Issue 1251593007: Add support for Linux memory mapping stream and remove ELF header usage (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/processor/minidump.cc ('k') | src/processor/proc_maps_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "google_breakpad/processor/proc_maps_linux.h"
6
7 #include <fcntl.h>
8 #include <stdio.h>
9
10 #if defined(OS_LINUX) || defined(OS_ANDROID)
11 #include <inttypes.h>
12 #endif
13
14 #include "processor/logging.h"
15
16 #if defined(OS_ANDROID) && !defined(__LP64__)
17 // In 32-bit mode, Bionic's inttypes.h defines PRI/SCNxPTR as an
18 // unsigned long int, which is incompatible with Bionic's stdint.h
19 // defining uintptr_t as an unsigned int:
20 // https://code.google.com/p/android/issues/detail?id=57218
21 #undef SCNxPTR
22 #define SCNxPTR "x"
23 #endif
24
25 namespace google_breakpad {
26
27 bool ParseProcMaps(const std::string& input,
28 std::vector<MappedMemoryRegion>* regions_out) {
29 std::vector<MappedMemoryRegion> regions;
30
31 // This isn't async safe nor terribly efficient, but it doesn't need to be at
32 // this point in time.
33
34 // Split the string by newlines.
35 std::vector<std::string> lines;
36 std::string line = "";
37 for (size_t i = 0; i < input.size(); i++) {
38 if (input[i] != '\n' && input[i] != '\r') {
39 line.push_back(input[i]);
40 } else if (line.size() > 0) {
41 lines.push_back(line);
42 line.clear();
43 }
44 }
45 if (line.size() > 0) {
46 BPLOG(ERROR) << "Input doesn't end in newline";
47 return false;
48 }
49
50 for (size_t i = 0; i < lines.size(); ++i) {
51 MappedMemoryRegion region;
52 const char* line = lines[i].c_str();
53 char permissions[5] = {'\0'}; // Ensure NUL-terminated string.
54 int path_index = 0;
55
56 // Sample format from man 5 proc:
57 //
58 // address perms offset dev inode pathname
59 // 08048000-08056000 r-xp 00000000 03:0c 64593 /usr/sbin/gpm
60 //
61 // The final %n term captures the offset in the input string, which is used
62 // to determine the path name. It *does not* increment the return value.
63 // Refer to man 3 sscanf for details.
64 if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR " %4c %lx %hhx:%hhx %ld %n",
65 &region.start, &region.end, permissions, &region.offset,
66 &region.major_device, &region.minor_device, &region.inode,
67 &path_index) < 7) {
68 BPLOG(ERROR) << "sscanf failed for line: " << line;
69 return false;
70 }
71
72 region.permissions = 0;
73
74 if (permissions[0] == 'r')
75 region.permissions |= MappedMemoryRegion::READ;
76 else if (permissions[0] != '-')
77 return false;
78
79 if (permissions[1] == 'w')
80 region.permissions |= MappedMemoryRegion::WRITE;
81 else if (permissions[1] != '-')
82 return false;
83
84 if (permissions[2] == 'x')
85 region.permissions |= MappedMemoryRegion::EXECUTE;
86 else if (permissions[2] != '-')
87 return false;
88
89 if (permissions[3] == 'p')
90 region.permissions |= MappedMemoryRegion::PRIVATE;
91 else if (permissions[3] != 's' && permissions[3] != 'S') // Shared memory.
92 return false;
93
94 // Pushing then assigning saves us a string copy.
95 regions.push_back(region);
96 regions.back().path.assign(line + path_index);
97 }
98
99 regions_out->swap(regions);
100 return true;
101 }
102
103 } // namespace google_breakpad
OLDNEW
« no previous file with comments | « src/processor/minidump.cc ('k') | src/processor/proc_maps_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698