PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/site-packages/pythonwin/pywin/debugger/__init__.py

https://github.com/rpattabi/ironruby
Python | 113 lines | 82 code | 18 blank | 13 comment | 18 complexity | 3616de95a8de799ae6e45c75ffbf982b MD5 | raw file
  1. import sys
  2. # Some cruft to deal with the Pythonwin GUI booting up from a non GUI app.
  3. def _MakeDebuggerGUI():
  4. app.InitInstance()
  5. isInprocApp = -1
  6. def _CheckNeedGUI():
  7. global isInprocApp
  8. if isInprocApp==-1:
  9. import win32ui
  10. isInprocApp = win32ui.GetApp().IsInproc()
  11. if isInprocApp:
  12. # MAY Need it - may already have one
  13. need = "pywin.debugger.dbgpyapp" not in sys.modules
  14. else:
  15. need = 0
  16. if need:
  17. import pywin.framework.app
  18. import dbgpyapp
  19. pywin.framework.app.CreateDefaultGUI(dbgpyapp.DebuggerPythonApp)
  20. else:
  21. # Check we have the appropriate editor
  22. # No longer necessary!
  23. pass
  24. return need
  25. # Inject some methods in the top level name-space.
  26. currentDebugger = None # Wipe out any old one on reload.
  27. def _GetCurrentDebugger():
  28. global currentDebugger
  29. if currentDebugger is None:
  30. _CheckNeedGUI()
  31. import debugger
  32. currentDebugger = debugger.Debugger()
  33. return currentDebugger
  34. def GetDebugger():
  35. # An error here is not nice - as we are probably trying to
  36. # break into the debugger on a Python error, any
  37. # error raised by this is usually silent, and causes
  38. # big problems later!
  39. try:
  40. rc = _GetCurrentDebugger()
  41. rc.GUICheckInit()
  42. return rc
  43. except:
  44. print "Could not create the debugger!"
  45. import traceback
  46. traceback.print_exc()
  47. return None
  48. def close():
  49. if currentDebugger is not None:
  50. currentDebugger.close()
  51. def run(cmd,globals=None, locals=None, start_stepping = 1):
  52. _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  53. def runeval(expression, globals=None, locals=None):
  54. return _GetCurrentDebugger().runeval(expression, globals, locals)
  55. def runcall(*args):
  56. return _GetCurrentDebugger().runcall(*args)
  57. def set_trace():
  58. import sys
  59. d = _GetCurrentDebugger()
  60. if d.frameShutdown: return # App closing
  61. if d.stopframe != d.botframe:
  62. # If im not "running"
  63. return
  64. sys.settrace(None) # May be hooked
  65. d.reset()
  66. d.set_trace()
  67. # "brk" is an alias for "set_trace" ("break" is a reserved word :-(
  68. brk = set_trace
  69. # Post-Mortem interface
  70. def post_mortem(t=None):
  71. if t is None:
  72. t = sys.exc_info()[2] # Will be valid if we are called from an except handler.
  73. if t is None:
  74. try:
  75. t = sys.last_traceback
  76. except AttributeError:
  77. print "No traceback can be found from which to perform post-mortem debugging!"
  78. print "No debugging can continue"
  79. return
  80. p = _GetCurrentDebugger()
  81. if p.frameShutdown: return # App closing
  82. # No idea why I need to settrace to None - it should have been reset by now?
  83. sys.settrace(None)
  84. p.reset()
  85. while t.tb_next != None: t = t.tb_next
  86. p.bAtPostMortem = 1
  87. p.prep_run(None)
  88. try:
  89. p.interaction(t.tb_frame, t)
  90. finally:
  91. t = None
  92. p.bAtPostMortem = 0
  93. p.done_run()
  94. def pm(t=None):
  95. post_mortem(t)