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