Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

syms.py 2.1KB

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