Skip to content

Add DWARF line table parser for source-level backtraces#329

Open
pcbeard wants to merge 5 commits into
swiftwasm:mainfrom
pcbeard:DwarfLineTableParser
Open

Add DWARF line table parser for source-level backtraces#329
pcbeard wants to merge 5 commits into
swiftwasm:mainfrom
pcbeard:DwarfLineTableParser

Conversation

@pcbeard

@pcbeard pcbeard commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Parse DWARF .debug_line, .debug_info, .debug_abbrev, and .debug_ranges sections from WASM custom sections to resolve code addresses to source file/line/column locations. Used by Caller.captureBacktrace() to provide source-level information in stack traces.

Key components:

  • DWARFLineTable: parses DWARF v4/v5 line number programs with CU-aware resolution using .debug_info address ranges
  • Code section offset conversion between file-level and DWARF addresses
  • binaryOffsetCorrection in Translator to fix buffer-relative offsets
  • Backtrace.Symbol.sourceLocation for resolved source locations
  • Precise line resolution via instruction mapping with function-start fallback
  • Translator fix from expose-debugging-api for folded instruction mapping
  • codeSectionStart exposed via ParsingPayload.codeSection
  • 13 unit tests for the DWARF parser

Parse DWARF .debug_line, .debug_info, .debug_abbrev, and .debug_ranges
sections from WASM custom sections to resolve code addresses to source
file/line/column locations. Used by Caller.captureBacktrace() to provide
source-level information in stack traces.

Key components:
- DWARFLineTable: parses DWARF v4/v5 line number programs with CU-aware
  resolution using .debug_info address ranges
- Code section offset conversion between file-level and DWARF addresses
- binaryOffsetCorrection in Translator to fix buffer-relative offsets
- Backtrace.Symbol.sourceLocation for resolved source locations
- Precise line resolution via instruction mapping with function-start fallback
- Translator fix from expose-debugging-api for folded instruction mapping
- codeSectionStart exposed via ParsingPayload.codeSection
- 13 unit tests for the DWARF parser

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's ongoing work on offline symbolication for Swift on other platforms. If we could agree on a format that WasmKit outputs, maybe the symbolicator could accept that and we wouldn't need DWARF parsing in WasmKit at all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could be optional of course, but handy during debugging. Still need something to decode the translated PC values to correct offsets that can be used offline. I don't believe the current PC values would work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be happy to adjust values to whatever symbolicator is expecting. Probably also need to align WasmKit with output from other Wasm runtimes so that the symbolicator can expect consistent input.

@pcbeard

pcbeard commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

Looking at the failing unit tests now.

@pcbeard
pcbeard requested a review from MaxDesiatov March 12, 2026 03:05
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.

2 participants