Python Active Scripting Debug — fix submitt ed (PR #2723)
Wuping Xin via python-win32 <[email protected]> Sun, 22 Mar 2026 20:19:38 +0000
| Newsgroups | gmane.comp.python.windows |
|---|---|
| Message-ID | <[email protected]> |
--===============0344088001724198128==
Content-Type: multipart/alternative;
boundary="------=_MBFD10089E-CCEA-499C-BACA-DE90934C6DCB"
--------=_MBFD10089E-CCEA-499C-BACA-DE90934C6DCB
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Hi Mark, All,
Following up on my earlier thread about axdebug being disabled on Python=20
3.11+ ("Debugging extensions (axdebug) module does not exist").
I've tracked down the root cause and submitted a fix: =20
https://github.com/mhammond/pywin32/pull/2723
The error message comes from framework.py line 763 =E2=80=94 when SetScript=
Site=20
creates the DebugManager, it tries to import axdebug. If axdebug.pyd=20
doesn't exist (because the build was skipped on 3.11+), the ImportError=20
is caught and debugging is silently disabled.
Root cause:
Python 3.11 (PEP 523) made PyFrameObject an opaque type :
- C extensions can no longer access struct fields like=20
frame->f_code, frame->f_back, or frame->f_trace directly.
- AXDebug.cpp's SetThreadStateTrace() relied on direct struct=20
access to walk the frame chain and set trace functions, so it failed to=20
compile on 3.11+.
- PyWin32: The module was disabled in setup.py as a workaround.
The fix replaces direct struct access with the official getter APIs that=20
Python provides for opaque frame access:
frame->f_code -> PyFrame_GetCode(frame)
frame->f_back -> PyFrame_GetBack(frame)
frame->f_trace =3D fn -> PyObject_SetAttrString(frame, "f_trace",=20
fn)
state->frame -> PyThreadState_GetFrame(state)
These APIs are stable across Python 3.11-3.14. The pre-3.11 code path is=20
preserved with #if guards, so older Python versions are unaffected.
This PR also fixed a long-standing bug in adb.py where step-over (F10)=20
would not stop after returning from a function =E2=80=94 dispatch_return no=
w=20
promotes stopframe to the caller frame.
Minimal change =E2=80=94 3 files, +33/-20 lines. Tested on Python 3.14.2 wi=
th a=20
custom ActiveX Script Host exercising the full debug path. I also built=20
a DAP (Debug Adapter Protocol) bridge that enables VS Code to debug=20
ActiveX-hosted Python scripts =E2=80=94 breakpoints, step-into, step-over,=
=20
step-out, variable inspection, and watch expressions all work correctly=20
through the fixed axdebug module.
Would appreciate your review when you get a chance.
Best,
Wuping
------ Original Message ------
>From "Wuping Xin" <[email protected]>
To "Mark Hammond" <[email protected]>; "[email protected]"=20
<[email protected]>
Date 3/3/2025 11:07:06 AM
Subject Re[2]: [python-win32] Python Active Scripting Debug
>
>Thank you Mark for the response. Appreciate your input.
>
>Best
>Wuping
>
>------ Original Message ------
>From "Mark Hammond" <[email protected]>
>To "Wuping Xin" <[email protected]>; "[email protected]"=20
><[email protected]>
>Date 3/3/2025 10:24:18 AM
>Subject Re: [python-win32] Python Active Scripting Debug
>
>>It has been quite a few years since anyone worked on that, but in=20
>>general it should "just work" if everything is registered correctly.=20
>>There are a few demos which should make OK starting points, and=20
>>ensuring everything is registered for debugging, and debugging output=20
>>can be seen (typically via win32traceutil) must be done.=20
>>Unfortunately, I'm not aware of anyone trying to use the VS tools in=20
>>this way.
>>
>>Good luck,
>>
>>Mark
>>
>>On 2025-02-28 8:54 p.m., Wuping Xin via python-win32 wrote:
>>>Hi All,
>>>
>>>I am trying to debug Python Active Scripting, using Visual Studio. I=20
>>>am 100% sure it should work but I just cannot get it work.
>>>
>>>I've installed the debug symbols of the Python version, and installed=20
>>>Visual Studio Python Native Development tools.
>>>
>>>I also set the "Debugging" registry entry for the ActivePy from 0 to=20
>>>1.
>>>
>>>I am able to attach the Python script to the PythonActiveScript host.
>>>
>>>But, I just got the following message:
>>>
>>>Debugging extensions (axdebug) module does not exist - debugging is=20
>>>disabled..
>>>
>>>
>>>Any insights?
>>>
>>>Thank you in advance!
>>>
>>>W.X.
>>>_______________________________________________
>>>python-win32 mailing list
>>>[email protected]
>>>https://mail.python.org/mailman/listinfo/python-win32
--------=_MBFD10089E-CCEA-499C-BACA-DE90934C6DCB
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<html><head>
=20
<style type=3D"text/css"><!--#x18cc6bec28b544c blockquote.cite
{margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right: 0p=
x; border-left: 1px solid rgb(204, 204, 204);}
#x18cc6bec28b544c blockquote.cite2
{margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right: 0p=
x; border-left: 1px solid rgb(204, 204, 204); margin-top: 3px; padding-top: =
0px;}
#x18cc6bec28b544c
{font-family: "Segoe UI"; font-size: 12pt;}
--></style><style id=3D"css_styles" type=3D"text/css"><!--blockquote.cite { =
margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px=
; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px;=
padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding=
-top: 0px; }
a img { border: 0px; }
li[style=3D'text-align: center;'], li[style=3D'text-align: center; '], li[s=
tyle=3D'text-align: right;'], li[style=3D'text-align: right; '] { list-sty=
le-position: inside;}
body { font-family: 'Segoe UI'; font-size: 12pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb soli=
d; padding-left: 0.3em; }
a.em-mention[href] { text-decoration: none; color: inherit; border-radius:=
3px; padding-left: 2px; padding-right: 2px; background-color: #e2e2e2; }
._em_placeholder {color: gray; border-bottom: 1px dotted lightblue;} ._em_p=
laceholder:before{color:gray; content: '{{ ';} ._em_placeholder:after{color=
:gray; content: ' }}';}
--></style></head>
<body><div>=C2=A0Hi Mark, All,</div><br />Following up on my earlier thre=
ad about axdebug being disabled on=C2=A0Python 3.11+ ("Debugging extensions =
(axdebug) module does not exist").<br /><br />I've tracked down the root c=
ause and submitted a fix:=C2=A0=C2=A0<a href=3D"https://github.com/mhammond=
/pywin32/pull/2723">https://github.com/mhammond/pywin32/pull/2723</a><br />=
<br />The error message comes from framework.py line 763 =E2=80=94 when Set=
ScriptSite=C2=A0creates the DebugManager, it tries to import axdebug. If ax=
debug.pyd=C2=A0doesn't exist (because the build was skipped on 3.11+), the=
ImportError=C2=A0is caught and debugging is silently disabled.<br /><br />R=
oot cause:=C2=A0<div><br /></div><div>Python 3.11 (PEP 523) made PyFrameObj=
ect an opaque type=C2=A0<span style=3D"color: rgb(0, 0, 0); font-size: 12pt=
;">:</span></div><div><span>=C2=A0 =C2=A0 =C2=A0-=C2=A0</span><span>=C2=A0C =
extensions can no longer access struct fields like frame->f_code,=C2=A0=
</span><span>=C2=A0frame->f_back, or frame->f_trace directly.=C2=A0</=
span></div><div><span>=C2=A0 =C2=A0 =C2=A0-=C2=A0 AXDebug.cpp's=C2=A0</span=
><span>SetThreadStateTrace() relied on direct struct access to walk the=C2=
=A0</span><span>=C2=A0frame chain and set trace functions, so it failed to=
compile on 3.11+.</span><span>=C2=A0=C2=A0</span></div><div><span><span></s=
pan>=C2=A0 =C2=A0 =C2=A0-=C2=A0 PyWin32: The module was disabled in setup.p=
y as a workaround.</span></div><div><br />The fix replaces direct struct ac=
cess with the official getter APIs=C2=A0that Python provides for opaque fra=
me access:<br /><br />=C2=A0 =C2=A0 frame->f_code=C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 ->=C2=A0 PyFrame_GetCode(frame)<br />=C2=A0 =C2=A0 frame->=
;f_back=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 PyFrame_GetBack(frame=
)<br />=C2=A0 =C2=A0 frame->f_trace =3D fn=C2=A0 ->=C2=A0 PyObject_Se=
tAttrString(frame, "f_trace", fn)<br />=C2=A0 =C2=A0 state->frame=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0->=C2=A0 PyThreadState_GetFram=
e(state)<br /><br />These APIs are stable across Python 3.11-3.14. The pre-=
3.11 code path=C2=A0is preserved with #if guards, so older Python versions=
are unaffected.<br /><br />This PR also fixed a long-standing bug in adb.py =
where step-over (F10) would=C2=A0not stop after returning from a function =
=E2=80=94 dispatch_return now promotes=C2=A0stopframe to the caller frame.=
<br /><br />Minimal change =E2=80=94 3 files, +33/-20 lines. Tested on Pyth=
on 3.14.2 with=C2=A0a custom ActiveX Script Host exercising the full debug=
path. I also=C2=A0built a DAP (Debug Adapter Protocol) bridge that enables=
VS Code to=C2=A0debug ActiveX-hosted Python scripts =E2=80=94 breakpoints,=
step-into,=C2=A0=C2=A0step-over, step-out, variable inspection, and watch e=
xpressions all=C2=A0work correctly through the fixed axdebug module.<br /><=
br />Would appreciate your review when you get a chance.<br /><br />Best,<b=
r />Wuping</div><div><br /></div><div><br />
<div>
<div>------ Original Message ------</div>
<div>From "Wuping Xin" <<a href=3D"mailto:[email protected]">oudouxin@g=
mail.com</a>></div>
<div>To "Mark Hammond" <<a href=3D"mailto:[email protected]">mha=
[email protected]</a>>; "[email protected]" <<a href=3D"ma=
ilto:[email protected]">[email protected]</a>></div>
<div>Date 3/3/2025 11:07:06 AM</div>
<div>Subject Re[2]: [python-win32] Python Active Scripting Debug</div></div=
><div x-em-quote=3D""><br /></div>
<div id=3D"x18cc6bec28b544c"><blockquote cite=3D"em36171177-4872-4535-9dcf-=
[email protected]" type=3D"cite" class=3D"cite2">
<div><br /></div>
<div>Thank you Mark for the response.=C2=A0 Appreciate your input.</div><di=
v><br /></div><div>Best</div><div>Wuping</div>
<div x-em-replyforwardheader=3D""><br /></div>
<div>
<div>------ Original Message ------</div>
<div>From "Mark Hammond" <<a href=3D"mailto:[email protected]">m=
[email protected]</a>></div>
<div>To "Wuping Xin" <<a href=3D"mailto:[email protected]">oudouxin@gma=
il.com</a>>; "[email protected]" <<a href=3D"mailto:python-win3=
[email protected]">[email protected]</a>></div>
<div>Date 3/3/2025 10:24:18 AM</div>
<div>Subject Re: [python-win32] Python Active Scripting Debug</div></div><d=
iv x-em-quote=3D""><br /></div>
<div id=3D"x9622fed07328432"><blockquote cite=3D"d8407d43-2c2c-4655-804e-af=
[email protected]" type=3D"cite" class=3D"cite2">
<p>It has been quite a few years since anyone worked on that, but in
general it should "just work" if everything is registered
correctly. There are a few demos which should make OK starting
points, and ensuring everything is registered for debugging, and
debugging output can be seen (typically via win32traceutil) must
be done. Unfortunately, I'm not aware of anyone trying to use the
VS tools in this way.
</p>
<p>Good luck,</p>
<p>Mark</p>
<div class=3D"moz-cite-prefix">On 2025-02-28 8:54 p.m., Wuping Xin via
python-win32 wrote:
<br />
</div>
<blockquote type=3D"cite" cite=3D"mid:em9d4802a6-462f-4de5-9a62-ea638a9=
[email protected]" class=3D"cite">Hi
All,
=20
<br />
<br />
I am trying to debug Python Active Scripting, using Visual
Studio.=C2=A0 I am 100% sure it should work but I just cannot get it
work.
=20
<br />
<br />
I've installed the debug symbols of the Python version, and
installed Visual Studio Python Native Development tools.
=20
<br />
<br />
I also set the "Debugging" registry entry for the ActivePy from 0
to 1.
=20
<br />
<br />
I am able to attach the Python script to the PythonActiveScript
host.
=20
<br />
<br />
But, I just got the following message:
<br />
<br />
Debugging extensions (axdebug) module does not exist - debugging
is disabled..
=20
<br />
<br />
<br />
Any insights?
<br />
<br />
Thank you in advance!
<br />
<br />
W.X.
<br />
_______________________________________________
<br />
python-win32 mailing list
<br />
<a class=3D"moz-txt-link-abbreviated" href=3D"mailto:python-win32@pyt=
hon.org">[email protected]</a>
<br />
<a class=3D"moz-txt-link-freetext" href=3D"https://mail.python.org/ma=
ilman/listinfo/python-win32">https://mail.python.org/mailman/listinfo/pytho=
n-win32</a>
<br />
</blockquote>
</blockquote></div>
</blockquote></div>
</div></body></html>
--------=_MBFD10089E-CCEA-499C-BACA-DE90934C6DCB--
--===============0344088001724198128==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
python-win32 mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-win32.python.org
Member address: [email protected]
--===============0344088001724198128==--