Closed huangluzhi closed 3 years ago
可能的原因: 您的lc和其他工程使用了不同的vscode(调试)配置
解决方案:
Delete Temporary Contents
值置为false
LeetCode C++ Debugger: Start Debugging
生成并保留临时代码文件(leetcode-main.cpp
等文件)leetcode-main.cpp
作为程序入口手动启动调试过程排除插件干扰如图,排除插件干扰后可以正常调试,通过插件启动无法正常调试。 我的环境及配置为 OS: Win10 x64 Professional 编译器: MinGW g++.exe .vscode文件夹内配置: launch.json
"version": "0.2.0",
"configurations": [{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": ["-g",],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"internalConsoleOptions": "neverOpen", /
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile"
}]
tasks.json
"version": "2.0.0",
"tasks": [{
"label": "Compile",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g",
"-m64",
"-Wall",
"-static-libgcc",
"-fexec-charset=GBK",
// "-std=c11",
],
"type": "process",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher":"$gcc"
}]
settings.json
"files.defaultLanguage": "c",
"editor.formatOnType": true,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.acceptSuggestionOnEnter": "off",
// "editor.snippetSuggestions": "top",
"code-runner.runInTerminal": true,
"code-runner.executorMap": {
"c": "gcc '$fileName' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -lm -static-libgcc -std=c11 -fexec-charset=GBK && &'./$fileNameWithoutExt.exe'",
"cpp": "g++ '$fileName' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -static-libgcc -std=c++14 -fexec-charset=GBK && &'./$fileNameWithoutExt.exe'"
// "c": "gcc $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -lm -static-libgcc -std=c11 -fexec-charset=GBK && $dir$fileNameWithoutExt.exe",
// "cpp": "g++ $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -static-libgcc -std=c++14 -fexec-charset=GBK && $dir$fileNameWithoutExt.exe"
},
"code-runner.saveFileBeforeRun": true,
"code-runner.preserveFocus": true,
"code-runner.clearPreviousOutput": false,
"code-runner.ignoreSelection": true,
"code-runner.fileDirectoryAsCwd": true,
"C_Cpp.clang_format_sortIncludes": true,
"files.associations": {
"algorithm": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"iterator": "cpp",
"xhash": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"deque": "cpp",
"list": "cpp",
"vector": "cpp",
"xstring": "cpp"
},
很遗憾使用您提供的配置文件无法复现该问题,可能需要您自行对比两种运行条件下的DEBUG CONSOLE的输出内容来发现问题,欢迎您贴出您发现的内容来做进一步的讨论。
以插件作为入口调试,发现断点仅在class Solution所在的cpp文件里失效,并且单步调试进入文件时会报错。以main.cpp为入口调试同样在答题的cpp内断点失效。 通过搜索得知MinGW的gdb调试不支持中文路径,而本身文件名又默认包含中文(中文leetcode站),因此我推断应该是文件包含中文路径的问题。请问这种情况除了换调试器还有其他方法吗,如果没有的话请问能推荐合适的调试器吗?
解决方案如下:
方案1 更改文件名使其不包含中文:
找到LeetCode
插件名为File Path
的设置项,点击Edit in setting.json
,添加如下内容即可将文件名修改为如1.cpp的形式:
"leetcode.filePath": {
"default": {
"filename": "${id}.${ext}",
"folder": ""
}
}
方案2 使用支持中文路径的编译/调试工具如clang/lldb
感谢解答
您好,按照说明运行LeetCode C++ Debugger: Start Debugging断点变成圆圈并提示module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained,无法单步调试,但是终端有响应并能正常输入输出。 此情况仅在使用插件调试时出现,在自己的leetcode无关的工程调试中则正常。