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

Start tracking the debug information origin for each instruction #67

Open
alexcrichton opened this issue Mar 14, 2019 · 5 comments
Open

Start tracking the debug information origin for each instruction #67

alexcrichton opened this issue Mar 14, 2019 · 5 comments
Labels

Comments

@alexcrichton
Copy link
Collaborator

@alexcrichton alexcrichton commented Mar 14, 2019

This is intended to be a tracking issue for now that's somewhat light on the details, but I wanted to make sure we had one tagged as sprint for our first 6 week sprint!

@fitzgen do you want to fill in some more particulars here?

@alexcrichton alexcrichton added the sprint label Mar 14, 2019
@fitzgen
Copy link
Member

@fitzgen fitzgen commented Mar 14, 2019

I'm imagining that each instruction would have something like this associated with it:

enum Whatever {
    NoDebugInfo,
    DebugInfoForFileOffset(u64),
    DebugInfo(DebugInfoId),
}

We would have methods for providing this info whenever creating new instructions.

The DebugInfoForFileOffset variant just keeps track of the instruction's (perhaps transitive) origin in an input wasm file.

As we emit wasm, we read the input DWARF and move from DebugInfoForFileOffset to the DebugInfo variant.

The gimli writer api already has arenas and ids, so we can either newtype all that stuff or just expose and use it directly.

This is all pretty half-baked. I also have been meaning to look closer at how llvm structure's its debug info APIs.

@oli-cosmian
Copy link

@oli-cosmian oli-cosmian commented Oct 1, 2020

I have started playing with walrus + DWARF and while I am now able to obtain the DWARF info for each InstrLocId, I still have to manually figure out the mapping between the DWARF offsets (with zero offset meaning the location where the function's body starts, so usually where its locals are defined) and the InstrLocId::data() which gives me the offset to the start of the wasm blob.

Is the idea to take the offset at the beginning of decoding a function and make the InstrLocId be relative to that? Or should we keep InstrLocId as it is and instead record the beginning byte offset and expose it so users of InstrLocId can compute the offset?

@d3lm
Copy link

@d3lm d3lm commented Oct 8, 2020

Are there any updates? I am curious to hear if this is moving forward and if we can soon start debugging Rust code in Chrome via DWARF debugging information.

@oli-cosmian
Copy link

@oli-cosmian oli-cosmian commented Oct 9, 2020

I'm still trying to figure out the base address so I can map DWARF offsets to instruction byte addresses. The problem I have is that I don't know enough about it all to be sure that there's always just one section in DWARF for wasm and consequently only one base address. I could just grab the base address by looking at the code section's base address? Or is that just true in my current setup?

I'm guessing, but https://webassembly.github.io/spec/core/binary/modules.html#binary-codesec isn't clear on that. I would think that there are multiple DWARF sections, one for each module's code section? Can there even be multiple modules in one .wasm file? Nothing in walrus' documentation hints at that being possible

@mitsuhiko
Copy link

@mitsuhiko mitsuhiko commented Nov 29, 2020

@oli-cosmian the "base address" within the WASM DWARF is basically 0. The offset of the code section is only added when addresses are used an the external interface.

So for instance 0x10 as address for a function in DWARF with the code section offset being 0x400 would be reported in stack traces as 0x410 by browser runtimes for instance. Multiple modules in one .wasm file would be impossible at least as far as DWARF is concerned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants