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

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

Issue 11299095: Add a first test for tools/find_runtime_symbols. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed Created 8 years 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import re 5 import re
6 import sys
7 6
8 7
9 _MAPS_PATTERN = re.compile( 8 _MAPS_PATTERN = re.compile(
10 '^([a-f0-9]+)-([a-f0-9]+)\s+(.)(.)(.)(.)\s+([a-f0-9]+)\s+(\S+):(\S+)\s+' 9 '^([a-f0-9]+)-([a-f0-9]+)\s+(.)(.)(.)(.)\s+([a-f0-9]+)\s+(\S+):(\S+)\s+'
11 '(\d+)\s+(\S+)$', re.IGNORECASE) 10 '(\d+)\s*(.*)$', re.IGNORECASE)
12 11
13 12
14 class ProcMapsEntry(object): 13 class ProcMapsEntry(object):
15 """A class representing one line in /proc/.../maps.""" 14 """A class representing one line in /proc/.../maps."""
16 15
17 def __init__( 16 def __init__(
18 self, begin, end, readable, writable, executable, private, offset, 17 self, begin, end, readable, writable, executable, private, offset,
19 major, minor, inode, name): 18 major, minor, inode, name):
20 self.begin = begin 19 self.begin = begin
21 self.end = end 20 self.end = end
22 self.readable = readable 21 self.readable = readable
23 self.writable = writable 22 self.writable = writable
24 self.executable = executable 23 self.executable = executable
25 self.private = private 24 self.private = private
26 self.offset = offset 25 self.offset = offset
27 self.major = major 26 self.major = major
28 self.minor = minor 27 self.minor = minor
29 self.inode = inode 28 self.inode = inode
30 self.name = name 29 self.name = name
31 30
31 def as_dict(self):
32 return {
33 'begin': self.begin,
34 'end': self.end,
35 'readable': self.readable,
36 'writable': self.writable,
37 'executable': self.executable,
38 'private': self.private,
39 'offset': self.offset,
40 'major': self.major,
41 'minor': self.minor,
42 'inode': self.inode,
43 'name': self.name,
44 }
M-A Ruel 2012/11/21 09:09:01 align at return, e.g. -4.
Dai Mikurube (NOT FULLTIME) 2012/11/21 09:14:41 Done.
45
32 46
33 class ProcMaps(object): 47 class ProcMaps(object):
34 """A class representing contents in /proc/.../maps.""" 48 """A class representing contents in /proc/.../maps."""
35 49
36 def __init__(self): 50 def __init__(self):
37 self._sorted_indexes = [] 51 self._sorted_indexes = []
38 self._dictionary = {} 52 self._dictionary = {}
39 self._sorted = True 53 self._sorted = True
40 54
41 def append(self, entry):
42 if self._sorted_indexes and self._sorted_indexes[-1] > entry.begin:
43 self._sorted = False
44 self._sorted_indexes.append(entry.begin)
45 self._dictionary[entry.begin] = entry
46
47 def iter(self, condition): 55 def iter(self, condition):
48 if not self._sorted: 56 if not self._sorted:
49 self._sorted_indexes.sort() 57 self._sorted_indexes.sort()
50 self._sorted = True 58 self._sorted = True
51 for index in self._sorted_indexes: 59 for index in self._sorted_indexes:
52 if not condition or condition(self._dictionary[index]): 60 if not condition or condition(self._dictionary[index]):
53 yield self._dictionary[index] 61 yield self._dictionary[index]
54 62
55 def __iter__(self): 63 def __iter__(self):
56 if not self._sorted: 64 if not self._sorted:
57 self._sorted_indexes.sort() 65 self._sorted_indexes.sort()
58 self._sorted = True 66 self._sorted = True
59 for index in self._sorted_indexes: 67 for index in self._sorted_indexes:
60 yield self._dictionary[index] 68 yield self._dictionary[index]
61 69
62 @staticmethod 70 @staticmethod
63 def load(f): 71 def load(f):
64 table = ProcMaps() 72 table = ProcMaps()
65 for line in f: 73 for line in f:
66 matched = _MAPS_PATTERN.match(line) 74 matched = _MAPS_PATTERN.match(line)
67 if matched: 75 if matched:
68 table.append(ProcMapsEntry( 76 table._append(ProcMapsEntry( # pylint: disable=W0212
69 int(matched.group(1), 16), # begin 77 int(matched.group(1), 16), # begin
70 int(matched.group(2), 16), # end 78 int(matched.group(2), 16), # end
71 matched.group(3), # readable 79 matched.group(3), # readable
72 matched.group(4), # writable 80 matched.group(4), # writable
73 matched.group(5), # executable 81 matched.group(5), # executable
74 matched.group(6), # private 82 matched.group(6), # private
75 int(matched.group(7), 16), # offset 83 int(matched.group(7), 16), # offset
76 matched.group(8), # major 84 matched.group(8), # major
77 matched.group(9), # minor 85 matched.group(9), # minor
78 int(matched.group(10), 10), # inode 86 int(matched.group(10), 10), # inode
(...skipping 13 matching lines...) Expand all
92 return (entry.executable == 'x' and re.match( 100 return (entry.executable == 'x' and re.match(
93 '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?', 101 '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
94 entry.name)) 102 entry.name))
95 103
96 @staticmethod 104 @staticmethod
97 def executable_and_constants(entry): 105 def executable_and_constants(entry):
98 return (((entry.writable == '-' and entry.executable == '-') or 106 return (((entry.writable == '-' and entry.executable == '-') or
99 entry.executable == 'x') and re.match( 107 entry.executable == 'x') and re.match(
100 '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?', 108 '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
101 entry.name)) 109 entry.name))
110
111 def _append(self, entry):
112 if self._sorted_indexes and self._sorted_indexes[-1] > entry.begin:
113 self._sorted = False
114 self._sorted_indexes.append(entry.begin)
115 self._dictionary[entry.begin] = entry
OLDNEW
« no previous file with comments | « tools/find_runtime_symbols/prepare_symbol_info.py ('k') | tools/find_runtime_symbols/static_symbols.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698