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
3 # found in the LICENSE file.
8 _MAPS_PATTERN
= re
.compile(
9 r
'^([a-f0-9]+)-([a-f0-9]+)\s+(.)(.)(.)(.)\s+([a-f0-9]+)\s+(\S+):(\S+)\s+'
10 r
'(\d+)\s*(.*)$', re
.IGNORECASE
)
13 class ProcMapsEntry(object):
14 """A class representing one line in /proc/.../maps."""
17 self
, begin
, end
, readable
, writable
, executable
, private
, offset
,
18 major
, minor
, inode
, name
):
21 self
.readable
= readable
22 self
.writable
= writable
23 self
.executable
= executable
24 self
.private
= private
35 'readable': self
.readable
,
36 'writable': self
.writable
,
37 'executable': self
.executable
,
38 'private': self
.private
,
39 'offset': self
.offset
,
47 class ProcMaps(object):
48 """A class representing contents in /proc/.../maps."""
51 self
._sorted
_indexes
= []
55 def iter(self
, condition
):
57 self
._sorted
_indexes
.sort()
59 for index
in self
._sorted
_indexes
:
60 if not condition
or condition(self
._dictionary
[index
]):
61 yield self
._dictionary
[index
]
65 self
._sorted
_indexes
.sort()
67 for index
in self
._sorted
_indexes
:
68 yield self
._dictionary
[index
]
74 table
.append_line(line
)
77 def append_line(self
, line
):
78 entry
= self
.parse_line(line
)
80 self
._append
_entry
(entry
)
84 matched
= _MAPS_PATTERN
.match(line
)
86 return ProcMapsEntry( # pylint: disable=W0212
87 int(matched
.group(1), 16), # begin
88 int(matched
.group(2), 16), # end
89 matched
.group(3), # readable
90 matched
.group(4), # writable
91 matched
.group(5), # executable
92 matched
.group(6), # private
93 int(matched
.group(7), 16), # offset
94 matched
.group(8), # major
95 matched
.group(9), # minor
96 int(matched
.group(10), 10), # inode
97 matched
.group(11) # name
103 def constants(entry
):
104 return (entry
.writable
== '-' and entry
.executable
== '-' and re
.match(
105 '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
109 def executable(entry
):
110 return (entry
.executable
== 'x' and re
.match(
111 '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
115 def executable_and_constants(entry
):
116 return (((entry
.writable
== '-' and entry
.executable
== '-') or
117 entry
.executable
== 'x') and re
.match(
118 '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
121 def _append_entry(self
, entry
):
122 if self
._sorted
_indexes
and self
._sorted
_indexes
[-1] > entry
.begin
:
124 self
._sorted
_indexes
.append(entry
.begin
)
125 self
._dictionary
[entry
.begin
] = entry