xavier-cai / vscode-leetcode-cpp-debug

Debug support for LeetCode with C++
https://marketplace.visualstudio.com/items?itemName=XavierCai.vscode-leetcode-cpp-debug
MIT License
25 stars 5 forks source link

mac无法调试么? #2

Closed linconz closed 4 years ago

linconz commented 4 years ago

我看output里提示一个exe文件未找到

xavier-cai commented 4 years ago

我这边没有测试过MAC环境,但是理论上应该是可以调试,毕竟这个插件只负责生成main函数这些代码,只要能自己准备好C++调试环境和配置(也就是.vscode文件夹),就能够调试。

如果遇到一些问题,可以把问题发生的条件和情况截图或详细说明,这样子我就有机会定位并解决这个问题。

linconz commented 4 years ago

我对VSCode用的也不怎么熟练... 昨天试了下,提示找不到stdc++.h这个头文件在mac应该是用不了的 另外还发现个问题,如果现在选的是leetcode-cn,生成的cpp文件名是中文题目,这样也编译不了...这个问题应该找leetcode插件作者才能解决

> Executing task: /usr/bin/clang++ -std=c++17 -stdlib=libc++ -g /Users/zhang/workfolder/leetcode/leetcode-main.cpp -o /Users/zhang/workfolder/leetcode/leetcode-main <

In file included from /Users/zhang/workfolder/leetcode/leetcode-main.cpp:3:
In file included from /Users/zhang/workfolder/leetcode/leetcode-entry.h:10:
In file included from /Users/zhang/workfolder/leetcode/leetcode-handler.h:6:
In file included from /Users/zhang/workfolder/leetcode/1.Sum.cpp:1:
/Users/zhang/workfolder/leetcode/leetcode-definition.h:44:10: fatal error: 'bits/stdc++.h' file not found
#include <bits/stdc++.h>
         ^~~~~~~~~~~~~~~
1 error generated.
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
xavier-cai commented 4 years ago

目前我自己的开发环境使用的是MinGW,所以对Clang测试不够,包括您提到的头文件和中文支持问题,这个工作将在之后完成,感谢您的使用!

目前这个问题的临时解决方案有:

  1. 自行在include路径下添加<bits/stdc++.h>头文件,内容包含常用头文件即可(或者从网上查找)。
  2. 找到LeetCode插件名为File Path的设置项,点击Edit in setting.json,添加如下内容即可将文件名修改为如1.cpp的形式:
    "leetcode.filePath": {
        "default": {
            "filename": "${id}.${ext}",
            "folder": ""
        }
    }
linconz commented 4 years ago

目前我自己的开发环境使用的是MinGW,所以对Clang测试不够,包括您提到的头文件和中文支持问题,这个工作将在之后完成,感谢您的使用!

目前这个问题的临时解决方案有:

  1. 自行在include路径下添加<bits/stdc++.h>头文件,内容包含常用头文件即可(或者从网上查找)。
  2. 找到LeetCode插件名为File Path的设置项,点击Edit in setting.json,添加如下内容即可将文件名修改为如1.cpp的形式:
    "leetcode.filePath": {
       "default": {
           "filename": "${id}.${ext}",
           "folder": ""
       }
    }

头文件的问题已经解决了,现在可以编译了,但是发现无法输入测试用例 我在launch.js里设置了externalConsoletrue,编译后可以自动打开终端,但是就停在那里不动了,看起来像是没有进入到工程文件夹,也没有执行起来leetcode-main

linconz commented 4 years ago

launch.json如下:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "leetcode-main",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "lldb",
            "preLaunchTask": "clang++ build active file"
        }
    ]
}

task.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=c++17",
                "-stdlib=libc++",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
xavier-cai commented 4 years ago

那终端是否有提示类似Input from [std::cin]的字样呢?

linconz commented 4 years ago

那终端是否有提示类似Input from [std::cin]的字样呢?

  • 如果没有提示,那可能是未能执行编译结果程序,需要您检查VS Code的调试功能是否正常运作
  • 如果有提示且处于无法输入的状态,可以尝试以下步骤,若始终无法输入则可能是临时代码有输入BUG需要修复,方便的话可以贴出题解源码然后我这边尝试一下定位问题

    • 可以尝试手动运行该程序
    • 或者在VS Code退出调试前,复制并保留工作目录下的以leetcode-开头的临时代码文件,并尝试手动编译名为leetcode-main.cpp的入口文件

发现用默认的cppdbg进行调试会出问题,vscode并没有进入输入测试用例的状态,externalConsole改为true调起默认终端也不会进入调试状态,然后我装了CodeLLDB插件,修改了launch.json里的typelldb,然后就可以在vs vode的terminal中输入测试用例进行调试了

xavier-cai commented 4 years ago

很高兴问题解决了,感谢您的使用与反馈!: )