Skip to content

Commit

Permalink
Cleanup win32comext.axdebug
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Sep 22, 2023
1 parent 03a8bb1 commit 1f5f734
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 192 deletions.
75 changes: 10 additions & 65 deletions com/win32comext/axdebug/Test/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

import pythoncom
import win32api
import win32com.server.util
import winerror
from win32com.axdebug import adb, axdebug, codecontainer, contexts, documents, gateways
from win32com.axdebug.util import _wrap, _wrap_remove, trace
from win32com.axscript import axscript
from win32com.client.util import Enumerator
from win32com.axdebug import codecontainer, gateways
from win32com.axdebug.util import _wrap, trace
from win32com.server.exception import Exception


Expand All @@ -26,8 +23,10 @@ def ReleaseConnection(self, extconn, reserved, fLastReleaseCloses):
return self.numExtRefs


# externalConnectionManager = ExternalConnection()
# wrappedExternalConnectionManager = _wrap(externalConnectionManager, pythoncom.IID_IExternalConnection)
externalConnectionManager = ExternalConnection()
wrappedExternalConnectionManager = _wrap(
externalConnectionManager, pythoncom.IID_IExternalConnection
)


def DelegatedExternalConnectionQI(iid):
Expand Down Expand Up @@ -97,71 +96,25 @@ def GetPathName(self):
try:
return win32api.GetFullPathName(self.module.__file__), 1
except (AttributeError, win32api.error):
raise Exception(scode == E_FAIL)
raise Exception(scode=winerror.E_FAIL)

def GetFileName(self):
# Result is a string with just the name of the document, no path information.
trace("GetFileName")
return os.path.split(module.__file__)
return os.path.split(self.module.__file__)

def NotifyChanged():
trace("NotifyChanged")
raise Exception(scode=winerror.E_NOTIMPL)


def TestSmartHelper():
pdm = pythoncom.CoCreateInstance(
axdebug.CLSID_ProcessDebugManager,
None,
pythoncom.CLSCTX_ALL,
axdebug.IID_IProcessDebugManager,
)
app = pdm.CreateApplication()
app.SetName("Python Process")

pydebugger = adb.Debugger()

nodes = BuildModuleTree()

all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes)
root = app.GetRootNode()
AttachParentNodes(root, nodes, all_real_nodes)

pydebugger.AttachApp(app)
cookie = pdm.AddApplication(app)
input("Waiting...")
ttest.test()

pdm.RemoveApplication(cookie)
print("Done")


def testdumb():
pdm = pythoncom.CoCreateInstance(
axdebug.CLSID_ProcessDebugManager,
None,
pythoncom.CLSCTX_ALL,
axdebug.IID_IProcessDebugManager,
)
app = pdm.GetDefaultApplication()

nodes = BuildModuleTree()
all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes)
AttachParentNodes(None, nodes, all_real_nodes)

parentNode = None
all_real_nodes = {}
input("Waiting...")
print("Done")


def TestSmartProvider():
import ttest
from win32com.axdebug import debugger

d = debugger.AXDebugger()
# d.StartDebugger()
# d.Attach()
# d.StartDebugger()
# d.Attach()
d.Break()
input("Waiting...")
ttest.test()
Expand All @@ -171,21 +124,13 @@ def TestSmartProvider():

def test():
try:
# app = TestSmartHelper()
app = TestSmartProvider()
# app = testdumb()
except:
traceback.print_exc()


# _wrap_remove(externalConnectionManager)
# wrappedExternalConnectionManager = None

if __name__ == "__main__":
test()
import win32com.axdebug.util

