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

Limited source mapping information in compiler debug output #6922

Closed
JoshuaBatty opened this issue Feb 11, 2025 · 2 comments
Closed

Limited source mapping information in compiler debug output #6922

JoshuaBatty opened this issue Feb 11, 2025 · 2 comments
Assignees
Labels
compiler:debug-info Debug Info support in the compiler team:compiler Compiler Team

Comments

@JoshuaBatty
Copy link
Member

JoshuaBatty commented Feb 11, 2025

I'm currently trying to implement source <-> bytecode mapping for compiler-explorer integration and noticed that the generated debug info (both DWARF and json) is quite limited. This is calling the debug build with forc build using OptLevel::Opt0.

For example:

script;

fn get_num() -> u64 {
    5
}

fn main() {
    let x = 5;
    let y = get_num();
    let res = x + y;
}

The generated symbols.json only contains mappings for the main function entry point:

{
  "paths": [...],
  "map": {
    "58": {"path": 1, "range": {"start": {"line": 7, "col": 1}, "end": {"line": 11,"col": 2}}},
    "59": {"path": 1, "range": {"start": {"line": 7, "col": 1}, "end": {"line": 11,"col": 2}}}
  }
}

DWARF output shows the same limited info:

Address            Line   Column File   ISA Discriminator Flags
------------------ ------ ------ ------ --- ------------- -------------
0x000000000000003a      7      1      2   0             0  is_stmt
0x000000000000003c      7      1      2   0             0  is_stmt end_sequence

Looking at the bytecode, we have operations like ADD, MOVE etc that should map to specific source locations (e.g. res = x + y on line 10), but these mappings are missing. This seems to be because many AllocatedOps aren't getting their owning_span populated which is required for them to be inserted into the sourcemap.

if let Some(span) = &span {
    source_map.insert(source_engine, half_word_ix, span);
}
@JoshuaBatty JoshuaBatty added compiler:debug-info Debug Info support in the compiler team:compiler Compiler Team labels Feb 11, 2025
@vaivaswatha
Copy link
Contributor

See #5511 (comment). Even at -O0, we remove some dead code, and that's why res here (and consequently x and y) get eliminated, thus not seen in the output. If you return res from main, you should see the instructions as well as its debug info.

@IGI-111
Copy link
Contributor

IGI-111 commented Feb 14, 2025

I'll close this since it seems to be working as intended, feel free to reopen if there's more to do here @JoshuaBatty

@IGI-111 IGI-111 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:debug-info Debug Info support in the compiler team:compiler Compiler Team
Projects
None yet
Development

No branches or pull requests

3 participants