Add --il-offset option to source command for IL offset resolution#323
Conversation
Add support for resolving method token + IL offset pairs (e.g., 0x6000001+0x5) to source file locations using PDB sequence points. This is useful when working with stacktraces from .NET runtimes that include IL offsets instead of line numbers (e.g., Tizen or environments without symbol files at runtime). Usage: dotnet inspect source --library MyApp.dll --il-offset 0x6000001+0x5 dotnet inspect source --platform System.Text.Json --il-offset 0x6000004+0x15 dotnet inspect source MyPackage --il-offset 0x6000002+0x1 --json Changes: - SourceLinkResolver: ResolveByILOffset() walks sequence points to find the best matching source line for a given IL offset. Works with and without SourceLink (falls back to file path + line only). - PdbContext/SourceLinkService: pass-through wrappers - SourceCommand: early branch in ExecuteAsync skips API extraction, parses token+offset format, validates MethodDef table, outputs in oneline/markdown/JSON - SourceILOffsetView: dedicated view model for markdown output - ILOffsetResult: JSON result type registered with source JSON contexts - Parser validates hex format and rejects non-MethodDef tokens Closes richlander#322 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thanks. Will take a look. |
|
Thanks for this — the feature works correctly end to end. I verified IL-offset resolution against PDB sequence points across exact, in-between, and boundary offsets, and the malformed/out-of-range token paths all fail gracefully. I pushed a small follow-up branch, 1. Dedup the resolver. 2. Tests for the walk. The parser was already covered, but the sequence-point resolution itself wasn't. Added I left the If it's easier than eyeballing the branch, you can pull the commit directly: |
Collapse the near-identical ResolveByILOffset / ResolveByILOffsetDirect methods into a single static sequence-point walk; the instance method now enriches the result with SourceLink URLs via `with`. Use !sp.IsHidden to match the rest of the file. Add ILOffsetResolutionTests covering the walk against a real PDB: exact sequence-point offsets, an in-between offset resolving to the preceding point, and the non-MethodDef / out-of-range null paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@richlander those changes make sense, I've pulled them in 🙂 |
|
I'll finish this up tomorrow. The rendering doesn't quite work the same as other commands. I already made some changes. I'll push those in the morning. |
|
The change: reshape the view to follow the
Source content is reserved for normal+, matching how Pushed to |
The IL-offset view emitted one frozen inline field block at every verbosity level, unlike the rest of the tool. Reshape it to follow the library-info view's discipline: -v:q → compact inline line (token + offsets only) -v:m → "Offset" section only -v:n+ → "Offset" + "Source" (resolved file/line/URL) sections No loose inline fields dangle above the sections. JSON and --oneline output are unchanged. Bump patch version to 0.7.11. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks! Published. |
Summary
Adds an
--il-offsetoption to thesourcecommand that resolves method token + IL offset pairs to source file locations using PDB sequence points.This is useful when working with stacktraces from .NET runtimes that include IL offsets instead of line numbers (e.g., Tizen, or environments where symbols aren't available at runtime). With
Switch.System.Diagnostics.StackTrace.ShowILOffsetsenabled, stacktraces include entries like:This option translates that token+offset into the actual source file and line number.
Usage
Implementation
SourceLinkResolver: NewResolveByILOffset()method walks PDB sequence points to find the best matching source line. Works with and without SourceLink (falls back to file path + line when no SourceLink URLs are available).SourceCommand: Early branch inExecuteAsyncskips API extraction (not needed — the token identifies the method directly). Parses and validates thetoken+offsethex format, rejecting non-MethodDef tokens.-v), and JSON (--json) output formats via a dedicatedSourceILOffsetViewandILOffsetResult.Closes #322