【问题标题】:Debug a problem in tk85.dll in an application that embeds the Python interpreter在嵌入 Python 解释器的应用程序中调试 tk85.dll 中的问题
【发布时间】:2011-01-31 13:55:10
【问题描述】:

我的 C++ 应用程序嵌入了 Python 解释器,但在关闭时似乎遇到了一些问题。在主窗口关闭后,我得到一个分段错误(这是 Windows,但无论如何我们都会称它为分段错误)。堆栈跟踪如下:

#0 102AD580 tk85!Tk_MainWindow() (C:\Users\... 1.3\bin\Debug\lib\tk85.dll:??)
#1 103082DD tk85!XSetStipple() (C:\Users\... 1.3\bin\Debug\lib\tk85.dll:??)
#2 102214A3 ??() (C:\Users\...1.3\bin\Debug\lib\tk85.dll:??)
#3 10220000 ??() (??:??)
#4 00000000 ??() (??:??)

我什至从哪里开始调试这个问题?它似乎是可重现的。

【问题讨论】:

  • 我在一台机器上遇到了同样的问题。我们没有有意识地导入tkinter 或相关代码。但是删除 tk85.dll 会阻止问题的发生。
  • 是否有一些示例应用程序,与解释器一起分发?如果是,它会崩溃吗?
  • 你有来源吗? XSetStipple 想做什么?平分的一种方法是创建一个atexit 处理程序并在其中放置一个断点以查看是否在拆卸之前或之后发生这种情况(使用您的处理程序在退出代码处进入 CRT 并将断点放在该函数,因此您可以在所有处理程序之前捕获它)。退出期间会发生一些暴力事件,例如除主线程之外的所有线程都被杀死,因此这可能是其中的一部分。也可能一些资源被释放,这个函数不应该被调用。 tk 有关闭路径吗?
  • 如果您有 Windows 10,则从 Windows 商店安装 WinDbg Preview,并在启用时间旅行调试的情况下记录跟踪。然后打开这个踪迹,从最后往后退一步,直到你第一次在堆栈踪迹中看到熟悉的东西。也许它会帮助你了解你是如何陷入困境的。此外,您还可以看到那里的模块卸载顺序。

标签: c++ python embed tkinter


【解决方案1】:

首先,我让你知道I identified race conditions in Python's Tkinter when used with nonthreaded Tcl/Tk (Py2 is shipped with that) and proposed a fix。我不确定我修复了所有可能的竞争条件,但我确实修复了我遇到的所有问题。

现在,为了能够调试 Tcl/Tk 问题,您需要使用调试版本的 Tcl/Tk 构建 Python 并将其嵌入。这应该使您能够在调试器中查看 tk*.dll 并查看问题所在。

  • 获取您的 Python 版本的源代码并进行以下更改:

    --- a/PCbuild/prepare_tcltk.bat
    +++ b/PCbuild/prepare_tcltk.bat
    @@ -46,10 +46,10 @@ rem if ERRORLEVEL 1 (echo Cannot locate python.exe on PATH or as PYTHON variable
    
     call "%PCBUILD%\get_externals.bat" --tkinter-src %ORG_SETTING%
    
    -%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Release /p:Platform=Win32
    -%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Release /p:Platform=Win32
    -%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Release /p:Platform=Win32
    +%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Debug /p:Platform=Win32
    +%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Debug /p:Platform=Win32
    +%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Debug /p:Platform=Win32
    
    -%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Release /p:Platform=x64
    -%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Release /p:Platform=x64
    -%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Release /p:Platform=x64
    +%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Debug /p:Platform=x64
    +%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Debug /p:Platform=x64
    +%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Debug /p:Platform=x64
    
  • 从 VS 命令提示符运行 PCBuild\prepare_tcltk.bat 以从源代码下载和构建 Tcl/Tk

  • 现在像往常一样构建一个调试 Python(PCBuild\readme.txt 有说明)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    相关资源
    最近更新 更多