Skip to content

Conversation

kehrazy
Copy link
Contributor

@kehrazy kehrazy commented Sep 21, 2025

Fixes #1528

  • honour the session DWARF version, enabling v5 when embed-source is requested and plumb the flag through the debug context
  • attach embedded source bytes to line table FileInfo records alongside existing MD5 hashes
  • stop excluding rustc’s embed-source-dwarf run-make test so CG_CLIF exercises the feature

@bjorn3
Copy link
Member

bjorn3 commented Sep 21, 2025

Thanks for working on this!

@bjorn3
Copy link
Member

bjorn3 commented Sep 22, 2025

Unrelated to this PR, but while trying to test this PR I noticed that with DWARFv5 anonymous sources get invalid file names. They are supposed to be called <anon>, but get called /path/to/working_directory/<anon> instead by gdb. By the way do you know of any debugger that already supports this? Even the gdb of Fedora Rawhide doesn't seem to support it.

@kehrazy
Copy link
Contributor Author

kehrazy commented Sep 22, 2025

Unrelated to this PR, but while trying to test this PR I noticed that with DWARFv5 anonymous sources get invalid file names. They are supposed to be called <anon>, but get called /path/to/working_directory/<anon> instead by gdb.

The fix might be FileName::prefer_remapped_unconditionally - internal files and all that.

How do you check the output? With what RUSTFLAGS do you compile a binary? Can you give me a repro?

@bjorn3
Copy link
Member

bjorn3 commented Sep 22, 2025

I used dist/rustc-clif -g -Zdwarf-version=5 -Zembed-source foo.rs and then removing foo.rs for trying to test -Zembed-source.

echo 'fn main() {}' | dist/rustc-clif -g -Zdwarf-version=5 - reproduces the <anon> issue.

  - honour the session DWARF version, enabling v5 when embed-source is requested and plumb the flag through the debug context
  - attach embedded source bytes to line table FileInfo records alongside existing MD5 hashes
  - stop excluding rustc’s embed-source-dwarf run-make test so CG_CLIF exercises the feature
@kehrazy
Copy link
Contributor Author

kehrazy commented Sep 22, 2025

both GDB and LLDB seem to not have DWARFv5 embedded source support :/

When using

echo 'fn main() {}' | ./dist/rustc-clif -g -Zdwarf-version=5 - 2>&1
echo 'int main() { return 0; }' | gcc -x c -gdwarf-5 - -o gcc_test

echo "y" | gdb -batch -ex "file rust_out" -ex "b main" -ex "list" 2>&1 | tail -1`
echo "y" | gdb -batch -ex "file gcc_test" -ex "b main" -ex "list" 2>&1 | tail -1

(after the latest change) I get:

warning: 1      <anon>: No such file or directory
warning: 1      <stdin>: No such file or directory

which looks okay!

@kehrazy
Copy link
Contributor Author

kehrazy commented Sep 22, 2025

which looks okay!

I really hate this solution, though, and I think it should be reverted - I can't seem to find a better approach here.

@bjorn3
Copy link
Member

bjorn3 commented Sep 25, 2025

This is what cg_llvm does for determining the file name: https://github.com/rust-lang/rust/blob/caccb4d0368bd918ef6668af8e13834d07040417/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L552-L648 It should be lifted into cg_ssa at some point, but for now what you have LGTM. Thanks!

@bjorn3 bjorn3 merged commit 6f8394e into rust-lang:main Sep 25, 2025
22 checks passed
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.

Implement -Zembed-source
2 participants