ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.23k stars 2.57k forks source link

zig doesn't produce global variable debug information #15095

Closed ryuukk closed 6 months ago

ryuukk commented 1 year ago

Zig Version

zig-windows-x86_64-0.11.0-dev.2287+1de64dba2.zip

OS: Windows 10 x64

Steps to Reproduce and Observed Behavior

var global: i32 = 0;

pub fn main() !void
{

}

break and try to inspect global

vscode:

image

remedybg:

image

vscode launch config:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "windows: game",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/game.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/bin/",
            "environment": [],
            "externalConsole": false,
        },
    ]
}

Expected Behavior

I should be able to inspect global in the debugger's watch menu

squeek502 commented 1 year ago

Does adding pub to global change anything? I would guess that it is getting optimized out since it's unused and not pub.

ryuukk commented 1 year ago

I tried with referencing it, no luck

image

david4r4 commented 1 year ago

It's not only a Windows problem, I believe. Even when you use it, if you make it pub or even if you export it, it makes no difference. You can play with it here: https://godbolt.org/z/Yrocjf3T3 If you check, the C version has a little !dbg tag that the Zig version does not have.

ryuukk commented 1 year ago

It's not only a Windows problem, I believe. Even when you use it, if you make it pub or even if you export it, it makes no difference. You can play with it here: https://godbolt.org/z/Yrocjf3T3 If you check, the C version has a little !dbg tag that the Zig version does not have.

I don't think that's because of it, D has the same problem, even thought you can see the !dbg https://godbolt.org/z/5GGz3W1To

david4r4 commented 1 year ago

Yeah, I think I was wrong and I apologize. Actually exporting the variable works for me on Linux, you could try that in the meantime. The problem seems to be with namespaced non-exported global variables... I can't get to inspect them with GDB.

ryuukk commented 1 year ago

with export it finds the variable, but it doesn't understand what type it is:

image

andrewrk commented 1 year ago

Not fixed by #15349:

var global: i32 = 0;

pub fn main() !void {
    global += 124;
}
$ gdb ./test
(gdb) break test.main
Breakpoint 1 at 0x20af48: file test.zig, line 4.
(gdb) run
Starting program: /home/andy/Downloads/zig/build-release/test 

Breakpoint 1, test.main () at test.zig:4
4       global += 124;
(gdb) p 'test.global'
$1 = <optimized out>
(gdb) 
r1sc commented 1 year ago

Is there any progress on this? I'd like to help but I'm not really familiar with the Zig compiler infrastructure yet..

LaXiS96 commented 1 year ago

Can confirm this also happens while targeting thumb-freestanding-none and using the Cortex-Debug VSCode extension. At first I thought it could have been an extension issue but it's GDB that doesn't "see" the variable.

Srekel commented 5 months ago

This is not solved for me.

image

This is using a default exe setup I think. Here is my tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "zig build  --summary failures",
            "group": "build",
            "problemMatcher": [
                "$gcc"
            ],
            "presentation": {
                "clear": true
            }
        },
    ]
}

and here is launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/zig-out/bin/zigtesting.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "preLaunchTask": "build"
        },
    ]
}

Running on Windows 11 Home. builtin.zig_version prints debug: 0.13.0

Srekel commented 5 months ago

On a separate note, would it be possible to get a specific github label for bugs about missing debug information, or actually debug-related issues in general?

I would love to report more, as they are at the top of the list of Zig things we would like improved for Tides, but it's hard to know which ones are already reported (long list of issues to look through).

Vexu commented 5 months ago

Are you able to see the value of hello by hovering over it? For me using lldb a.global is showing up as a static variable (which is incorrect but a different issue).

On a separate note, would it be possible to get a specific github label for bugs about missing debug information, or actually debug-related issues in general?

Sure!

Srekel commented 5 months ago

Are you able to see the value of hello by hovering over it?

Yep!

image

Also it shows up if I add a watch for it. lol however doesn't.