win32com.axdebug.util._dump_wrapped()
print(
" %d/%d com objects still alive"
% (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())
Expand Down
39 changes: 18 additions & 21 deletions com/win32comext/axdebug/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import pythoncom
import win32api
import win32com.client.connect
from win32com.axdebug.util import _wrap, _wrap_remove, trace
from win32com.server.util import unwrap
from win32com.axdebug.util import _wrap, trace

from . import axdebug, gateways, stackframe

Expand Down Expand Up @@ -118,8 +117,8 @@ def __xxxxx__set_break(self, filename, lineno, cond=None):
def stop_here(self, frame):
traceenter("stop_here", _dumpf(frame), _dumpf(self.stopframe))
# As per bdb.stop_here, except for logicalbotframe
## if self.stopframe is None:
## return 1
# if self.stopframe is None:
# return 1
if frame is self.stopframe:
return 1

Expand Down Expand Up @@ -157,13 +156,13 @@ def dispatch_return(self, frame, arg):
tracev("dispatch_return resetting sys.trace")
sys.settrace(None)
return
# self.bSetTrace = 0
# self.bSetTrace = 0
self.currentframe = frame.f_back
return bdb.Bdb.dispatch_return(self, frame, arg)

def dispatch_line(self, frame):
traceenter("dispatch_line", _dumpf(frame), _dumpf(self.botframe))
# trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe)
# trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe)
if frame is self.logicalbotframe:
trace("dispatch_line", _dumpf(frame), "for bottom frame returing tracer")
# The next code executed in the frame above may be a builtin (eg, apply())
Expand Down Expand Up @@ -195,13 +194,13 @@ def dispatch_call(self, frame, arg):
trace(
"dispatch_call has no document for", _dumpf(frame), "- skipping trace!"
)
## sys.settrace(None)
# sys.settrace(None)
return None
return self.trace_dispatch

# rc = bdb.Bdb.dispatch_call(self, frame, arg)
# trace("dispatch_call", _dumpf(frame),"returned",rc)
# return rc
# rc = bdb.Bdb.dispatch_call(self, frame, arg)
# trace("dispatch_call", _dumpf(frame),"returned",rc)
# return rc

def trace_dispatch(self, frame, event, arg):
traceenter("trace_dispatch", _dumpf(frame), event, arg)
Expand All @@ -213,8 +212,8 @@ def trace_dispatch(self, frame, event, arg):
#
# The user functions do bugger all!
#
# def user_call(self, frame, argument_list):
# traceenter("user_call",_dumpf(frame))
# def user_call(self, frame, argument_list):
# traceenter("user_call",_dumpf(frame))

def user_line(self, frame):
traceenter("user_line", _dumpf(frame))
Expand All @@ -226,11 +225,11 @@ def user_line(self, frame):
self._HandleBreakPoint(frame, None, breakReason)

def user_return(self, frame, return_value):
# traceenter("user_return",_dumpf(frame),return_value)
# traceenter("user_return",_dumpf(frame),return_value)
bdb.Bdb.user_return(self, frame, return_value)

def user_exception(self, frame, exc_info):
# traceenter("user_exception")
# traceenter("user_exception")
bdb.Bdb.user_exception(self, frame, exc_info)

def _HandleBreakPoint(self, frame, tb, reason):
Expand Down Expand Up @@ -284,8 +283,6 @@ def CloseApp(self):
"*** Could not RemoveStackFrameSniffer %d"
% (self.stackSnifferCookie)
)
if self.stackSniffer:
_wrap_remove(self.stackSniffer)
self.stackSnifferCookie = self.stackSniffer = None

if self.appEventConnection is not None:
Expand All @@ -298,7 +295,7 @@ def CloseApp(self):
self.codeContainerProvider = None

