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