block.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) 2021 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. """Compare symbols against a block list."""
  18. import logging
  19. import sys
  20. from typing import Optional, Pattern
  21. import pandas as pd # type: ignore
  22. import memdf.collect
  23. import memdf.name
  24. import memdf.report
  25. import memdf.select
  26. import memdf.util.config
  27. from memdf import Config, ConfigDescription
  28. BLOCKLIST_CONFIG: ConfigDescription = {
  29. 'symbol.block': {
  30. 'help': 'Block symbol',
  31. 'metavar': 'REGEX',
  32. 'default': []
  33. }
  34. }
  35. def main(argv):
  36. status = 0
  37. try:
  38. config = Config().init({
  39. **memdf.util.config.CONFIG,
  40. **memdf.collect.PREFIX_CONFIG,
  41. **memdf.collector.readelf.NM_CONFIG,
  42. **memdf.report.REPORT_CONFIG,
  43. **memdf.report.OUTPUT_CONFIG,
  44. **BLOCKLIST_CONFIG,
  45. })
  46. config.argparse.add_argument('inputs', metavar='FILE', nargs='+')
  47. config = config.parse(argv)
  48. block_re: Optional[Pattern] = config.get_re('symbol.block')
  49. if block_re is None:
  50. logging.warning('No block list')
  51. else:
  52. frames = []
  53. for filename in config.get('args.inputs', []):
  54. ssdf = memdf.collector.readelf.read_sources(config, filename)
  55. frames.append(ssdf[ssdf.kind == 'U'])
  56. ssdf = pd.concat(frames)
  57. ssdf = ssdf[ssdf.symbol.str.fullmatch(block_re)]
  58. memdf.report.write_dfs(config, {'Symbols': ssdf})
  59. except Exception as exception:
  60. status = 1
  61. raise exception
  62. return status
  63. if __name__ == '__main__':
  64. sys.exit(main(sys.argv))