您如何使用 'Code::Blocks 20.03'("mingw" 版本)进行调试?

How do you debug using 'Code::Blocks 20.03' (the "mingw" version)?

我使用 Code::Blocks 20.03 构建了一个 Console Application,它是使用 codeblocks-20.03mingw-setup.exe 安装的。使用默认的安装目录(见注释 01)和安装类型(完整)。

我尝试 Debug 使用 Debug 菜单,单击 Start/Continue,但调试失败。

我想日志中的重要信息是

Starting the debuggee failed: No executable specified, use `target exec'

尝试调试的完整输出如下。

我的问题是,如何使用 Code::Blocks 20.03 (the "mingw" version) 进行调试?

尝试 运行 调试会话的完整输出。


Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target: 
Debug
Adding source dir: C:\CodeBlocks20.03Small\ConsoleApplication\program01INc\
Adding source dir: C:\CodeBlocks20.03Small\ConsoleApplication\program01INc\
Adding file: C:\CodeBlocks20.03Small\ConsoleApplication\program01INc\bin\Debug\program01INc.exe
Changing directory to: C:/CodeBlocks20.03Small/ConsoleApplication/program01INc/.
Set variable: PATH=.;C:\Program Files\CodeBlocks\MinGW\bin;C:\Program Files\CodeBlocks\MinGW;C:\Program Files\Microsoft MPI\Bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server0\Tools\Binn;C:\Program Files (x86)\Skype\Phone;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd;C:\Users\Roger\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm;C:\Program Files\Microsoft SQL Server0\Tools\Binn;C:\Program Files (x86)\GtkSharp.12\bin;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0;c:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn;c:\Program Files\Microsoft SQL Server0\DTS\Binn;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\FreeFem++;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\Roger\AppData\Local\Programs\Python\Python38-32\Scripts;C:\Users\Roger\AppData\Local\Programs\Python\Python38-32;C:\Users\Roger\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64;C:\texlive17\bin\win32;C:\Users\Roger\AppData\Local\Microsoft\WindowsApps;\;C:\Program Files (x86)\clisp-2.49
Starting debuggee: C:\MinGW\bin\gdb.exe -nx -fullname -quiet  -args C:/CodeBlocks20.03Small/ConsoleApplication/program01INc/bin/Debug/program01INc.exe
done
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.6.1
Starting the debuggee failed: No executable specified, use `target exec'.
Debugger finished with status 0
===============================

在构建我的项目时,我使用了 Select Compiler 对话框中的默认值。

注01:

看起来您应该(日期 2021 年 4 月 11 日)始终使用默认目录进行安装。我在 C:\Program Files\CodeBlocksSmall 中安装了 Code::Blocks 的版本,当我去卸载它时,卸载程序只会接受 C:\Program Files\CodeBlocks 作为卸载目录。我手动删除了 CodeBlocksSmall 目录。我在使用 codeblocks-20.03-setup.exe.

安装时注意到了这种行为

相关问题 Starting the debuggee failed: No executable specified, use `target exec'

=======================

看起来好像先前安装的 MinGW 被尝试的调试会话无意中使用了(这不再可能)。查看文件的参与

C:\MinGW\bin\gdb.exe,在行

Starting debugger: C:\MinGW\bin\gdb.exe -nx -fullname -quiet  -args

现在,当我尝试 运行 调试会话时,失败发生的方式有所不同(请参阅接下来的四行之后)。

在我看来,我至少需要更改

指示的行为
Starting debugger: C:\MinGW\bin\gdb.exe -nx -fullname -quiet  -args

产生的行为
Starting debugger: C:\Program Files\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname -quiet -args

Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target: 
Debug
Adding source dir: C:\Codeblocks20.03\ConsoleApp\program01INcForAnswer\
Adding source dir: C:\Codeblocks20.03\ConsoleApp\program01INcForAnswer\
Adding file: C:\Codeblocks20.03\ConsoleApp\program01INcForAnswer\bin\Debug\program01INcForAnswer.exe
Changing directory to: C:/Codeblocks20.03/ConsoleApp/program01INcForAnswer/.
Set variable: PATH=.;C:\Program Files\CodeBlocks\MinGW\bin;C:\Program Files\CodeBlocks\MinGW;C:\Program Files\Microsoft MPI\Bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server0\Tools\Binn;C:\Program Files (x86)\Skype\Phone;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd;C:\Users\Roger\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm;C:\Program Files\Microsoft SQL Server0\Tools\Binn;C:\Program Files (x86)\GtkSharp.12\bin;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0;c:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn;c:\Program Files\Microsoft SQL Server0\DTS\Binn;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\FreeFem++;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\Roger\AppData\Local\Programs\Python\Python38-32\Scripts;C:\Users\Roger\AppData\Local\Programs\Python\Python38-32;C:\Users\Roger\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64;C:\texlive17\bin\win32;C:\Users\Roger\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\clisp-2.49
Starting debugger: C:\MinGW\bin\gdb.exe -nx -fullname -quiet  -args C:/Codeblocks20.03/ConsoleApp/program01INcForAnswer/bin/Debug/program01INcForAnswer.exe
failed

另一个相关问题在

code blocks failed message runing hello code

那里,错误消息就像上面显示的那样,另请参见下面

Starting debugger: C:\MinGW\bin\gdb.exe -nx -fullname -quiet -args C:/Codeblocks20.03/ConsoleApp/program01INcForAnswer/bin/Debug/program01INcForAnswer.exe failed

请注意,在这两种情况下,Code::Blocks 都试图从目录 C:\MinGW\bin

调用调试器

要使调试工作,如果您在 Windows 上安装 Code::Blocks 20.03MinGW 版本,使用 codeblocks-20.03mingw-setup.exe( 2021 年 4 月 8 日版本,接受默认安装)。

为了让它工作,我做了以下工作。

Settings 菜单中,我单击了 Debugger..,然后在屏幕左侧选择了 Default,一种调试器类型。这向我显示 Executable paths 设置为

C:\MinGW\bin\gdb.exe

我改成了

C:\Program Files\Codeblocks\MinGW\bin\gdb.exe

然后我就可以使用调试器了。