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

Get location info from function indexes in addr2line script #3206

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

eloparco
Copy link
Contributor

@eloparco eloparco commented Mar 6, 2024

Updating the addr2line script so that:

  • line info is printed in a more convenient format, e.g.
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12

similar to how Rust prints stack traces when there's a panic. In an IDE, the user can conveniently click on the printed path and be redirected to the file line.

  • a new --no-addr argument can be provided to the script

It can be used in fast interpreter mode (that is not supported by the script otherwise) or with older wamr versions (where the stack trace only had the function index info and not the function address). In that case, wasm-objdump is used to get the function name from the index and llvm-dwarfdump to obtain the location info (where the line refers to the start of the function).

@eloparco
Copy link
Contributor Author

eloparco commented Mar 6, 2024

Tested with a few simple examples:

int
c(int n)
{
    __builtin_trap();
}

int
b(int n)
{
    n += 3;
    return c(n);
}

int
a(int n)
{
    return b(n);
}

int
main(int argc, char **argv)
{
    int i = 5;
    a(i);

    return 0;
}
fn c(_: i32) -> i32 {
    panic!("this is a panic!");
}

fn b(mut n: i32) -> i32 {
    n += 3;
    c(n)
}

fn a(n: i32) -> i32 {
    b(n)
}

fn main() {
    let i = 5;
    a(i);
}

If I want to run it in CI, should I add a new folder in samples with a program that crashes (as above)? Or should I use test-tools/addr2line?

print(line)
_, offset, index = splitted
if not index.startswith("$f"):
print(f"{i}: {index}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

wondering what kind of case it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That happens with _start

#00: 0x0159 - $f5
#01: 0x01b2 - $f6
#02: 0x0200 - $f7
#03: 0x026b - $f8
#04: 0x236b - $f15
#05: 0x011f - _start

I added a comment in the code.

location = line
return (function_name, location)
if "DW_AT_decl_line" in line:
function_line = get_dwarf_tag_value("DW_AT_decl_line", line)
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicated with L154 and L155 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? L154-155 are for the file, L157-158 for the line

@wenyongh
Copy link
Contributor

wenyongh commented Mar 7, 2024

Tested with a few simple examples:

int
c(int n)
{
    __builtin_trap();
}

int
b(int n)
{
    n += 3;
    return c(n);
}

int
a(int n)
{
    return b(n);
}

int
main(int argc, char **argv)
{
    int i = 5;
    a(i);

    return 0;
}
fn c(_: i32) -> i32 {
    panic!("this is a panic!");
}

fn b(mut n: i32) -> i32 {
    n += 3;
    c(n)
}

fn a(n: i32) -> i32 {
    b(n)
}

fn main() {
    let i = 5;
    a(i);
}

If I want to run it in CI, should I add a new folder in samples with a program that crashes (as above)? Or should I use test-tools/addr2line?

@eloparco how about creating a new folder under samples, so it not only tests the tool but also shows the usage for the developers.

@eloparco
Copy link
Contributor Author

eloparco commented Mar 7, 2024

@eloparco how about creating a new folder under samples, so it not only tests the tool but also shows the usage for the developers.

That's what I had in mind as well, added it.

When I use AOT, the first stack frame address seems to be incorrect:

#00: 0x0000 - $f5
#01: 0x01ac - $f6
#02: 0x01fa - $f7
#03: 0x0265 - $f8
#04: 0x2365 - $f15
#05: 0x0119 - _start

I'm compiling with --enable-dump-call-stack. And added --size-level=0 as well to avoid problems on mac M1 (that I'm using for testing).

@eloparco eloparco force-pushed the eloparco/extend-addr2line branch 3 times, most recently from cbb4d81 to 68fba3f Compare March 7, 2024 17:04
Copy link
Contributor

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

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

LGTM

@lum1n0us
Copy link
Collaborator

lum1n0us commented Mar 8, 2024

LGTM

@wenyongh wenyongh merged commit 0e4c479 into bytecodealliance:main Mar 8, 2024
399 checks passed
@eloparco
Copy link
Contributor Author

eloparco commented Mar 8, 2024

When I use AOT, the first stack frame address seems to be incorrect:

@wenyongh @lum1n0us any ideas about this one? Opened an issue #3212

@wenyongh
Copy link
Contributor

wenyongh commented Mar 9, 2024

@eloparco please try #3213.

wenyongh pushed a commit that referenced this pull request Mar 11, 2024
…3211)

Last bit missing from #3206: demangling of function names (useful for wasm
generated from Rust for instance) using `llvm-cxxfilt`.

Before this PR:
```text
0: abort
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/panic_abort/src/lib.rs:85
1: _ZN3std3sys4wasi14abort_internal17h50698daab05bf73bE
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/wasi/mod.rs:181
2: _ZN3std7process5abort17h6bc522b6749f17cfE
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/process.rs:2278
3: _ZN3std5alloc8rust_oom17h452ad5ba6cebff96E
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/alloc.rs:364
```

After:
```text
0: abort
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/panic_abort/src/lib.rs:85
1: std::sys::wasi::abort_internal::h50698daab05bf73b
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/wasi/mod.rs:181
2: std::process::abort::h6bc522b6749f17cf
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/process.rs:2278
3: std::alloc::rust_oom::h452ad5ba6cebff96
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/alloc.rs:364
```
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 1, 2024
…alliance#3206)

Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 2, 2024
…alliance#3206)

Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…alliance#3206)

Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script 

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…ytecodealliance#3211)

Last bit missing from bytecodealliance#3206: demangling of function names (useful for wasm
generated from Rust for instance) using `llvm-cxxfilt`.

Before this PR:
```text
0: abort
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/panic_abort/src/lib.rs:85
1: _ZN3std3sys4wasi14abort_internal17h50698daab05bf73bE
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/wasi/mod.rs:181
2: _ZN3std7process5abort17h6bc522b6749f17cfE
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/process.rs:2278
3: _ZN3std5alloc8rust_oom17h452ad5ba6cebff96E
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/alloc.rs:364
```

After:
```text
0: abort
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/panic_abort/src/lib.rs:85
1: std::sys::wasi::abort_internal::h50698daab05bf73b
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/wasi/mod.rs:181
2: std::process::abort::h6bc522b6749f17cf
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/process.rs:2278
3: std::alloc::rust_oom::h452ad5ba6cebff96
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/alloc.rs:364
```
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…alliance#3206)

Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…alliance#3206)

Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request Jun 7, 2024
…alliance#3206)

Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
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.

None yet

3 participants