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 doesn't produce global variable debug information #15095

Closed
ryuukk opened this issue Mar 28, 2023 · 13 comments · Fixed by #19865
Closed

zig doesn't produce global variable debug information #15095

ryuukk opened this issue Mar 28, 2023 · 13 comments · Fixed by #19865
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@ryuukk
Copy link
Contributor

ryuukk commented Mar 28, 2023

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

@ryuukk ryuukk added the bug Observed behavior contradicts documented or intended behavior label Mar 28, 2023
@squeek502
Copy link
Collaborator

squeek502 commented Mar 28, 2023

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

@ryuukk
Copy link
Contributor Author

ryuukk commented Mar 28, 2023

I tried with referencing it, no luck

image

@david4r4
Copy link
Contributor

david4r4 commented Mar 28, 2023

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 ryuukk changed the title windows: debuggers can't inspect global variables zig doesn't produce global variable debug information Mar 28, 2023
@ryuukk
Copy link
Contributor Author

ryuukk commented Mar 29, 2023

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
Copy link
Contributor

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
Copy link
Contributor Author

ryuukk commented Mar 30, 2023

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

image

@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Apr 10, 2023
@andrewrk andrewrk added this to the 0.11.0 milestone Apr 10, 2023
@andrewrk
Copy link
Member

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
Copy link

r1sc commented Jul 13, 2023

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

@LaXiS96
Copy link

LaXiS96 commented Nov 7, 2023

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.

@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0, 0.13.0 Jan 29, 2024
@andrewrk andrewrk added backend-llvm The LLVM backend outputs an LLVM IR Module. and removed frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels May 9, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, 0.13.0 May 22, 2024
@Srekel
Copy link

Srekel commented Jun 10, 2024

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
Copy link

Srekel commented Jun 10, 2024

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
Copy link
Member

Vexu commented Jun 10, 2024

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
Copy link

Srekel commented Jun 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants