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

Side by Side Diff: tools/find_runtime_symbols/parse_proc_maps.py

Issue 10795028: A tool for mapping runtime addresses to symbol names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import re
7 import sys
8
9
10 _MAPS_PATTERN = re.compile(
11 '^([a-f0-9]+)-([a-f0-9]+)\s+(.)(.)(.)(.)\s+([a-f0-9]+)\s+(\S+):(\S+)\s+'
12 '(\d+)\s+(\S+)$', re.IGNORECASE)
13
14
15 class ProcMapsEntry(object):
16 """A class representing one line in /proc/.../maps."""
17
18 def __init__(
19 self, begin, end, readable, writable, executable, private, offset,
20 major, minor, inode, name):
21 self.begin = begin
22 self.end = end
23 self.readable = readable
24 self.writable = writable
25 self.executable = executable
26 self.private = private
27 self.offset = offset
28 self.major = major
29 self.minor = minor
30 self.inode = inode
31 self.name = name
32
33
34 class ProcMaps(object):
35 """A class representing contents in /proc/.../maps."""
36
37 def __init__(self):
38 self._sorted_indexes = []
39 self._dictionary = {}
40 self._sorted = True
41
42 def append(self, entry):
43 if self._sorted_indexes and self._sorted_indexes[-1] > entry.begin:
44 self._sorted = False
45 self._sorted_indexes.append(entry.begin)
46 self._dictionary[entry.begin] = entry
47
48 def iter(self, condition):
49 if not self._sorted:
50 self._sorted_indexes.sort()
51 self._sorted = True
52 for index in self._sorted_indexes:
53 if not condition or condition(self._dictionary[index]):
54 yield self._dictionary[index]
55
56 def __iter__(self):
57 if not self._sorted:
58 self._sorted_indexes.sort()
59 self._sorted = True
60 for index in self._sorted_indexes:
61 yield self._dictionary[index]
62
63
64 def parse_proc_maps(f):
65 table = ProcMaps()
66 for line in f:
67 matched = _MAPS_PATTERN.match(line)
68 if matched:
69 table.append(ProcMapsEntry(
70 int(matched.group(1), 16), # begin
71 int(matched.group(2), 16), # end
72 matched.group(3), # readable
73 matched.group(4), # writable
74 matched.group(5), # executable
75 matched.group(6), # private
76 int(matched.group(7), 16), # offset
77 matched.group(8), # major
78 matched.group(9), # minor
79 int(matched.group(10), 10), # inode
80 matched.group(11) # name
81 ))
82
83 return table
84
85
86 def main():
87 if len(sys.argv) < 2:
88 sys.stderr.write("""Usage:
89 %s /path/to/maps
90 """ % sys.argv[0])
91 return 1
92
93 with open(sys.argv[1], mode='r') as f:
94 maps = parse_proc_maps(f)
95
96 for entry in maps:
97 print "%016x-%016x +%06x %s" % (
98 entry.begin, entry.end, entry.offset, entry.name)
99
100 return 0
101
102
103 if __name__ == '__main__':
104 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698