block.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 memdf.collect
  22. import memdf.name
  23. import memdf.report
  24. import memdf.select
  25. import memdf.util.config
  26. import pandas as pd # type: ignore
  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. raise exception
  61. return status
  62. if __name__ == '__main__':
  63. sys.exit(main(sys.argv))