Skip to content

attempt to print stack trace addresses #1

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

Closed
wants to merge 3 commits into from
Closed

attempt to print stack trace addresses #1

wants to merge 3 commits into from

Conversation

jfo
Copy link
Owner

@jfo jfo commented Feb 17, 2018

@jfo
Copy link
Owner Author

jfo commented Feb 17, 2018

when run with our friend:

// err.zig

const std = @import("std");

pub fn main() !void {
    const allocator = std.debug.global_allocator;

    const args = try std.os.argsAlloc(allocator);
    defer std.os.argsFree(allocator, args);

    const count = try parseFile(allocator, args[1]);

    if (count < 10) return error.NotEnoughItems;
}

fn parseFile(allocator: &std.mem.Allocator, file_path: []const u8) !usize {
    const contents = std.io.readFileAlloc(allocator, file_path) catch return error.UnableToReadFile;
    defer allocator.free(contents);

    return contents.len;
}

looks something like

0   err                                 0x000000010514ce73 openSelfDebugInfo + 147
1   err                                 0x000000010514c346 getSelfDebugInfo + 150
2   err                                 0x000000010514bc79 dumpCurrentStackTrace + 169
3   err                                 0x000000010514b634 panic.6 + 212
4   err                                 0x000000010514b46b panic + 91
5   err                                 0x000000010515b13e main.0 + 446
6   err                                 0x000000010515ae59 callMain + 73
7   err                                 0x000000010515add9 callMainWithArgs + 361
8   err                                 0x000000010515ac64 main + 36
9   libdyld.dylib                       0x00007fff7af96115 start + 1
10  ???                                 0x0000000000000001 0x0 + 1

@jfo
Copy link
Owner Author

jfo commented Feb 17, 2018

@andrewrk
Copy link

We don't want to introduce a dependency on .h files and libc in the standard library.

What we can do is read the source for the code you're calling into and port it into zig

@jfo
Copy link
Owner Author

jfo commented Feb 17, 2018

Yes, I know that about the libc dep, hence the "just experimenting"

But, is this headed in the right direction?

@andrewrk
Copy link

I think that the existing dwarf code can actually support macos, but it incorrectly looks for it in its own binary, whereas in reality you have to find the object files and look there. I'd start with trying to figure out, perhaps by reading the implementation of the code you just called into, how to find the actual dwarf info

@jfo
Copy link
Owner Author

jfo commented Feb 17, 2018

❤️ SO

also

@andrewrk
Copy link

Yes I think these are the keys to doing it. cc @bnoordhuis are you still working on this?

@bnoordhuis
Copy link

Yes, but using the symtab segment from the image, not external dSYM data. It's less precise but at least it's always available. I'll try to PR it in the next few days.

@jfo jfo closed this Apr 10, 2018
jfo pushed a commit that referenced this pull request Aug 22, 2018
Sync with zig-lang/zig master
jfo pushed a commit that referenced this pull request Jan 11, 2019
Fix dirent/stat, add preadv
jfo pushed a commit that referenced this pull request Jul 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants