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