trace2line 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. '''
  3. TODO port this to Python fully. I started it, but then it was hanging on some
  4. IO blocking annoyance in the pipeline, and I don't have the time to deal with
  5. it, so I'm just going to forward the common options to the old shell script for
  6. now...
  7. '''
  8. import os
  9. import common
  10. import lkmc.import_path
  11. from shell_helpers import LF
  12. class Main(common.LkmcCliFunction):
  13. def __init__(self):
  14. super().__init__(
  15. defaults = {
  16. 'show_time': False,
  17. },
  18. description='''\
  19. Convert an execution trace containing PC values into the Linux kernel lines executed.
  20. ''',
  21. )
  22. def timed_main(self):
  23. self.sh.run_cmd([
  24. os.path.join(self.env['root_dir'], 'trace2line.sh'), LF,
  25. 'true' if self.env['emulator'] == 'gem5' else 'false', LF,
  26. self.env['trace_txt_file'], LF,
  27. self.get_toolchain_tool('addr2line'), LF,
  28. self.env['vmlinux'], LF,
  29. self.env['run_dir'], LF,
  30. ])
  31. if __name__ == '__main__':
  32. Main().cli()
  33. # This was the old full Python port attempt that was failing:
  34. # import subprocess
  35. # import sys
  36. # if kwargs['emulator'] == 'gem5':
  37. # def get_pc(line):
  38. # # TODO
  39. # # stdin = sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file")
  40. # pass
  41. # else:
  42. # def get_pc(line):
  43. # return line.split('=')[-1]
  44. # with \
  45. # subprocess.Popen(
  46. # [
  47. # self.get_toolchain_tool('addr2line'),
  48. # '-e',
  49. # kwargs['vmlinux'],
  50. # '-f',
  51. # '-p',
  52. # ],
  53. # stdout=subprocess.PIPE,
  54. # stdin=subprocess.PIPE,
  55. # ) as proc, \
  56. # open(kwargs['trace_txt_file'], 'r') as infile, \
  57. # open(os.path.join(kwargs['run_dir'], 'trace-lines.txt'), 'w') as outfile \
  58. # :
  59. # for in_line in infile:
  60. # proc.stdin.write(get_pc(in_line).encode())
  61. # proc.stdin.flush()
  62. # stdout = proc.stdout.read()
  63. # outfile.write(stdout.decode())
  64. # # TODO
  65. # # sed -E "s|at ${kwargs['linux_build_dir']}/(\./\|)||"
  66. # # uniq -c