dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.4k stars 196 forks source link

[NativeAOT-LLVM] WASM debugging #2408

Open SingleAccretion opened 11 months ago

SingleAccretion commented 11 months ago

Currently, we emit basic DWARF information and our target debuggers (LLDB and the DevTools extension) are more or less able to consume it.

We should do much more. WASM debugging story is somewhat infamously lacking in a number of areas, so a lot of this issue will be about upstream (but not necessarily /runtime) work. Note as well that this issue is about native debugging. If/when NAOT gets investment in the direction of managed debugging, that I am sure will have rather separate concerns.

But first, some obvious things we need to address on our side: 1) Add debugging tests. 2) Emit DWARF for funclets so that they can be stepped through. 3) Emit DWARF for statics so that they can be inspected.

In parallel, we should pursue improvements to the overall ecosystem with the following end goal: it is possible to produce highly optimized WASM with a separate debug info file, which could be used to debug rich WASM core dump files. Basically, parity with other native experiences.

The exact work items in this direction are TBD, but the first problem to solve is the "optimized" part. As https://github.com/dotnet/runtimelab/issues/2357#issuecomment-1661108919 shows, currently, debug must be dropped if you do not want to give up on shrinking relocations (essentially, a post-link optimization). DWARF is a fragile format as it operates on exact offsets within functions for things like location lists, which is not terribly compatible with post-link optimizations. Current solutions in tools like wasm-opt employ expensive DWARF parsing and writeback to solve this. The task here is to design a scheme that would allow for relocation shrinking in the linker at a lower cost (both in terms of performance and complexity).

SingleAccretion commented 7 months ago

Ref: https://github.com/llvm/llvm-project/pull/77949.

Ref: https://llvm.org/docs/CommandGuide/llvm-debuginfo-analyzer.html. Ref: https://github.com/llvm/llvm-project/pull/82588