def AttachApp(self, debugApplication, codeContainerProvider):
# traceenter("AttachApp", debugApplication, codeContainerProvider)
# traceenter("AttachApp", debugApplication, codeContainerProvider)
self.codeContainerProvider = codeContainerProvider
self.debugApplication = debugApplication
self.stackSniffer = _wrap(
Expand All @@ -307,7 +304,7 @@ def AttachApp(self, debugApplication, codeContainerProvider):
self.stackSnifferCookie = debugApplication.AddStackFrameSniffer(
self.stackSniffer
)
# trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie)
# trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie)

# Connect to the application events.
self.appEventConnection = win32com.client.connect.SimpleConnection(
Expand All @@ -321,7 +318,7 @@ def ResetAXDebugging(self):
return

if len(self.recursiveData) == 0:
# print "ResetAXDebugging called for final time."
# print("ResetAXDebugging called for final time.")
self.logicalbotframe = None
self.debuggingThread = None
self.currentframe = None
Expand Down Expand Up @@ -432,8 +429,8 @@ def _BreakFlagsChanged(self):
)
trace("_BreakFlagsChanged has breaks", self.breaks)
# If a request comes on our debugging thread, then do it now!
# if self.debuggingThread!=win32api.GetCurrentThreadId():
# return
# if self.debuggingThread!=win32api.GetCurrentThreadId():
# return

if len(self.breaks) or self.breakFlags:
if self.logicalbotframe:
Expand Down
26 changes: 12 additions & 14 deletions com/win32comext/axdebug/codecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
to color the text, and also how to translate lines into offsets, and back.
"""

import os
import sys
import tokenize

import win32api
import winerror
from win32com.axdebug import axdebug
from win32com.axdebug import axdebug, contexts
from win32com.axdebug.util import _wrap
from win32com.server.exception import Exception

from . import contexts
from .util import RaiseNotImpl, _wrap

_keywords = {} # set of Python keywords
for name in """
and assert break class continue def del elif else except exec
Expand Down Expand Up @@ -43,7 +42,7 @@ def __init__(
self.codeContexts = {}
self.site = site
self.startLineNumber = startLineNumber
self.debugDocument = None
self.debugDocument = debugDocument

def _Close(self):
self.text = self.lines = self.lineOffsets = None
Expand Down Expand Up @@ -78,9 +77,9 @@ def GetLineOfPosition(self, charPos):
lastOffset = lineOffset
lineNo = lineNo + 1
else: # for not broken.
# print "Cant find", charPos, "in", self.lineOffsets
# print "Cant find", charPos, "in", self.lineOffsets
raise Exception(scode=winerror.S_FALSE)
# print "GLOP ret=",lineNo, (charPos-lastOffset)
# print "GLOP ret=",lineNo, (charPos-lastOffset)
return lineNo, (charPos - lastOffset)

def GetNextLine(self):
Expand Down Expand Up @@ -187,13 +186,13 @@ def _MakeContextAtPosition(self, charPos):

# Returns a DebugCodeContext. debugDocument can be None for smart hosts.
def GetCodeContextAtPosition(self, charPos):
# trace("GetContextOfPos", charPos, maxChars)
# trace("GetContextOfPos", charPos, maxChars)
# Convert to line number.
lineNo, offset = self.GetLineOfPosition(charPos)
charPos = self.GetPositionOfLine(lineNo)
try:
cc = self.codeContexts[charPos]
# trace(" GetContextOfPos using existing")
# trace(" GetContextOfPos using existing")
except KeyError:
cc = self._MakeContextAtPosition(charPos)
self.codeContexts[charPos] = cc
Expand Down Expand Up @@ -253,11 +252,10 @@ def GetName(self, dnt):


if __name__ == "__main__":
sys.path.append(".")
import ttest
from Test import ttest

sc = SourceModuleContainer(ttest)
# sc = SourceCodeContainer(open(sys.argv[1], "rb").read(), sys.argv[1])
# sc = SourceCodeContainer(open(sys.argv[1], "rb").read(), sys.argv[1])
attrs = sc.GetSyntaxColorAttributes()
attrlen = 0
for attr in attrs:
Expand All @@ -269,8 +267,8 @@ def GetName(self, dnt):
if attrlen != len(text):
print("Lengths dont match!!! (%d/%d)" % (attrlen, len(text)))

# print "Attributes:"
# print attrs
# print("Attributes:")
# print(attrs)
print("GetLineOfPos=", sc.GetLineOfPosition(0))
print("GetLineOfPos=", sc.GetLineOfPosition(4))
print("GetLineOfPos=", sc.GetLineOfPosition(10))
5 changes: 1 addition & 4 deletions com/win32comext/axdebug/contexts.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
""" A module for managing the AXDebug I*Contexts
"""
import pythoncom
import win32com.server.util

from . import adb, axdebug, gateways

# Utility function for wrapping object created by this module.
from .util import _wrap, _wrap_remove, trace
from .util import _wrap


class DebugCodeContext(gateways.DebugCodeContext, gateways.DebugDocumentContext):
Expand Down
Loading

0 comments on commit 1f5f734

Please sign in to comment.