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

Debug location for char parameter emitted with DW_OP_piece 4, causes errors in GDB and Clang

Open dstenb opened this issue 2 years ago • 1 comments

LLVM commit: ef35da825f38a86e4621c13a2898d561da88991c

When compiling the following program:

int a, b;
void c(char d) { a = d & 5; }
void main() {
  unsigned long long e = b;
  c(e >> 48);
}

for i386 using:

clang -m32 -O3 -g foo.c

GDB 13.2 will emit an error when trying to print d:

(gdb) b c
Breakpoint 1 at 0x11e1: c. (2 locations)
(gdb) run
Starting program: foo.out 

Breakpoint 1.2, c (d=<error reading variable: access outside bounds of object referenced via synthetic pointer>) at reduce1.c:2
2  void c(char d) { a = d & 5; }

and LLDB from the same LLVM commit crashes:

(lldb) b c
Breakpoint 1: 2 locations.
(lldb) run
Process 164454 launched: 'foo.out' (i386)
lldb: /upstream/llvm-project/lldb/source/Expression/DWARFExpression.cpp:2192: static bool lldb_private::DWARFExpression::Evaluate(lldb_private::ExecutionContext *, lldb_private::RegisterContext *, lldb::ModuleSP, const
 lldb_private::DataExtractor &, const lldb_private::plugin::dwarf::DWARFUnit *, const lldb::RegisterKind, const lldb_private::Value *, const lldb_private::Value *, lldb_private::Value &, lldb_private::Status *): Assertion `ap_int.g
etBitWidth() >= bit_size' failed.
LLDB diagnostics will be written to /tmp/diagnostics-6d67d3
Please include the directory content when filing a bug report
Aborted (core dumped)

The DW_AT_location in question looks like:

0x00000096:       DW_TAG_formal_parameter
                    DW_AT_location      (indexed (0x1) loclist = 0x0000001e: 
                       [0x00001208, 0x0000120b): DW_OP_breg1 ECX+0, DW_OP_convert (0x00000027) "DW_ATE_unsigned_64", DW_OP_convert (0x0000002b) "DW_ATE_unsigned_8", DW_OP_stack_value, DW_OP_piece 0x4)
                    DW_AT_abstract_origin       (0x00000065 "d")

As seen, a 4-byte DW_OP_piece has been emitted for the 8-bit type, and applied to a DW_ATE_unsigned_8 converted value on the stack, which at least looks suspicious.

dstenb avatar Dec 12 '23 15:12 dstenb

@llvm/issue-subscribers-debuginfo

Author: David Stenberg (dstenb)

LLVM commit: ef35da825f38a86e4621c13a2898d561da88991c

When compiling the following program:

int a, b;
void c(char d) { a = d &amp; 5; }
void main() {
  unsigned long long e = b;
  c(e &gt;&gt; 48);
}

for i386 using:

clang -m32 -O3 -g foo.c

GDB 13.1 will emit an error when trying to print d:

(gdb) b c
Breakpoint 1 at 0x11e1: c. (2 locations)
(gdb) run
Starting program: foo.out 

Breakpoint 1.2, c (d=&lt;error reading variable: access outside bounds of object referenced via synthetic pointer&gt;) at reduce1.c:2
2  void c(char d) { a = d &amp; 5; }

and LLDB from same LLVM commit crashes:

(lldb) b c
Breakpoint 1: 2 locations.
(lldb) run
Process 164454 launched: 'foo.out' (i386)
lldb: /upstream/llvm-project/lldb/source/Expression/DWARFExpression.cpp:2192: static bool lldb_private::DWARFExpression::Evaluate(lldb_private::ExecutionContext *, lldb_private::RegisterContext *, lldb::ModuleSP, const
 lldb_private::DataExtractor &amp;, const lldb_private::plugin::dwarf::DWARFUnit *, const lldb::RegisterKind, const lldb_private::Value *, const lldb_private::Value *, lldb_private::Value &amp;, lldb_private::Status *): Assertion `ap_int.g
etBitWidth() &gt;= bit_size' failed.
LLDB diagnostics will be written to /tmp/diagnostics-6d67d3
Please include the directory content when filing a bug report
Aborted (core dumped)

The DW_AT_location in question looks like:

0x00000096:       DW_TAG_formal_parameter
                    DW_AT_location      (indexed (0x1) loclist = 0x0000001e: 
                       [0x00001208, 0x0000120b): DW_OP_breg1 ECX+0, DW_OP_convert (0x00000027) "DW_ATE_unsigned_64", DW_OP_convert (0x0000002b) "DW_ATE_unsigned_8", DW_OP_stack_value, DW_OP_piece 0x4)
                    DW_AT_abstract_origin       (0x00000065 "d")

As seen, a 4-byte DW_OP_piece has been emitted for the 8-bit type, and applied to a DW_ATE_unsigned_8 converted value on the stack, which at least looks suspicious.

llvmbot avatar Dec 12 '23 15:12 llvmbot