mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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