debugging icon indicating copy to clipboard operation
debugging copied to clipboard

Native DWARF Debugging Workaround

Open ErikMcClure opened this issue 5 years ago • 1 comments

As discussed at the February in-person meeting, I have been trying to implement translating WebAssembly DWARF to native DWARF debugging that can be used by a debugger like GDB to accurately step through and display the contents of variables.

This is problematic, because some implementations have relocatable linear memory sections, which means the value in memory after compilation is not an actual pointer. Instead, it is an offset from the linear memory section pointer, which must be looked up. This requires accessing a global variable from a DWARF expression using DW_OP_addr, but LLVM does not seem to allow this.

If it were possible to emit DW_OP_addr, then one could construct a workaround by replacing pointers with structs that have a custom member offset. wasmtime says they have managed to do this, but their debugging code doesn't actually seem to use LLVM to emit DWARF information. If they are bypassing LLVM, it would explain how they were able to use DW_OP_addr, and reinforces the need to update LLVM to support this use-case.

If it is possible to convince LLVM to emit the necessary DWARF expressions, I am eager to know how to achieve this. Otherwise I'd like to open a feature request in LLVM to support emitting them.

ErikMcClure avatar Feb 24 '20 09:02 ErikMcClure

This requires accessing a global variable from a DWARF expression using DW_OP_addr, but LLVM does not seem to allow this.

Accessing a location of a global variable requires VM/Runtime context (at least for wasmtime). It is somewhat similar to TLS in native representation. Shall we treat it as a such? Ideally the memory locations have to resolved in relation to the context as well. In wasmtime, we are counting on the VM context to resolve pointers.

I see there is some of DW_OP_form_tls_address support in LLVM -- it is possible to utilize that.

If it is possible to convince LLVM to emit the necessary DWARF expressions

There is wasm-global <index> in Wasm DWARF for globals locations in DWARF expressions. We need to implement that in LLVM, at least for data locations so they will be properly transformed to native DWARF locations.

yurydelendik avatar Feb 24 '20 16:02 yurydelendik