rust-lang/rustc_codegen_gcc

Location generation in debuginfo treats mangled names as short names

tempdragon opened this issue · 3 comments

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.

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

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!

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.