2
0

aio.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/python
  2. # GDB debugging support: aio/iohandler debug
  3. #
  4. # Copyright (c) 2015 Red Hat, Inc.
  5. #
  6. # Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
  7. #
  8. # This work is licensed under the terms of the GNU GPL, version 2 or
  9. # later. See the COPYING file in the top-level directory.
  10. #
  11. import gdb
  12. from qemugdb import coroutine
  13. def isnull(ptr):
  14. return ptr == gdb.Value(0).cast(ptr.type)
  15. def dump_aiocontext(context, verbose):
  16. '''Display a dump and backtrace for an aiocontext'''
  17. cur = context['aio_handlers']['lh_first']
  18. # Get pointers to functions we're going to process specially
  19. sym_fd_coroutine_enter = gdb.parse_and_eval('fd_coroutine_enter')
  20. while not isnull(cur):
  21. entry = cur.dereference()
  22. gdb.write('----\n%s\n' % entry)
  23. if verbose and cur['io_read'] == sym_fd_coroutine_enter:
  24. coptr = (cur['opaque'].cast(gdb.lookup_type('FDYieldUntilData').pointer()))['co']
  25. coptr = coptr.cast(gdb.lookup_type('CoroutineUContext').pointer())
  26. coroutine.bt_jmpbuf(coptr['env']['__jmpbuf'])
  27. cur = cur['node']['le_next'];
  28. gdb.write('----\n')
  29. class HandlersCommand(gdb.Command):
  30. '''Display aio handlers'''
  31. def __init__(self):
  32. gdb.Command.__init__(self, 'qemu handlers', gdb.COMMAND_DATA,
  33. gdb.COMPLETE_NONE)
  34. def invoke(self, arg, from_tty):
  35. verbose = False
  36. argv = gdb.string_to_argv(arg)
  37. if len(argv) > 0 and argv[0] == '--verbose':
  38. verbose = True
  39. argv.pop(0)
  40. if len(argv) > 1:
  41. gdb.write('usage: qemu handlers [--verbose] [handler]\n')
  42. return
  43. if len(argv) == 1:
  44. handlers_name = argv[0]
  45. else:
  46. handlers_name = 'qemu_aio_context'
  47. dump_aiocontext(gdb.parse_and_eval(handlers_name), verbose)