Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig: debug with vscode #375

Open
5 tasks done
Tracked by #376 ...
hhstore opened this issue Jul 31, 2022 · 7 comments
Open
5 tasks done
Tracked by #376 ...

Zig: debug with vscode #375

hhstore opened this issue Jul 31, 2022 · 7 comments
Labels
Tutorial vscode Visual Studio Code Zig

Comments

@hhstore
Copy link
Owner

hhstore commented Jul 31, 2022

related:

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

Zig + vscode 配置 debug 断点调试:

  • 可能是全网首发的 zig + vscode debug 断点调试 的完整配置教程.

准备工作:

关于如何配置 zig+zls+vscode, 请看此篇: #361

Debug 示例:

示例:

zig build.zig 构建脚本修改:

image

dev@dev:~/D/i/b/ziglings-solutions|solutions✓
 zig build 15

Compiling 015_for.zig...
Checking 015_for.zig...
Zig Build Result: /xxx/ziglings-solutions/zig-cache/o/a9333ffcfddf7b471e7e17163202b638/015_for
PASSED:

vscode 配置:

  • .vscode/ 添加: launch.json, 内容如下:
  • 关键配置项: program, 是 zig build 编译结果完整路径. (需要先编译 zig 项目代码, 再手动指定)
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug ex002",
            // "program": "${workspaceFolder}/<executable file>",
            "program": "${workspaceFolder}/zig-cache/o/61ece68b736d12a98d44010040aab147/002_std",
            "args": [
                "exercises/002_std.zig"
            ],
            "cwd": "${workspaceFolder}"
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug ex015",
            // "program": "${workspaceFolder}/<executable file>",
            "program": "${workspaceFolder}/zig-cache/o/a9333ffcfddf7b471e7e17163202b638/015_for",
            "args": [
                "exercises/015_for.zig"
            ],
            "cwd": "${workspaceFolder}"
        }
    ]
}

截图效果:

  • 配置说明:

image

  • 断点调试效果:

image

  • 目前 debug 插件, 功能支持不完善, 不能捕获全局变量/常量. (修改此例)

image

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

1

4 similar comments
@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

1

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

1

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

1

@hhstore
Copy link
Owner Author

hhstore commented Jul 31, 2022

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tutorial vscode Visual Studio Code Zig
Projects
None yet
Development

No branches or pull requests

1 participant