[DebugInfo] Add a DW_OP_LLVM_entry_value operation
Summary:
Internally in LLVM's metadata we use DW_OP_entry_value operations with
the same semantics as DWARF; that is, its operand specifies the number
of bytes that the entry value covers.
At the time of emitting entry values we don't know the emitted size of
the DWARF expression that the entry value will cover. Currently the size
is hardcoded to 1 in DIExpression, and other values causes the verifier
to fail. As the size is 1, that effectively means that we can only have
valid entry values for registers that can be encoded in one byte, which
are the registers with DWARF numbers 0 to 31 (as they can be encoded as
single-byte DW_OP_reg0..DW_OP_reg31 rather than a multi-byte
DW_OP_regx). It is a bit confusing, but it seems like llvm-dwarfdump
will print an operation "correctly", even if the byte size is less than
that, which may make it seem that we emit correct DWARF for registers
with DWARF numbers > 31. If you instead use readelf for such cases, it
will interpret the number of specified bytes as a DWARF expression. This
seems like a limitation in llvm-dwarfdump.
As suggested in D66746, a way forward would be to add an internal
variant of DW_OP_entry_value, DW_OP_LLVM_entry_value, whose operand
instead specifies the number of operations that the entry value covers,
and we then translate that into the byte size at the time of emission.
In this patch that internal operation is added. This patch keeps the
limitation that a entry value can only be applied to simple register
locations, but it will fix the issue with the size operand being
incorrect for DWARF numbers > 31.
Reviewers: aprantl, vsk, djtodoro, NikolaPrica
Reviewed By: aprantl
Subscribers: jyknight, fedor.sergeev, hiraditya, llvm-commits
Tags: #debug-info, #llvm
Differential Revision: https://reviews.llvm.org/D67492
llvm-svn: 374881
2019-10-15 19:31:21 +08:00
; RUN: llc -debug-entry-values -filetype=asm -o - %s | FileCheck %s
; Verify that the entry value covers both of the DW_OP_regx pieces. Previously
; the size operand of the entry value would be hardcoded to one.
;
; XXX: Is this really what should be emitted, or should we instead emit one
; entry value operation per DW_OP_regx? GDB can currently not understand
; entry values containing complex expressions like this.
target datalayout = "E-m:e-i64:64-n32:64-S128"
target triple = "sparc64"
; Based on the following C reproducer:
;
; volatile long double global;
; extern void clobber();
; int foo(long double p) {
; global = p;
; clobber();
; return 123;
; }
; CHECK: .byte 243 ! DW_OP_GNU_entry_value
; CHECK-NEXT: .byte 8 ! 8
; CHECK-NEXT: .byte 144 ! sub-register DW_OP_regx
; CHECK-NEXT: .byte 72 ! 72
; CHECK-NEXT: .byte 147 ! DW_OP_piece
; CHECK-NEXT: .byte 8 ! 8
; CHECK-NEXT: .byte 144 ! sub-register DW_OP_regx
; CHECK-NEXT: .byte 73 ! 73
; CHECK-NEXT: .byte 147 ! DW_OP_piece
; CHECK-NEXT: .byte 8 ! 8
; CHECK-NEXT: .byte 159 ! DW_OP_stack_value
@global = common global fp128 0 x L 00000000000000000000000000000000 , align 16 , !dbg !0
; Function Attrs: nounwind
define signext i32 @foo ( fp128 %p ) #0 !dbg !12 {
entry:
call void @llvm.dbg.value ( metadata fp128 %p , metadata !17 , metadata !DIExpression ( ) ) , !dbg !18
store volatile fp128 %p , fp128 * @global , align 16 , !dbg !19
tail call void @clobber ( ) , !dbg !20
ret i32 123 , !dbg !21
}
declare void @clobber ( )
; Function Attrs: nounwind readnone speculatable willreturn
declare void @llvm.dbg.value ( metadata , metadata , metadata ) #1
attributes #0 = { nounwind }
attributes #1 = { nounwind readnone s p e c u l a t a b l e w i l l r e t u r n }
!llvm.dbg.cu = ! { !2 }
!llvm.module.flags = ! { !8 , !9 , !10 }
!llvm.ident = ! { !11 }
!0 = !DIGlobalVariableExpression ( var: !1 , expr: !DIExpression ( ) )
!1 = distinct !DIGlobalVariable ( name: "global" , scope: !2 , file: !3 , line: 1 , type: !6 , isLocal: false , isDefinition: true )
!2 = distinct !DICompileUnit ( language: D W _ L A N G _ C 99 , file: !3 , producer: "clang version 10.0.0" , isOptimized: true , runtimeVersion: 0 , emissionKind: F u l l D e b u g , enums: !4 , globals: !5 , nameTableKind: N one )
!3 = !DIFile ( filename: "entry-value-complex-reg-expr.c" , directory: "/" )
!4 = ! { }
!5 = ! { !0 }
!6 = !DIDerivedType ( tag: D W _ T A G _ v o l a t i l e _ type , baseType: !7 )
!7 = !DIBasicType ( name: "long double" , size: 128 , encoding: D W _ A T E _ float )
!8 = ! { i32 2 , !"Dwarf Version" , i32 4 }
!9 = ! { i32 2 , !"Debug Info Version" , i32 3 }
!10 = ! { i32 1 , !"wchar_size" , i32 4 }
!11 = ! { !"clang version 10.0.0" }
!12 = distinct !DISubprogram ( name: "foo" , scope: !3 , file: !3 , line: 3 , type: !13 , scopeLine: 3 , flags: D I F l a g P r o t o t y p e d | D I F l a g A l l C a l l s D e s c r i b e d , spFlags: D I S P F l a g D e f i n i t i o n | D I S P F l a g O p t i m i z e d , unit: !2 , retainedNodes: !16 )
!13 = !DISubroutineType ( types: !14 )
!14 = ! { !15 , !7 }
!15 = !DIBasicType ( name: "int" , size: 32 , encoding: D W _ A T E _ s i g n e d )
!16 = ! { !17 }
2019-11-20 19:20:53 +08:00
!17 = !DILocalVariable ( name: "p" , arg: 1 , scope: !12 , file: !3 , line: 3 , type: !7 )
[DebugInfo] Add a DW_OP_LLVM_entry_value operation
Summary:
Internally in LLVM's metadata we use DW_OP_entry_value operations with
the same semantics as DWARF; that is, its operand specifies the number
of bytes that the entry value covers.
At the time of emitting entry values we don't know the emitted size of
the DWARF expression that the entry value will cover. Currently the size
is hardcoded to 1 in DIExpression, and other values causes the verifier
to fail. As the size is 1, that effectively means that we can only have
valid entry values for registers that can be encoded in one byte, which
are the registers with DWARF numbers 0 to 31 (as they can be encoded as
single-byte DW_OP_reg0..DW_OP_reg31 rather than a multi-byte
DW_OP_regx). It is a bit confusing, but it seems like llvm-dwarfdump
will print an operation "correctly", even if the byte size is less than
that, which may make it seem that we emit correct DWARF for registers
with DWARF numbers > 31. If you instead use readelf for such cases, it
will interpret the number of specified bytes as a DWARF expression. This
seems like a limitation in llvm-dwarfdump.
As suggested in D66746, a way forward would be to add an internal
variant of DW_OP_entry_value, DW_OP_LLVM_entry_value, whose operand
instead specifies the number of operations that the entry value covers,
and we then translate that into the byte size at the time of emission.
In this patch that internal operation is added. This patch keeps the
limitation that a entry value can only be applied to simple register
locations, but it will fix the issue with the size operand being
incorrect for DWARF numbers > 31.
Reviewers: aprantl, vsk, djtodoro, NikolaPrica
Reviewed By: aprantl
Subscribers: jyknight, fedor.sergeev, hiraditya, llvm-commits
Tags: #debug-info, #llvm
Differential Revision: https://reviews.llvm.org/D67492
llvm-svn: 374881
2019-10-15 19:31:21 +08:00
!18 = !DILocation ( line: 0 , scope: !12 )
!19 = !DILocation ( line: 4 , scope: !12 )
!20 = !DILocation ( line: 5 , scope: !12 )
!21 = !DILocation ( line: 6 , scope: !12 )