run-gdb-user 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python3
  2. import os
  3. import common
  4. import lkmc.import_path
  5. class Main(common.LkmcCliFunction):
  6. def __init__(self):
  7. super().__init__(
  8. description='''GDB step debug guest userland processes without gdbserver.
  9. More information at: https://github.com/cirosantilli/linux-kernel-module-cheat#gdb-step-debug-userland-processes
  10. '''
  11. )
  12. self.add_argument(
  13. 'executable',
  14. help='Path to the executable to be debugged relative to the Buildroot build directory.'
  15. )
  16. self.add_argument(
  17. 'break_at',
  18. default=None,
  19. help='Break at this point, e.g. main.',
  20. nargs='?'
  21. )
  22. def timed_main(self):
  23. raise Exception("This is known to be broken, but fixing shouldn't be too hard! Keyword: get_argparse. See also: https://github.com/cirosantilli/linux-kernel-module-cheat/issues/63")
  24. executable = self.env['image']
  25. addr = self.get_elf_entry(os.path.join(self.env['buildroot_build_build_dir'], executable))
  26. args = {}
  27. args['before'] = '-ex \"add-symbol-file {} {}\"'.format(executable, hex(addr))
  28. # Or else lx-symbols throws for arm:
  29. # gdb.MemoryError: Cannot access memory at address 0xbf0040cc
  30. # TODO understand better.
  31. # Also, lx-symbols overrides the add-symbol-file commands.
  32. args['no_lxsymbols'] = True
  33. args['break_at'] = self.env['break_at']
  34. rungdb = lkmc.import_path.import_path_main('run-gdb')
  35. return rungdb(**args)
  36. if __name__ == '__main__':
  37. Main().cli()