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