Skip to content

Cross-Compiling for Windows breaks error stack traces #12729

Open

Description

@nolanderc

Zig Version

0.10.0-dev.3857+10e11b60e

Steps to Reproduce

mkdir zig-test && cd zig-test
zig init-exe

and replace src/main.zig with the following:

const std = @import("std");

pub fn main() !void {
    std.log.info("running on thread {}", .{std.Thread.getCurrentId()});
    return error.Whatever;
}

Then build the program on a non-windows OS (tested using Ubuntu 20.04 through WSL2):

zig build -Dtarget=x86_64-windows

Expected Behavior

The program should terminate with a message containing the error and a stack trace showing where the error originated from. For example, this is the result when on WSL2 using zig build run:

info: running on thread 24663
error: Whatever
/home/christofer/dev/tmp/zig-test/src/main.zig:5:5: 0x20d416 in main (zig-test)
    return error.Whatever;
    ^

Actual Behavior

Attempting to run this program on a Windows machine (tested on Windows 11 build 22000.856) produces the following output:

info: running on thread 32448
error: Whatever
thread 32448 panic: reached unreachable code
Panicked during a panic. Aborting.

Activity

  1. added
    bug
    on Sep 3, 2022
  2. nolanderc commented on Sep 7, 2022

    @nolanderc
    ContributorAuthor

    I have a hunch that this might be related to #8205, since all sources live in WSL and thus use UNC paths when creating the stack trace.

  3. added
    os-windows
    arch-x86_64
    on Oct 15, 2022
  4. added this to the 0.11.0 milestone on Oct 15, 2022
  5. added a commit that references this issue on Apr 14, 2023
  6. added a commit that references this issue on Apr 23, 2023
  7. squeek502 commented on May 29, 2023

    @squeek502
    Member

    Now that #15768 is merged, could anyone using WSL2 test to see if this was fixed by it?

  8. star-tek-mb commented on May 29, 2023

    @star-tek-mb
    Contributor

    Now that #15768 is merged, could anyone using WSL2 test to see if this was fixed by it?

    Stack traces are still broken like that on WSL2:
    ???:?:?: 0x7ff77c7d33a2 in ??? (test.exe)

  9. kcbanner commented on May 30, 2023

    @kcbanner
    Contributor

    I looked into this, and it's happening because the PDB path is of the form /home/kcbanner/temp/12729/zig-cache/o/84727f745cb2d4778303a1b5b8068004/12729.pdb.

    After the call to fs.path.resolve in readCoffDebugInfo, path is \home\kcbanner\temp\12729\zig-cache\o\84727f745cb2d4778303a1b5b8068004\12729.pdb. This then fails to open in the call to openFile in Pdb.init.

  10. kcbanner commented on Jul 21, 2023

    @kcbanner
    Contributor

    There is an additional problem, even if you do find the PDB by doing something like:

            const pdb_paths = [_][]const u8{
                path,
                fs.path.basename(path),
            };
    
            di.debug_data = PdbOrDwarf{ .pdb = undefined };
            di.debug_data.pdb = for (pdb_paths) |pdb_path| {
                break pdb.Pdb.init(allocator, pdb_path) catch |err| switch (err) {
                    error.FileNotFound, error.IsDir => continue,
                    else => return err,
                };
            } else return error.MissingDebugInfo;

    All the source paths are also unix-style, ie:

    image

    So to support this we'd need to have some path-mapping heuristic for source files as well.

  11. modified the milestones: 0.11.0, 0.11.1 on Jul 22, 2023
  12. modified the milestones: 0.11.1, 0.12.0, 0.13.0 on Jan 29, 2024
  13. modified the milestones: 0.14.0, 0.15.0 on Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_64bugos-windows

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions