summaryrefslogtreecommitdiffstats
path: root/tools/find_runtime_symbols
diff options
context:
space:
mode:
authordmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-29 10:48:17 +0000
committerdmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-29 10:48:17 +0000
commit07fe446a65df9335e8e6acdf612b00b2ea6c6c03 (patch)
tree3ebf72f2c6ab2ec7135e1af7c3d6a7f5c461e52c /tools/find_runtime_symbols
parent9c3b79ce6719d173e7bbba60caa7c796e24c16f9 (diff)
downloadchromium_src-07fe446a65df9335e8e6acdf612b00b2ea6c6c03.zip
chromium_src-07fe446a65df9335e8e6acdf612b00b2ea6c6c03.tar.gz
chromium_src-07fe446a65df9335e8e6acdf612b00b2ea6c6c03.tar.bz2
Add a Python library to read /proc on Linux.
It also moves tools/find_runtime_tools/proc_maps.py into tools/linux/procfs.py. BUG=324194 TEST=tools/linux/tests/procfs_tests.py NOTRY=True Review URL: https://codereview.chromium.org/96443002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/find_runtime_symbols')
-rwxr-xr-xtools/find_runtime_symbols/find_runtime_symbols.py17
-rwxr-xr-xtools/find_runtime_symbols/prepare_symbol_info.py11
-rw-r--r--tools/find_runtime_symbols/proc_maps.py125
-rwxr-xr-xtools/find_runtime_symbols/tests/proc_maps_test.py110
4 files changed, 20 insertions, 243 deletions
diff --git a/tools/find_runtime_symbols/find_runtime_symbols.py b/tools/find_runtime_symbols/find_runtime_symbols.py
index bed9e80..e96db4f 100755
--- a/tools/find_runtime_symbols/find_runtime_symbols.py
+++ b/tools/find_runtime_symbols/find_runtime_symbols.py
@@ -14,14 +14,21 @@ import os
import sys
from static_symbols import StaticSymbolsInFile
-from proc_maps import ProcMaps
+
+
+_BASE_PATH = os.path.dirname(os.path.abspath(__file__))
+_TOOLS_LINUX_PATH = os.path.join(_BASE_PATH, os.pardir, 'linux')
+sys.path.insert(0, _TOOLS_LINUX_PATH)
+
+
+from procfs import ProcMaps # pylint: disable=F0401
try:
from collections import OrderedDict # pylint: disable=E0611
except ImportError:
- BASE_PATH = os.path.dirname(os.path.abspath(__file__))
- SIMPLEJSON_PATH = os.path.join(BASE_PATH, os.pardir, os.pardir, 'third_party')
- sys.path.insert(0, SIMPLEJSON_PATH)
+ _SIMPLEJSON_PATH = os.path.join(_BASE_PATH, os.pardir, os.pardir,
+ 'third_party')
+ sys.path.insert(0, _SIMPLEJSON_PATH)
from simplejson import OrderedDict
@@ -76,7 +83,7 @@ class RuntimeSymbolsInProcess(object):
symbols_in_process = RuntimeSymbolsInProcess()
with open(os.path.join(prepared_data_dir, _MAPS_FILENAME), mode='r') as f:
- symbols_in_process._maps = ProcMaps.load(f)
+ symbols_in_process._maps = ProcMaps.load_file(f)
with open(os.path.join(prepared_data_dir, _FILES_FILENAME), mode='r') as f:
files = json.load(f)
diff --git a/tools/find_runtime_symbols/prepare_symbol_info.py b/tools/find_runtime_symbols/prepare_symbol_info.py
index d550388..9bce545 100755
--- a/tools/find_runtime_symbols/prepare_symbol_info.py
+++ b/tools/find_runtime_symbols/prepare_symbol_info.py
@@ -13,11 +13,16 @@ import subprocess
import sys
import tempfile
-from proc_maps import ProcMaps
-
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
REDUCE_DEBUGLINE_PATH = os.path.join(BASE_PATH, 'reduce_debugline.py')
+_TOOLS_LINUX_PATH = os.path.join(BASE_PATH, os.pardir, 'linux')
+sys.path.insert(0, _TOOLS_LINUX_PATH)
+
+
+from procfs import ProcMaps # pylint: disable=F0401
+
+
LOGGER = logging.getLogger('prepare_symbol_info')
@@ -138,7 +143,7 @@ def prepare_symbol_info(maps_path,
shutil.copyfile(maps_path, os.path.join(output_dir_path, 'maps'))
with open(maps_path, mode='r') as f:
- maps = ProcMaps.load(f)
+ maps = ProcMaps.load_file(f)
LOGGER.debug('Listing up symbols.')
files = {}
diff --git a/tools/find_runtime_symbols/proc_maps.py b/tools/find_runtime_symbols/proc_maps.py
deleted file mode 100644
index 2d917b3..0000000
--- a/tools/find_runtime_symbols/proc_maps.py
+++ /dev/null
@@ -1,125 +0,0 @@
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import re
-
-
-_MAPS_PATTERN = re.compile(
- r'^([a-f0-9]+)-([a-f0-9]+)\s+(.)(.)(.)(.)\s+([a-f0-9]+)\s+(\S+):(\S+)\s+'
- r'(\d+)\s*(.*)$', re.IGNORECASE)
-
-
-class ProcMapsEntry(object):
- """A class representing one line in /proc/.../maps."""
-
- 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
-
- def as_dict(self):
- return {
- 'begin': self.begin,
- 'end': self.end,
- 'readable': self.readable,
- 'writable': self.writable,
- 'executable': self.executable,
- 'private': self.private,
- 'offset': self.offset,
- 'major': self.major,
- 'minor': self.minor,
- 'inode': self.inode,
- 'name': self.name,
- }
-
-
-class ProcMaps(object):
- """A class representing contents in /proc/.../maps."""
-
- def __init__(self):
- self._sorted_indexes = []
- self._dictionary = {}
- self._sorted = True
-
- 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]
-
- @staticmethod
- def load(f):
- table = ProcMaps()
- for line in f:
- table.append_line(line)
- return table
-
- def append_line(self, line):
- entry = self.parse_line(line)
- if entry:
- self._append_entry(entry)
-
- @staticmethod
- def parse_line(line):
- matched = _MAPS_PATTERN.match(line)
- if matched:
- return ProcMapsEntry( # pylint: disable=W0212
- 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
- )
- else:
- return None
-
- @staticmethod
- def constants(entry):
- return (entry.writable == '-' and entry.executable == '-' and re.match(
- '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
- entry.name))
-
- @staticmethod
- def executable(entry):
- return (entry.executable == 'x' and re.match(
- '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
- entry.name))
-
- @staticmethod
- def executable_and_constants(entry):
- return (((entry.writable == '-' and entry.executable == '-') or
- entry.executable == 'x') and re.match(
- '\S+(\.(so|dll|dylib|bundle)|chrome)((\.\d+)+\w*(\.\d+){0,3})?',
- entry.name))
-
- def _append_entry(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
diff --git a/tools/find_runtime_symbols/tests/proc_maps_test.py b/tools/find_runtime_symbols/tests/proc_maps_test.py
deleted file mode 100755
index 502f252..0000000
--- a/tools/find_runtime_symbols/tests/proc_maps_test.py
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/usr/bin/env python
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import cStringIO
-import logging
-import os
-import sys
-import unittest
-
-ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-sys.path.insert(0, ROOT_DIR)
-
-from proc_maps import ProcMaps
-
-
-class ProcMapsTest(unittest.TestCase):
- _TEST_PROCMAPS = '\n'.join([
- '00000000-00001000 r--p 00000000 fc:00 0',
- '0080b000-0080c000 r-xp 0020b000 fc:00 2231329'
- ' /usr/bin/some',
- '0080c000-0080f000 ---p 0020c000 fc:00 2231329'
- ' /usr/bin/some',
- '0100a000-0100c000 r-xp 0120a000 fc:00 22381'
- ' /usr/bin/chrome',
- '0100c000-0100f000 ---p 0120c000 fc:00 22381'
- ' /usr/bin/chrome',
- '0237d000-02a9b000 rw-p 00000000 00:00 0'
- ' [heap]',
- '7fb920e6d000-7fb920e85000 r-xp 00000000 fc:00 263482'
- ' /lib/x86_64-linux-gnu/libpthread-2.15.so',
- '7fb920e85000-7fb921084000 ---p 00018000 fc:00 263482'
- ' /lib/x86_64-linux-gnu/libpthread-2.15.so',
- '7fb9225f4000-7fb922654000 rw-s 00000000 00:04 19660808'
- ' /SYSV00000000 (deleted)',
- 'ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0'
- ' [vsyscall]',
- ])
-
- _EXPECTED = [
- (0x0, 0x1000, 'r', '-', '-', 'p', 0x0, 'fc', '00', 0, ''),
- (0x80b000, 0x80c000, 'r', '-', 'x', 'p', 0x20b000,
- 'fc', '00', 2231329, '/usr/bin/some'),
- (0x80c000, 0x80f000, '-', '-', '-', 'p', 0x20c000,
- 'fc', '00', 2231329, '/usr/bin/some'),
- (0x100a000, 0x100c000, 'r', '-', 'x', 'p', 0x120a000,
- 'fc', '00', 22381, '/usr/bin/chrome'),
- (0x100c000, 0x100f000, '-', '-', '-', 'p', 0x120c000,
- 'fc', '00', 22381, '/usr/bin/chrome'),
- (0x237d000, 0x2a9b000, 'r', 'w', '-', 'p', 0x0,
- '00', '00', 0, '[heap]'),
- (0x7fb920e6d000, 0x7fb920e85000, 'r', '-', 'x', 'p', 0x0,
- 'fc', '00', 263482, '/lib/x86_64-linux-gnu/libpthread-2.15.so'),
- (0x7fb920e85000, 0x7fb921084000, '-', '-', '-', 'p', 0x18000,
- 'fc', '00', 263482, '/lib/x86_64-linux-gnu/libpthread-2.15.so'),
- (0x7fb9225f4000, 0x7fb922654000, 'r', 'w', '-', 's', 0x0,
- '00', '04', 19660808, '/SYSV00000000 (deleted)'),
- (0xffffffffff600000, 0xffffffffff601000, 'r', '-', 'x', 'p', 0x0,
- '00', '00', 0, '[vsyscall]'),
- ]
-
- @staticmethod
- def _expected_as_dict(index):
- return {
- 'begin': ProcMapsTest._EXPECTED[index][0],
- 'end': ProcMapsTest._EXPECTED[index][1],
- 'readable': ProcMapsTest._EXPECTED[index][2],
- 'writable': ProcMapsTest._EXPECTED[index][3],
- 'executable': ProcMapsTest._EXPECTED[index][4],
- 'private': ProcMapsTest._EXPECTED[index][5],
- 'offset': ProcMapsTest._EXPECTED[index][6],
- 'major': ProcMapsTest._EXPECTED[index][7],
- 'minor': ProcMapsTest._EXPECTED[index][8],
- 'inode': ProcMapsTest._EXPECTED[index][9],
- 'name': ProcMapsTest._EXPECTED[index][10],
- }
-
- def test_load(self):
- maps = ProcMaps.load(cStringIO.StringIO(self._TEST_PROCMAPS))
- for index, entry in enumerate(maps):
- self.assertEqual(entry.as_dict(), self._expected_as_dict(index))
-
- def test_constants(self):
- maps = ProcMaps.load(cStringIO.StringIO(self._TEST_PROCMAPS))
- selected = [4, 7]
- for index, entry in enumerate(maps.iter(ProcMaps.constants)):
- self.assertEqual(entry.as_dict(),
- self._expected_as_dict(selected[index]))
-
- def test_executable(self):
- maps = ProcMaps.load(cStringIO.StringIO(self._TEST_PROCMAPS))
- selected = [3, 6]
- for index, entry in enumerate(maps.iter(ProcMaps.executable)):
- self.assertEqual(entry.as_dict(),
- self._expected_as_dict(selected[index]))
-
- def test_executable_and_constants(self):
- maps = ProcMaps.load(cStringIO.StringIO(self._TEST_PROCMAPS))
- selected = [3, 4, 6, 7]
- for index, entry in enumerate(maps.iter(ProcMaps.executable_and_constants)):
- self.assertEqual(entry.as_dict(),
- self._expected_as_dict(selected[index]))
-
-
-if __name__ == '__main__':
- logging.basicConfig(
- level=logging.DEBUG if '-v' in sys.argv else logging.ERROR,
- format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s')
- unittest.main()