xmake-io / xmake-vscode

🍩 A XMake integration in Visual Studio Code
https://xmake.io
Apache License 2.0
229 stars 54 forks source link

vscode 调试存在bug #123

Open F7kyyy opened 2 years ago

F7kyyy commented 2 years ago

Xmake 版本

2.6.8

操作系统版本和架构

Windows 10 专业版 21H2

描述问题

工具链使用的是msys2安装的mingw-w64-x86_64-toolchain,xmake同样是使用msys2安装 image

在调试过程中,断点调试时,打的断点位置不是鼠标点击位置 同时高亮的行并不是代码运行的行,我应该执行for循环,但是高亮的行数不对 调试 同样的代码使用微软cmake插件则没有这个问题

期待的结果

可以解答是配置问题,还是软件自身问题

工程配置

xmake.lua

add_rules("mode.debug", "mode.release")

target("hello_xmake")
    set_kind("binary")
    add_includedirs("includes")
    add_files("src/main.cpp")

文件结构,.cathe .clangd是使用vscode clangd插件,在不使用,仅使用官方C/C++插件,同样存在问题

│  .clang-format
│  .clangd
│  .gitignore
│  xmake.lua
│
├─.cache
│  
├─.vscode
│      
├─build
│  
├─includes
│      fun.h
└─src
        main.cpp

fun.h

#include <bits/stdc++.h>

void disply_print() {
    for (int i = 0; i < 10; i++) {
        std::cout << "hello xmake"
                  << "\n";
    }
}

void extracted() {
    std::deque<int> poker;
    for (int i = 1; i < 100; i++) {
        poker.emplace_back(i);
    }
    int i = 1;
    while (poker.size() > 1) {
        int t = poker.front();
        poker.pop_front();
        if (i % 7 == 0) {
            poker.emplace_back(t);
        }
        i++;
    }

    printf("the last poker is: %d", poker.front());
}

main.cpp

#include "fun.h"

void disply() {
    std::cout << "the number of Students is 32" << std::endl;
}

void displaynumber() {
    std::vector<int> v{0, 1, 2, 3};
    for (auto &value : v) {
        std::cout<<value<<" ";
    }
}

int main() {
    disply();
    disply_print();
    displaynumber();
    extracted();
}

setting.json

"xmake.compileCommandsDirectory": "${workspaceRoot}/build",
"xmake.customDebugConfig": {
    "stopAtEntry": false,
    "externalConsole": false,
    "internalConsoleOptions": "neverOpen",
    "setupCommands": [
        {
            "description": "为 gdb 启用整齐打印",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }
    ]
}

附加信息和错误日志

没有显示错误,正常调试,但是存在上述问题

waruqi commented 2 years ago

dev 分支做过一些改动,你可以更新到 dev 版本再试试

https://github.com/xmake-io/xmake/issues/2509

waruqi commented 2 years ago

另外,确认下你这里的编译平台,windows/msvc 还是 mingw/gcc

F7kyyy commented 2 years ago

dev 分支做过一些改动,你可以更新到 dev 版本再试试

xmake-io/xmake#2509

执行xmake update -s dev,更新lua脚本还存在问题,在xmake,github realease页面下载xmake-dev.win64.exe好像也不太行,还存在以上问题。

waruqi commented 2 years ago

另外,确认下你这里的编译平台,windows/msvc 还是 mingw/gcc

先确认下,啥信息也不给,就说不行。。我咋只知道什么问题。

F7kyyy commented 2 years ago

另外,确认下你这里的编译平台,windows/msvc 还是 mingw/gcc

mingw/gcc,使用msys2 安装的mingw-w64-x86_64-toolchain image

waruqi commented 2 years ago

-vD 编译看下,贴下 link flags

F7kyyy commented 2 years ago

-vD 编译看下,贴下 link flags

❯ xmake build -v -D
[ 25%]: ccache compiling.debug src\main.cpp
C:\Users\FengisZZZ\ServerTools\msys\mingw64\bin\x86_64-w64-mingw32-g++ -c -m64 -g -O0 -Iincludes -o c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\.objs\test\mingw\x86_64\debug\src\main.cpp.obj src\main.cpp
[ 50%]: linking.debug test.exe
C:\Users\FengisZZZ\ServerTools\msys\mingw64\bin\x86_64-w64-mingw32-g++ -o c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\mingw\x86_64\debug\test.exe c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\.objs\test\mingw\x86_64\debug\src\main.cpp.obj -m64 -g

build cache stats:
cache directory: c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\.build_cache
cache hit rate: 100%
cache hit: 1
cache miss: 0
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0

[100%]: build ok!
waruqi commented 2 years ago

你先手动配置上 add_ldflags("-O0", {force = true}) ,然后再执行 -vD 给我看下,再试试调试是否可以

F7kyyy commented 2 years ago
❯ xmake build -vD
[ 25%]: ccache compiling.debug src\main.cpp
C:\Users\FengisZZZ\ServerTools\msys\mingw64\bin\x86_64-w64-mingw32-g++ -c -m64 -g -O0 -Iincludes -o c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\.objs\test\mingw\x86_64\debug\src\main.cpp.obj src\main.cpp
[ 50%]: linking.debug test.exe
C:\Users\FengisZZZ\ServerTools\msys\mingw64\bin\x86_64-w64-mingw32-g++ -o c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\mingw\x86_64\debug\test.exe c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\.objs\test\mingw\x86_64\debug\src\main.cpp.obj -m64 -g -O0

build cache stats:
cache directory: c:\Users\FengisZZZ\Desktop\Project\Xmake_dev\test\build\.build_cache
cache hit rate: 100%
cache hit: 1
cache miss: 0
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0

[100%]: build ok!

调试还是不可以。

waruqi commented 2 years ago

那就不知道了,这边也只是把 binary 送给 vscode 配置的调试器。

你可以对下跟 cmake 的 编译link flags,再对下加载的调试器差异。

F7kyyy commented 2 years ago

好的,我看看去

f-zl commented 2 years ago

碰到了类似的问题。同工程同样msys2的gcc 11.2.0工具链,用xmake v2.6.8编译,用vscode的cpptools调试时行数错误,用cmake ninja编译可以正常调试(CMakeLists使用xmake生成)。

waruqi commented 2 years ago

可以对下 cmake 的 编译和链接 flags ,看下差异,挨个排除对比下