BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 """
borlanic 0:fbdae7e6d805 2 mbed SDK
borlanic 0:fbdae7e6d805 3 Copyright (c) 2011-2013 ARM Limited
borlanic 0:fbdae7e6d805 4
borlanic 0:fbdae7e6d805 5 Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:fbdae7e6d805 6 you may not use this file except in compliance with the License.
borlanic 0:fbdae7e6d805 7 You may obtain a copy of the License at
borlanic 0:fbdae7e6d805 8
borlanic 0:fbdae7e6d805 9 http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:fbdae7e6d805 10
borlanic 0:fbdae7e6d805 11 Unless required by applicable law or agreed to in writing, software
borlanic 0:fbdae7e6d805 12 distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:fbdae7e6d805 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:fbdae7e6d805 14 See the License for the specific language governing permissions and
borlanic 0:fbdae7e6d805 15 limitations under the License.
borlanic 0:fbdae7e6d805 16
borlanic 0:fbdae7e6d805 17
borlanic 0:fbdae7e6d805 18 Utility to find which libraries could define a given symbol
borlanic 0:fbdae7e6d805 19 """
borlanic 0:fbdae7e6d805 20 from argparse import ArgumentParser
borlanic 0:fbdae7e6d805 21 from os.path import join, splitext
borlanic 0:fbdae7e6d805 22 from os import walk
borlanic 0:fbdae7e6d805 23 from subprocess import Popen, PIPE
borlanic 0:fbdae7e6d805 24
borlanic 0:fbdae7e6d805 25
borlanic 0:fbdae7e6d805 26 OBJ_EXT = ['.o', '.a', '.ar']
borlanic 0:fbdae7e6d805 27
borlanic 0:fbdae7e6d805 28
borlanic 0:fbdae7e6d805 29 def find_sym_in_lib(sym, obj_path):
borlanic 0:fbdae7e6d805 30 contain_symbol = False
borlanic 0:fbdae7e6d805 31
borlanic 0:fbdae7e6d805 32 out = Popen(["nm", "-C", obj_path], stdout=PIPE, stderr=PIPE).communicate()[0]
borlanic 0:fbdae7e6d805 33 for line in out.splitlines():
borlanic 0:fbdae7e6d805 34 tokens = line.split()
borlanic 0:fbdae7e6d805 35 n = len(tokens)
borlanic 0:fbdae7e6d805 36 if n == 2:
borlanic 0:fbdae7e6d805 37 sym_type = tokens[0]
borlanic 0:fbdae7e6d805 38 sym_name = tokens[1]
borlanic 0:fbdae7e6d805 39 elif n == 3:
borlanic 0:fbdae7e6d805 40 sym_type = tokens[1]
borlanic 0:fbdae7e6d805 41 sym_name = tokens[2]
borlanic 0:fbdae7e6d805 42 else:
borlanic 0:fbdae7e6d805 43 continue
borlanic 0:fbdae7e6d805 44
borlanic 0:fbdae7e6d805 45 if sym_type == "U":
borlanic 0:fbdae7e6d805 46 # This object is using this symbol, not defining it
borlanic 0:fbdae7e6d805 47 continue
borlanic 0:fbdae7e6d805 48
borlanic 0:fbdae7e6d805 49 if sym_name == sym:
borlanic 0:fbdae7e6d805 50 contain_symbol = True
borlanic 0:fbdae7e6d805 51
borlanic 0:fbdae7e6d805 52 return contain_symbol
borlanic 0:fbdae7e6d805 53
borlanic 0:fbdae7e6d805 54
borlanic 0:fbdae7e6d805 55 def find_sym_in_path(sym, dir_path):
borlanic 0:fbdae7e6d805 56 for root, _, files in walk(dir_path):
borlanic 0:fbdae7e6d805 57 for file in files:
borlanic 0:fbdae7e6d805 58
borlanic 0:fbdae7e6d805 59 _, ext = splitext(file)
borlanic 0:fbdae7e6d805 60 if ext not in OBJ_EXT: continue
borlanic 0:fbdae7e6d805 61
borlanic 0:fbdae7e6d805 62 path = join(root, file)
borlanic 0:fbdae7e6d805 63 if find_sym_in_lib(sym, path):
borlanic 0:fbdae7e6d805 64 print path
borlanic 0:fbdae7e6d805 65
borlanic 0:fbdae7e6d805 66
borlanic 0:fbdae7e6d805 67 if __name__ == '__main__':
borlanic 0:fbdae7e6d805 68 parser = ArgumentParser(description='Find Symbol')
borlanic 0:fbdae7e6d805 69 parser.add_argument('-s', '--sym', required=True,
borlanic 0:fbdae7e6d805 70 help='The symbol to be searched')
borlanic 0:fbdae7e6d805 71 parser.add_argument('-p', '--path', required=True,
borlanic 0:fbdae7e6d805 72 help='The path where to search')
borlanic 0:fbdae7e6d805 73 args = parser.parse_args()
borlanic 0:fbdae7e6d805 74
borlanic 0:fbdae7e6d805 75 find_sym_in_path(args.sym, args.path)