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

Side by Side Diff: tools/find_runtime_symbols/find_runtime_symbols.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, 1 month 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import re
10 import sys 9 import sys
11 10
12 from static_symbols import StaticSymbolsInFile 11 from static_symbols import StaticSymbolsInFile
13 from proc_maps import ProcMaps 12 from proc_maps import ProcMaps
14 13
15 14
16 _MAPS_FILENAME = 'maps' 15 _MAPS_FILENAME = 'maps'
17 _FILES_FILENAME = 'files.json' 16 _FILES_FILENAME = 'files.json'
18 17
19 18
20 class _ListOutput(object): 19 class _ListOutput(object):
21 def __init__(self, result): 20 def __init__(self, result):
22 self.result = result 21 self.result = result
23 22
24 def output(self, address, symbol): 23 def output(self, address, symbol): # pylint: disable=W0613
25 self.result.append(symbol) 24 self.result.append(symbol)
26 25
27 26
28 class _DictOutput(object): 27 class _DictOutput(object):
29 def __init__(self, result): 28 def __init__(self, result):
30 self.result = result 29 self.result = result
31 30
32 def output(self, address, symbol): 31 def output(self, address, symbol):
33 self.result[address] = symbol 32 self.result[address] = symbol
34 33
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 73
75 @staticmethod 74 @staticmethod
76 def load(prepared_data_dir): 75 def load(prepared_data_dir):
77 symbols_in_process = RuntimeSymbolsInProcess() 76 symbols_in_process = RuntimeSymbolsInProcess()
78 77
79 with open(os.path.join(prepared_data_dir, _MAPS_FILENAME), mode='r') as f: 78 with open(os.path.join(prepared_data_dir, _MAPS_FILENAME), mode='r') as f:
80 symbols_in_process._maps = ProcMaps.load(f) 79 symbols_in_process._maps = ProcMaps.load(f)
81 with open(os.path.join(prepared_data_dir, _FILES_FILENAME), mode='r') as f: 80 with open(os.path.join(prepared_data_dir, _FILES_FILENAME), mode='r') as f:
82 files = json.load(f) 81 files = json.load(f)
83 82
83 # pylint: disable=W0212
84 for vma in symbols_in_process._maps.iter(ProcMaps.executable_and_constants): 84 for vma in symbols_in_process._maps.iter(ProcMaps.executable_and_constants):
85 file_entry = files.get(vma.name) 85 file_entry = files.get(vma.name)
86 if not file_entry: 86 if not file_entry:
87 continue 87 continue
88 88
89 static_symbols = StaticSymbolsInFile(vma.name) 89 static_symbols = StaticSymbolsInFile(vma.name)
90 90
91 nm_entry = file_entry.get('nm') 91 nm_entry = file_entry.get('nm')
92 if nm_entry and nm_entry['format'] == 'bsd': 92 if nm_entry and nm_entry['format'] == 'bsd':
93 with open(os.path.join(prepared_data_dir, nm_entry['file']), 'r') as f: 93 with open(os.path.join(prepared_data_dir, nm_entry['file']), 'r') as f:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 found = symbols_in_process.find_typeinfo(address) 125 found = symbols_in_process.find_typeinfo(address)
126 if found: 126 if found:
127 if found.startswith('typeinfo for '): 127 if found.startswith('typeinfo for '):
128 outputter.output(address, found[13:]) 128 outputter.output(address, found[13:])
129 else: 129 else:
130 outputter.output(address, found) 130 outputter.output(address, found)
131 else: 131 else:
132 outputter.output(address, '0x%016x' % address) 132 outputter.output(address, '0x%016x' % address)
133 133
134 134
135 def find_runtime_typeinfo_symbols_list(static_symbols, addresses): 135 def find_runtime_typeinfo_symbols_list(symbols_in_process, addresses):
136 result = [] 136 result = []
137 _find_runtime_typeinfo_symbols(static_symbols, addresses, _ListOutput(result)) 137 _find_runtime_typeinfo_symbols(
138 symbols_in_process, addresses, _ListOutput(result))
138 return result 139 return result
139 140
140 141
141 def find_runtime_typeinfo_symbols_dict(static_symbols, addresses): 142 def find_runtime_typeinfo_symbols_dict(symbols_in_process, addresses):
142 result = {} 143 result = {}
143 _find_runtime_typeinfo_symbols(static_symbols, addresses, _DictOutput(result)) 144 _find_runtime_typeinfo_symbols(
145 symbols_in_process, addresses, _DictOutput(result))
144 return result 146 return result
145 147
146 148
147 def find_runtime_typeinfo_symbols_file(static_symbols, addresses, f): 149 def find_runtime_typeinfo_symbols_file(symbols_in_process, addresses, f):
148 _find_runtime_typeinfo_symbols( 150 _find_runtime_typeinfo_symbols(
149 static_symbols, addresses, _FileOutput(f, False)) 151 symbols_in_process, addresses, _FileOutput(f, False))
150 152
151 153
152 def find_runtime_symbols_list(static_symbols, addresses): 154 def find_runtime_symbols_list(symbols_in_process, addresses):
153 result = [] 155 result = []
154 _find_runtime_symbols(static_symbols, addresses, _ListOutput(result)) 156 _find_runtime_symbols(symbols_in_process, addresses, _ListOutput(result))
155 return result 157 return result
156 158
157 159
158 def find_runtime_symbols_dict(static_symbols, addresses): 160 def find_runtime_symbols_dict(symbols_in_process, addresses):
159 result = {} 161 result = {}
160 _find_runtime_symbols(static_symbols, addresses, _DictOutput(result)) 162 _find_runtime_symbols(symbols_in_process, addresses, _DictOutput(result))
161 return result 163 return result
162 164
163 165
164 def find_runtime_symbols_file(static_symbols, addresses, f): 166 def find_runtime_symbols_file(symbols_in_process, addresses, f):
165 _find_runtime_symbols( 167 _find_runtime_symbols(
166 static_symbols, addresses, _FileOutput(f, False)) 168 symbols_in_process, addresses, _FileOutput(f, False))
167 169
168 170
169 def main(): 171 def main():
170 # FIX: Accept only .pre data 172 # FIX: Accept only .pre data
171 if len(sys.argv) < 2: 173 if len(sys.argv) < 2:
172 sys.stderr.write("""Usage: 174 sys.stderr.write("""Usage:
173 %s /path/to/prepared_data_dir/ < addresses.txt 175 %s /path/to/prepared_data_dir/ < addresses.txt
174 """ % sys.argv[0]) 176 """ % sys.argv[0])
175 return 1 177 return 1
176 178
177 log = logging.getLogger('find_runtime_symbols') 179 log = logging.getLogger('find_runtime_symbols')
178 log.setLevel(logging.WARN) 180 log.setLevel(logging.WARN)
179 handler = logging.StreamHandler() 181 handler = logging.StreamHandler()
180 handler.setLevel(logging.WARN) 182 handler.setLevel(logging.WARN)
181 formatter = logging.Formatter('%(message)s') 183 formatter = logging.Formatter('%(message)s')
182 handler.setFormatter(formatter) 184 handler.setFormatter(formatter)
183 log.addHandler(handler) 185 log.addHandler(handler)
184 186
185 prepared_data_dir = sys.argv[1] 187 prepared_data_dir = sys.argv[1]
186 if not os.path.exists(prepared_data_dir): 188 if not os.path.exists(prepared_data_dir):
187 log.warn("Nothing found: %s" % prepared_data_dir) 189 log.warn("Nothing found: %s" % prepared_data_dir)
188 return 1 190 return 1
189 if not os.path.isdir(prepared_data_dir): 191 if not os.path.isdir(prepared_data_dir):
190 log.warn("Not a directory: %s" % prepared_data_dir) 192 log.warn("Not a directory: %s" % prepared_data_dir)
191 return 1 193 return 1
192 194
193 symbols_in_process = RuntimeSymbolsInProcess.load(prepared_data_dir) 195 symbols_in_process = RuntimeSymbolsInProcess.load(prepared_data_dir)
194 return find_runtime_symbols_file(static_symbols, sys.stdin, sys.stdout) 196 return find_runtime_symbols_file(symbols_in_process, sys.stdin, sys.stdout)
195 197
196 198
197 if __name__ == '__main__': 199 if __name__ == '__main__':
198 sys.exit(main()) 200 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698