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

Location generation in debuginfo treats mangled names as short names #472

Open
tempdragon opened this issue Mar 15, 2024 · 3 comments
Open
Labels
libgccjit requires a change in libgccjit

Comments

@tempdragon
Copy link
Contributor

tempdragon commented Mar 15, 2024

Problems

Currently, at least for GDB, demangling for variable names and function names are not supported by the debuginfo generated in cg_gcc.

Causes

For the short test program, https://github.com/rust-lang/rustc_codegen_gcc/blob/b5d61f1c9e2177f66f2c80c63ced76d8cc66d3db/example/std_example.rs, cg_gcc-generated debuginfo, as is dumped by abi-dumper:
ABI_gcc.txt
While in LLVM:
ABI_llvm.txt
Upon inspection, it's evident that the current debuginfo generation treats mangled names as short names in the DWARF file.

Potential Solutions

Add a new function to generate a Location from mangled names and change the internal representation of Location in gccjit to allow storage of names as demangled ones.

@antoyo antoyo added the libgccjit requires a change in libgccjit label Mar 15, 2024
@antoyo
Copy link
Contributor

antoyo commented Mar 15, 2024

Is this something you want to investigate yourself or would you want me to look into how to do this in libgccjit?

@tempdragon
Copy link
Contributor Author

tempdragon commented Mar 15, 2024

Either is ok. If you are in a hurry(of solving this in 14 days), you can do it yourself.
I opened this to see if there are any other suggestions.
Oh, if I shouldn't even post this, please also tell me. Thanks!

@tempdragon
Copy link
Contributor Author

tempdragon commented Mar 21, 2024

As far as I know at this time, there are two ways of generating a (de)mangle-aware DWARF:

  1. By adding a duplicated DW_AT_linkage_name identical to DW_AT_name to DW_TAG_subprogram (rustc_codegen_cranelift)
  2. By adding a different linkage name, as is done in rustc_codegen_llvm

As is mentioned in rustc_codegen_cranelift/src/debuginfo/emit.rs, it is a MUST to have a linkage name in GDB, or the whole entry will be ignored.

In theory, the second one may result in a smaller size but seems harder to implement. However, in GCC, DW_AT_linkage is generated from DECL_ASSEMBLER_NAME with the prerequisite of NOT being identical to DECL_NAME which in turn becomes the DW_AT_name(as is called the "ShortName" sometimes), making it hard to generate without modifying the dwarf generation functions. Meanwhile, a short name will also require adding new structs and modifying the dwarf since the function names must NOT repeat.

It seems that I will have to modify the dwarf generation anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libgccjit requires a change in libgccjit
Projects
None yet
Development

No branches or pull requests

2 participants