firedbg-rust-parser

Crates.iofiredbg-rust-parser
lib.rsfiredbg-rust-parser
version1.0.0
sourcesrc
created_at2023-12-08 16:53:36.784585
updated_at2023-12-08 16:53:36.784585
descriptionFireDBG Source Parser for Rust
homepagehttps://firedbg.sea-ql.org
repositoryhttps://github.com/SeaQL/FireDBG.for.Rust
max_upload_size
id1062235
size203,662
Chris Tsang (tyt2y3)

documentation

https://docs.rs/firedbg-rust-parser

README

FireDBG Source Parser for Rust

Based on syn.

firedbg-rust-parser is a Rust source code parser. It can parse a Rust source file, walk the abstract syntax tree of Rust, then produce a list of breakpoints for the debugger to pause the program at the beginning of every function call.

Walking the AST

We will walk the Rust AST, syn::Item, and collect all forms of function / method:

  1. Free standalone function, syn::Item::Fn
  2. Impl function, syn::Item::Impl
  3. Trait default function, syn::Item::Trait
  4. Impl trait function, syn::Item::Impl
  5. Nested function, walking the syn::Item recursively
  6. Function defined inside inline module, syn::Item::Mod

Breakable Span

A span is a region of source code, denoted by a ranged line and column number tuple, along with macro expansion information. It allows the debugger to set a breakpoint at the correct location. The debugger will set the breakpoint either at the start or the end of the breakable span.

fn func() -> i32 {
/*                ^-- Start of Breakable Span: (Line 1, Column 19)  */
    let mut i = 0;
/*  ^-- End of Breakable Span: (Line 3, Column 5)  */
    for _ in (1..10) {
        i += 1;
    }
    i
}

Ideas

The current implementation is rudimentary, but we get exactly what we need. We considered embedding Rust Analyzer, for a few advantages: 1) to get the fully-qualified type names 2) to traverse the static call graph. The problem is resource usage: we'd end up running the compiler frontend thrice (by cargo, by language server, by firedbg).

Commit count: 62

cargo fmt