Skip to content

Addr2line enhance 5#4977

Open
TianlongLiang wants to merge 8 commits into
bytecodealliance:mainfrom
TianlongLiang:addr2line_enhance_5
Open

Addr2line enhance 5#4977
TianlongLiang wants to merge 8 commits into
bytecodealliance:mainfrom
TianlongLiang:addr2line_enhance_5

Conversation

@TianlongLiang

Copy link
Copy Markdown
Contributor

No description provided.

…lver

Refactor the wasm symbolicator to make its toolchain workarounds
explicit. addr2line.py now detects the wasi-sdk's clang major version
at startup and routes per-frame address resolution to one of:

- resolve_address_modern (clang >= 22, wasi-sdk 33+):
    single llvm-symbolizer call per address. The symbolizer handles
    address-to-name correctly on this clang.

- resolve_address_legacy (clang < 22 or unknown):
    llvm-symbolizer call + llvm-dwarfdump --lookup overlay to fix
    the outermost function name. Older clang versions emit wasm DWARF
    that confuses llvm-symbolizer's address-to-name resolver for some
    addresses (e.g., reports 'recurse' as 'free'). --lookup goes
    through a different DWARF traversal path that handles them.

The dispatch decision is logged once to stderr so users can see
which path was taken without polluting stdout. Stdout is byte-
identical between paths for non-buggy inputs.

Also includes accumulated improvements:
- --mode flag {interp,aot,fast-interp} for different runtime offset
  conventions (interp post-advance, aot at-instruction-start,
  fast-interp's transformed in-memory bytecode)
- Inline frame annotation "(inlined into <next>)" for clarity
- llvm-symbolizer preferred over llvm-addr2line for column info
- Fallback for offset=0 (trap at function entry; frame_ip not captured)
- Last-resort function-index name fallback when DWARF lacks PC ranges
- README: document the --mode flag, inline expansion behavior, and the
  modern/legacy resolver split. Link to the test suite under
  test-tools/addr2line/tests/ for the LLVM-bug rationale.
- symbolicate.sh: pass --mode aot for the AOT call-stack invocation.
- verify.sh (new): assertion-based smoke test that runs the existing
  symbolicate.sh and grep-checks for inline expansion (trap_helper)
  in both the wasm and AOT outputs. Replaces the inline assertions
  the CI step previously carried.
- wasm-apps/trap.c: add a trap_helper marked __attribute__((always_inline))
  that the trap site falls inside, so addr2line.py can demonstrate
  inline-frame annotation against this sample.

Depends on the addr2line.py refactor (--mode flag, modern/legacy split).
New self-contained sample demonstrating the full production-debug
workflow for optimized WASM:

- 4-step build pipeline (clang -Oz -g -flto, wasm-opt -Oz -g, llvm-strip
  --strip-all, wamrc) producing prod.wasm + prod.aot + debug.wasm
  companion artifacts.
- Two test apps (oob, stackoverflow) split into multi-file C sources
  to exercise cross-TU LTO inlining.
- USE_FAST_INTERP CMake option to build iwasm in classic or fast-interp
  mode for testing.
- symbolicate.sh: end-to-end driver that runs iwasm on the prod binary,
  captures the call stack, and resolves it via addr2line.py + the
  debug companion. Auto-detects classic vs fast-interp from the iwasm
  binary.
- verify.sh: per-(app, mode) assertion that the symbolicated output
  contains the expected source files. Used by CI.

Depends on the addr2line.py refactor (--mode flag is invoked from
symbolicate.sh).
New test suite at test-tools/addr2line/tests/ exercising addr2line.py
against purpose-built C/C++ sources covering:

- Baseline single-function resolution
- Inline expansion (always_inline, 4-level deep chain)
- Cross-TU LTO inlining (multi-file recursion + wasm-opt -Oz -g)
- Trap inside loop body (DWARF line-table edge case)
- Multi-frame call stack
- C++ symbol demangling
- AOT mode offset math
- fast-interp / --no-addr fallbacks
- offset=0 fallback (trap at function entry)
- Empty input
- Version-dispatch stderr message
- Multi-SDK legacy/modern equivalence (opt-in via --multi-sdk)

Layout:
  test-tools/addr2line/tests/
  ├── README.md              -- documentation
  ├── conftest.py            -- pytest fixtures (sdk discovery, build,
  │                            run_addr2line invocation, multi-sdk
  │                            parametrization)
  ├── test_addr2line.py      -- 14 test cases
  ├── pytest.ini             -- marker definitions (slow, multi_sdk)
  ├── run_tests.sh           -- thin pytest wrapper
  ├── apps/                  -- 8 purpose-built C/C++ sources
  └── fixtures/              -- 3 plaintext call-stack inputs

Sources under apps/ are NOT copied from samples/; they target specific
edge cases independent of sample evolution.

Depends on the addr2line.py refactor (test_dispatch_message_in_stderr
checks the modern/legacy stderr message; test_modern_legacy_equivalence
verifies both paths agree on output).
compilation_on_android_ubuntu.yml:
- Existing build_samples_others step (debug-tools) now calls verify.sh
  instead of inline grep assertions.
- New build_samples_debug_tools_optimized job: builds the new sample
  twice (classic-interp and fast-interp via -DUSE_FAST_INTERP=ON) and
  runs verify.sh oob/stackoverflow x wasm/aot for each build.
- New addr2line_tests job: runs the pytest suite at
  test-tools/addr2line/tests/ against the default wasi-sdk on every PR.

nightly_run.yml:
- New addr2line_tests_multi_sdk job: installs wasi-sdk 29.0 (legacy
  path, clang 21.x) and 33.0 (modern path, clang 22.x) side by side
  and runs the test suite with --multi-sdk to exercise both code paths
  and validate test_modern_legacy_equivalence.

Depends on:
- the addr2line.py refactor (per-PR job runs the test suite)
- samples/debug-tools refresh (existing sample CI step now calls verify.sh)
- samples/debug-tools-optimized (new job builds and tests it)
- the pytest suite (new jobs invoke pytest)
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.

1 participant