llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[DWARF][DebugInfo] Missing variables due to clang setting type size to zero

Open OCHyams opened this issue 4 years ago • 3 comments

clang built with 968be05b8fdc1d23c055cc4963230a89efbc5967 (2022-01-12) Target: x86_64-unknown-linux-gnu

Clang sometimes emits DW_TAG_base_type DIEs with the attribute DW_AT_byte_size set to 0. This is observable when enabling DWARFv5 in the following reproducer. Look at the DIE for DW_ATE_unsigned_1 (0x00000023) which is used in the location expression for b (0x0000004e) as part of a conversion (DW_OP_convert).

$ cat ex.cpp
__attribute__((optnone))
void ext(bool) {}
__attribute__((noinline))
void fun(bool b) {
  ext(b);
}
int main() {
  fun(true);
  return 0;
}


$ clang -c -O2 -gdwarf-5 ex.cpp -o ex.o
$ llvm-dwarfdump test.o
0x00000023:   DW_TAG_base_type
                DW_AT_name	("DW_ATE_unsigned_1")
                DW_AT_encoding	(DW_ATE_unsigned)
                DW_AT_byte_size	(0x00)

0x00000027:   DW_TAG_base_type
                DW_AT_name	("DW_ATE_unsigned_8")
                DW_AT_encoding	(DW_ATE_unsigned)
                DW_AT_byte_size	(0x01)
<snip>
0x00000042:   DW_TAG_subprogram
                DW_AT_low_pc	(0x00000000004004b0)
                DW_AT_high_pc	(0x00000000004004b5)
                DW_AT_frame_base	(DW_OP_reg7 RSP)
                DW_AT_call_all_calls	(true)
                DW_AT_linkage_name	("_Z3funb")
                DW_AT_name	("fun")
                DW_AT_decl_file	("/home/och/dev/bugs/scratch/ex.cpp")
                DW_AT_decl_line	(4)
                DW_AT_external	(true)

0x0000004e:     DW_TAG_formal_parameter
                  DW_AT_location	(DW_OP_breg5 RDI+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_convert (0x00000023) "DW_ATE_unsigned_1", DW_OP_convert (0x00000027) "DW_ATE_unsigned_8", DW_OP_stack_value)
                  DW_AT_name	("b")
                  DW_AT_decl_file	("/home/och/dev/bugs/scratch/ex.cpp")
                  DW_AT_decl_line	(4)
                  DW_AT_type	(0x0000009a "bool")

lldb says the variable is unavailable and helpfully reports "Unsupported type size in DW_OP_convert":

__attribute__((optnone))
void ext(bool) {}
__attribute__((noinline))
void fun(bool b) {
  ext(b);
}
int main() {
  fun(true);
  return 0;
}

$ clang -O2 -gdwarf-5 ex.cpp -o ex
$ lldb ex
~/dev/bugs/scratch$ lldb ex
(lldb) target create "ex"
Current executable set to '/home/och/dev/bugs/scratch/ex' (x86_64).
(lldb) b fun
Breakpoint 1: where = ex`fun(bool) at ex.cpp:5:3, address = 0x00000000004004b0
(lldb) run
Process 6295 launched: '/home/och/dev/bugs/scratch/ex' (x86_64)
Process 6295 stopped
* thread #1, name = 'ex', stop reason = breakpoint 1.1
    frame #0: 0x00000000004004b0 ex`fun(b=<unavailable>) at ex.cpp:5:3
   2   	void ext(bool) {}
   3   	__attribute__((noinline))
   4   	void fun(bool b) {
-> 5   	  ext(b);
   6   	}
   7   	int main() {
   8   	  fun(true);
(lldb) p b
error: Couldn't materialize: couldn't get the value of variable b: Unsupported type size in DW_OP_convert

OCHyams avatar Jan 12 '22 16:01 OCHyams

@llvm/issue-subscribers-debuginfo

llvmbot avatar Jan 12 '22 16:01 llvmbot

I've put a patch up for review here https://reviews.llvm.org/D117124.

OCHyams avatar Jan 12 '22 16:01 OCHyams

That landed in b6a41fddcfd375ce30487ef87ca2cd65a6be0bcc. Closing this ticket.

OCHyams avatar Jan 21 '22 14:01 OCHyams