Chromium Code Reviews| Index: tools/find_runtime_symbols/parse_proc_maps.py |
| diff --git a/tools/find_runtime_symbols/parse_proc_maps.py b/tools/find_runtime_symbols/parse_proc_maps.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..35b4909ff31a8e6821d9dfb00c6fa03f16956b3e |
| --- /dev/null |
| +++ b/tools/find_runtime_symbols/parse_proc_maps.py |
| @@ -0,0 +1,90 @@ |
| +#!/usr/bin/env python |
| + |
| +import re |
| +import sys |
| + |
| +class ProcMapsEntry(object): |
|
M-A Ruel
2012/07/19 15:21:15
A oneliner docstring would help here and in a few
Dai Mikurube (NOT FULLTIME)
2012/07/20 04:32:39
Done.
|
| + def __init__( |
| + self, begin, end, readable, writable, executable, private, offset, |
| + major, minor, inode, name): |
| + self.begin = begin |
| + self.end = end |
| + self.readable = readable |
| + self.writable = writable |
| + self.executable = executable |
| + self.private = private |
| + self.offset = offset |
| + self.major = major |
| + self.minor = minor |
| + self.inode = inode |
| + self.name = name |
| + |
| + |
| +class ProcMaps(object): |
| + |
| + def __init__(self): |
| + self._sorted_indexes = [] |
| + self._dictionary = {} |
| + self._sorted = True |
| + |
| + def append(self, entry): |
| + if self._sorted_indexes and self._sorted_indexes[-1] > entry.begin: |
| + self._sorted = False |
| + self._sorted_indexes.append(entry.begin) |
| + self._dictionary[entry.begin] = entry |
| + |
| + def iter(self, condition): |
| + if not self._sorted: |
| + self._sorted_indexes.sort() |
| + self._sorted = True |
| + for index in self._sorted_indexes: |
| + if not condition or condition(self._dictionary[index]): |
| + yield self._dictionary[index] |
| + |
| + def __iter__(self): |
| + if not self._sorted: |
| + self._sorted_indexes.sort() |
| + self._sorted = True |
| + for index in self._sorted_indexes: |
| + yield self._dictionary[index] |
| + |
| + |
| +_MAPS_PATTERN = re.compile( |
|
M-A Ruel
2012/07/19 15:21:15
All constants in every files at top of the file
Dai Mikurube (NOT FULLTIME)
2012/07/20 04:32:39
Done.
|
| + '^([a-f0-9]+)-([a-f0-9]+)\s+(.)(.)(.)(.)\s+([a-f0-9]+)\s+(\S+):(\S+)\s+' |
| + '(\d+)\s+(\S+)$', re.IGNORECASE) |
| + |
| +def parse_proc_maps(FILE): |
| + table = ProcMaps() |
| + for line in FILE: |
| + matched = _MAPS_PATTERN.match(line) |
| + if matched: |
| + table.append(ProcMapsEntry( |
| + int(matched.group(1), 16), # begin |
| + int(matched.group(2), 16), # end |
| + matched.group(3), # readable |
| + matched.group(4), # writable |
| + matched.group(5), # executable |
| + matched.group(6), # private |
| + int(matched.group(7), 16), # offset |
| + matched.group(8), # major |
| + matched.group(9), # minor |
| + int(matched.group(10), 10), # inode |
| + matched.group(11) # name |
| + )) |
| + |
| + return table |
| + |
| + |
| +if __name__ == '__main__': |
| + if len(sys.argv) < 2: |
| + sys.stderr.write("""Usage: |
| +%s /path/to/maps |
| +""" % sys.argv[0]) |
| + sys.exit(1) |
| + |
| + with open(sys.argv[1], mode='r') as FILE: |
| + maps = parse_proc_maps(FILE) |
| + |
| + for entry in maps: |
| + print "%016x-%016x +%06x %s" % ( |
| + entry.begin, entry.end, entry.offset, entry.name) |