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

Generate debug info for LLDB/GDB #50

Merged
merged 3 commits into from
Mar 7, 2019

Conversation

yurydelendik
Copy link
Contributor

@yurydelendik yurydelendik commented Feb 7, 2019

  • Updates wasm2obj to embed .debug_XXX section into object file
  • Updates wasmtime:
    • to support JIT interface to GDB
    • generate proper information to work with LLDB

Example:

$ ../llvm-lldb/bin/lldb target/debug/wasmtime -- fib2.wasm --invoke=test
(lldb) b fib
(lldb) r
Process 53880 launched: 'wasmtime' (x86_64)
1 location added to breakpoint 1
Process 53880 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001019d3047 JIT(0x102856200)`fib(n=<unavailable>) at fib2.c:2:13
   1   	int fib(int n) {
-> 2   	  int i, t, a = 0, b = 1;
   3   	  for (i = 0; i < n; i++) {
   4   	    t = a;
   5   	    a = b;

See also parent #46

P.S. work towards https://yurydelendik.github.io/webassembly-dwarf/#aot-jit-compilers

@yurydelendik yurydelendik force-pushed the debug_line branch 2 times, most recently from a2da7fd to 92670c5 Compare February 8, 2019 19:39
@yurydelendik yurydelendik changed the title [WIP] Generate debug info for LLDB/GDB Generate debug info for LLDB/GDB Feb 8, 2019
Cargo.toml Outdated Show resolved Hide resolved

trait Reader: gimli::Reader<Offset = usize, Endian = LittleEndian> {}

impl<'input> Reader for gimli::EndianSlice<'input, LittleEndian> {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a new Reader trait instead of using gimli::Reader directly? To hide the associated types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it from gimli's examples/dwarfdump.rs -- it is the only syntax I could find atm

lib/debug/src/transform.rs Outdated Show resolved Hide resolved
@philipc
Copy link
Contributor

philipc commented Feb 15, 2019

Your method of transforming the line program is not what I expected. It looks like it is a 1-1 mapping of line program instructions, with the only transformation being for the address for each line program instruction. I don't know enough about cranelift to know if that is valid though. For example, can cranelift do optimizations (eg reorder/combining) that mean either

  • the transformed addresses are no longer monotonically increasing (we'll hit a panic in LineProgram::generate_row)
  • there isn't a transformed address (we'll hit a panic in AddrTransform::translate)

I was expecting you would need to generate a new line program, with the file/line information for each address being determined by looking up the srcloc in the original line program.

lib/debug/src/lib.rs Outdated Show resolved Hide resolved
@yurydelendik
Copy link
Contributor Author

Your method of transforming the line program is not what I expected. It looks like it is a 1-1 mapping of line program instructions, with the only transformation being for the address for each line program instruction.

I was expecting you would need to generate a new line program, with the file/line information for each address being determined by looking up the srcloc in the original line program.

You are correct. Currently I'm just trying to introduce the basics like JIT interface for LLDB, and then continue building on it. Anyway, I changed the logic in the .debug_line generation to be closer to what I planned.

@yurydelendik yurydelendik force-pushed the debug_line branch 2 times, most recently from 0c258b5 to 2ebc32a Compare February 22, 2019 17:08
Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

lib/debug/README.md Outdated Show resolved Hide resolved
lib/jit/src/compiler.rs Show resolved Hide resolved
lib/environ/src/compilation.rs Outdated Show resolved Hide resolved
lib/environ/src/cranelift.rs Outdated Show resolved Hide resolved
lib/environ/src/cranelift.rs Outdated Show resolved Hide resolved
lib/runtime/src/jit_int.rs Show resolved Hide resolved
lib/obj/src/context.rs Outdated Show resolved Hide resolved
lib/obj/src/context.rs Outdated Show resolved Hide resolved
lib/obj/src/context.rs Outdated Show resolved Hide resolved
lib/obj/Cargo.toml Outdated Show resolved Hide resolved
@yurydelendik yurydelendik force-pushed the debug_line branch 2 times, most recently from 8560f43 to 920d726 Compare March 4, 2019 14:34
Generate DWARF sections based on WASM DWARF.
Ignore some of debug_info/debug_line for dead code.
@sunfishcode
Copy link
Member

Ok great, let's land this and #59 now.

@sunfishcode sunfishcode merged commit ddbc007 into bytecodealliance:master Mar 7, 2019
@m4b
Copy link
Contributor

m4b commented Mar 8, 2019

Wanted to say this is really cool and exciting, great work !

@bjorn3
Copy link
Contributor

bjorn3 commented May 11, 2019

@yurydelendik how do you get this to work with lldb? When I ran lldb -- wasmtime -g ../../target/wasm32-unknown-wasi/release/rustc_binary.wasm example.rs the backtrace didn't have any symbols before wasmtime_call.

@yurydelendik
Copy link
Contributor Author

@yurydelendik how do you get this to work with lldb? When I ran lldb -- wasmtime -g ../../target/wasm32-unknown-wasi/release/rustc_binary.wasm example.rs the backtrace didn't have any symbols before wasmtime_call.

@bjorn3 https://gist.github.com/yurydelendik/4103d782dfc62634bc9f4de98de20835 has a log of running wasmtime w/lldb. (works on linux, and requires trunk lldb build + config on macos)

@bjorn3
Copy link
Contributor

bjorn3 commented May 13, 2019

requires trunk lldb build + config on macos

That seems to be the problem. I tried xcode lldb on macos. On linux it does work with lldb, but not with gdb.

grishasobol pushed a commit to grishasobol/wasmtime that referenced this pull request Nov 29, 2021
These limits seems to be picked arbitrary, and I just made it arbitrary larger.

We need to reconsider these limits, ideally providing to user a way to customize the limits.

FWIW, When the last time I've tried to run gcc's torture testsuite with wasmi it also bumped into this limit.

Fixes bytecodealliance#41.
howjmay pushed a commit to howjmay/wasmtime that referenced this pull request Jan 24, 2022
* Update for recent C API changes

Updating these bindings to account for bytecodealliance#2579

* Appease go vet
pchickey pushed a commit to pchickey/wasmtime that referenced this pull request May 12, 2023
* Implement file append functionality.

 - In the preview1-to-preview2 polyfill, using `append_via_stream`.
 - In the host implementation, using a new system-interface `FileIoExt::append` function.

* Add a basic testcase.
pchickey pushed a commit to pchickey/wasmtime that referenced this pull request May 16, 2023
* Implement file append functionality.

 - In the preview1-to-preview2 polyfill, using `append_via_stream`.
 - In the host implementation, using a new system-interface `FileIoExt::append` function.

* Add a basic testcase.
frank-emrich pushed a commit to frank-emrich/wasmtime that referenced this pull request Jul 19, 2023
dhil added a commit to dhil/wasmtime that referenced this pull request Nov 13, 2023
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.

6 participants