xmake-io / xmake-vscode

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

debug 时找不到 dll #133

Closed VirFunc closed 2 years ago

VirFunc commented 2 years ago

Xmake 版本

v2.6.9+HEAD.22ecc0156

操作系统版本和架构

Windows 10 version 21H1

描述问题

用一个很简单的工程测试了一下插件的功能,这个工程只有一个源代码文件,引用了 xmake-repo 上的 libsdl 库。 用插件来运行程序可以运行,在代码里获取了一下环境变量,应该是插件把 SDL2 的 dll 所在的文件夹加入了 PATH。 但是用插件来调试程序就会报错,看了一下错误代码,应该是 dll 没找到。

看了 xmake-vscode 的代码
https://github.com/xmake-io/xmake-vscode/blob/4c27f99a2d20f2d5a3b4f80f37191892eb15ab46/src/debugger.ts#L158-L162 可能是因为没有像 xmake run 那样设置设置环境变量? 因为不知道怎么从 xmake 获取到所需要设置的环境变量,我也没有办法自己写 launch, 虽然直接去 package 里把 dll 给 copy 过来可以结果问题,但是总不能每个 package 都手动 copy 一个过来吧。

希望作者大佬能指点一下

期待的结果

能够正常 debug 程序

工程配置

xmake.lua 文件如下

set_xmakever("2.6.9")
set_project("myapp")

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

add_requires("libsdl")

target("app")
    set_kind("binary")
    add_files("src/**.cpp")
    add_headerfiles("src/**.h")
    add_packages("libsdl")

唯一一个源代码文件 main.cpp,内容如下

#include "SDL_events.h"
#include "SDL_video.h"
#include <SDL2/SDL.h>

int main(int argc, char** argv) {
    SDL_Init(SDL_INIT_EVERYTHING);

    auto window = SDL_CreateWindow("app", 
        SDL_WINDOWPOS_CENTERED, 
        SDL_WINDOWPOS_CENTERED,
        1080,
        720,
        SDL_WINDOW_SHOWN);

    SDL_Event e;
    bool quit = false;

    while(!quit) {
        while(SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT) {
                quit = true;
                break;
            }
        }
    }

    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

附加信息和错误日志

vscode 调试控制台输出

-------------------------------------------------------------------
You may only use the C/C++ Extension for Visual Studio Code
with Visual Studio Code, Visual Studio or Visual Studio for Mac
software to help you develop and test your applications.
-------------------------------------------------------------------
Loaded 'D:\Projects\temp\vsxmake_test\build\windows\x64\debug\app.exe'. Symbols loaded.
Loaded 'C:\Windows\System32\ntdll.dll'. 
Loaded 'C:\Windows\System32\kernel32.dll'. 
Loaded 'C:\Windows\System32\KernelBase.dll'. 
The program '[13388] app.exe' has exited with code -1073741515 (0xc0000135).
waruqi commented 2 years ago

已知问题,目前还不支持透传环境变量给调试器

暂时没时间搞,你可以来个 pr

waruqi commented 2 years ago

开了个 pr ,https://github.com/xmake-io/xmake-vscode/pull/134

但是暂时没 win 环境测试,你可以拉下 runenvs 分支,自己 本地 调下,如果有问题,可以参考着改下 runenvs 分支实现。。

VirFunc commented 2 years ago

晚上回去试一下

VirFunc commented 2 years ago

测试了一下,debug 时还是存在问题,直接运行的 PATH 比 debug 的 PATH 多出了

C:\Users\<username>\AppData\Local\.xmake\packages\l\libsdl\2.0.22\8b7dc91315c541c989c1e4401c0a35e3\bin

看了一下 xmake 那边 make_runenvs 的实现,这里把 package 的 linkdir 加入了 PATH,根据 xmake require -l 的输出来看,libsdl 的 linkdir 只有 lib 文件夹,里面放了 .lib 文件,但是 xrepo 里的 libsdl 包在 install 的时候.dll 文件放进了 bin 文件夹里

但是看了 xmake 里 run 和 xmake-vscode 里 target_runenvs.lua 的实现,二者获取环境变量的方式都是走的 make_runenvs,不知道为什么会产生不同的结果。

waruqi commented 2 years ago

看下 target_runenvs.lua 的输出,按理会带上的

cd yourproject
xmake l /xxx/xxx/xxtarget_runenvs.lua targetname
VirFunc commented 2 years ago

试了一下,确实没有带上,单步调试插件的时候也看了,只有 lib

waruqi commented 2 years ago

应该可以了,更新下插件

VirFunc commented 2 years ago

现在可以正常调试了,感谢