Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stackframe.py 6.0KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. """Support for stack-frames.
  2. Provides Implements a nearly complete wrapper for a stack frame.
  3. """
  4. import pythoncom
  5. from win32com.server.exception import COMException
  6. from . import axdebug, expressions, gateways
  7. from .util import RaiseNotImpl, _wrap, trace
  8. # def trace(*args):
  9. # pass
  10. class EnumDebugStackFrames(gateways.EnumDebugStackFrames):
  11. """A class that given a debugger object, can return an enumerator
  12. of DebugStackFrame objects.
  13. """
  14. def __init__(self, debugger):
  15. infos = []
  16. frame = debugger.currentframe
  17. # print "Stack check"
  18. while frame:
  19. # print " Checking frame", frame.f_code.co_filename, frame.f_lineno-1, frame.f_trace,
  20. # Get a DebugCodeContext for the stack frame. If we fail, then it
  21. # is not debuggable, and therefore not worth displaying.
  22. cc = debugger.codeContainerProvider.FromFileName(frame.f_code.co_filename)
  23. if cc is not None:
  24. try:
  25. address = frame.f_locals["__axstack_address__"]
  26. except KeyError:
  27. # print "Couldnt find stack address for",frame.f_code.co_filename, frame.f_lineno-1
  28. # Use this one, even tho it is wrong :-(
  29. address = axdebug.GetStackAddress()
  30. frameInfo = (
  31. DebugStackFrame(frame, frame.f_lineno - 1, cc),
  32. address,
  33. address + 1,
  34. 0,
  35. None,
  36. )
  37. infos.append(frameInfo)
  38. # print "- Kept!"
  39. # else:
  40. # print "- rejected"
  41. frame = frame.f_back
  42. gateways.EnumDebugStackFrames.__init__(self, infos, 0)
  43. # def __del__(self):
  44. # print "EnumDebugStackFrames dieing"
  45. def Next(self, count):
  46. return gateways.EnumDebugStackFrames.Next(self, count)
  47. # def _query_interface_(self, iid):
  48. # from win32com.util import IIDToInterfaceName
  49. # print "EnumDebugStackFrames QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid))
  50. # return 0
  51. def _wrap(self, obj):
  52. # This enum returns a tuple, with 2 com objects in it.
  53. obFrame, min, lim, fFinal, obFinal = obj
  54. obFrame = _wrap(obFrame, axdebug.IID_IDebugStackFrame)
  55. if obFinal:
  56. obFinal = _wrap(obFinal, pythoncom.IID_IUnknown)
  57. return obFrame, min, lim, fFinal, obFinal
  58. class DebugStackFrame(gateways.DebugStackFrame):
  59. def __init__(self, frame, lineno, codeContainer):
  60. self.frame = frame
  61. self.lineno = lineno
  62. self.codeContainer = codeContainer
  63. self.expressionContext = None
  64. # def __del__(self):
  65. # print "DSF dieing"
  66. def _query_interface_(self, iid):
  67. if iid == axdebug.IID_IDebugExpressionContext:
  68. if self.expressionContext is None:
  69. self.expressionContext = _wrap(
  70. expressions.ExpressionContext(self.frame),
  71. axdebug.IID_IDebugExpressionContext,
  72. )
  73. return self.expressionContext
  74. # from win32com.util import IIDToInterfaceName
  75. # print "DebugStackFrame QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid))
  76. return 0
  77. #
  78. # The following need implementation
  79. def GetThread(self):
  80. """Returns the thread associated with this stack frame.
  81. Result must be a IDebugApplicationThread
  82. """
  83. RaiseNotImpl("GetThread")
  84. def GetCodeContext(self):
  85. offset = self.codeContainer.GetPositionOfLine(self.lineno)
  86. return self.codeContainer.GetCodeContextAtPosition(offset)
  87. #
  88. # The following are usefully implemented
  89. def GetDescriptionString(self, fLong):
  90. filename = self.frame.f_code.co_filename
  91. s = ""
  92. if 0: # fLong:
  93. s = s + filename
  94. if self.frame.f_code.co_name:
  95. s = s + self.frame.f_code.co_name
  96. else:
  97. s = s + "<lambda>"
  98. return s
  99. def GetLanguageString(self, fLong):
  100. if fLong:
  101. return "Python ActiveX Scripting Engine"
  102. else:
  103. return "Python"
  104. def GetDebugProperty(self):
  105. return _wrap(StackFrameDebugProperty(self.frame), axdebug.IID_IDebugProperty)
  106. class DebugStackFrameSniffer:
  107. _public_methods_ = ["EnumStackFrames"]
  108. _com_interfaces_ = [axdebug.IID_IDebugStackFrameSniffer]
  109. def __init__(self, debugger):
  110. self.debugger = debugger
  111. trace("DebugStackFrameSniffer instantiated")
  112. # def __del__(self):
  113. # print "DSFS dieing"
  114. def EnumStackFrames(self):
  115. trace("DebugStackFrameSniffer.EnumStackFrames called")
  116. return _wrap(
  117. EnumDebugStackFrames(self.debugger), axdebug.IID_IEnumDebugStackFrames
  118. )
  119. # A DebugProperty for a stack frame.
  120. class StackFrameDebugProperty:
  121. _com_interfaces_ = [axdebug.IID_IDebugProperty]
  122. _public_methods_ = [
  123. "GetPropertyInfo",
  124. "GetExtendedInfo",
  125. "SetValueAsString",
  126. "EnumMembers",
  127. "GetParent",
  128. ]
  129. def __init__(self, frame):
  130. self.frame = frame
  131. def GetPropertyInfo(self, dwFieldSpec, nRadix):
  132. RaiseNotImpl("StackFrameDebugProperty::GetPropertyInfo")
  133. def GetExtendedInfo(self): ### Note - not in the framework.
  134. RaiseNotImpl("StackFrameDebugProperty::GetExtendedInfo")
  135. def SetValueAsString(self, value, radix):
  136. #
  137. RaiseNotImpl("DebugProperty::SetValueAsString")
  138. def EnumMembers(self, dwFieldSpec, nRadix, iid):
  139. print("EnumMembers", dwFieldSpec, nRadix, iid)
  140. from . import expressions
  141. return expressions.MakeEnumDebugProperty(
  142. self.frame.f_locals, dwFieldSpec, nRadix, iid, self.frame
  143. )
  144. def GetParent(self):
  145. # return IDebugProperty
  146. RaiseNotImpl("DebugProperty::GetParent")