In order to set breakpoints on labels and list source code around labels, we need collect debug information for labels, i.e., label name, the function label belong, line number in the file, and the address label located. In order to keep these information in LLVM IR and to allow backend to generate debug information correctly. We create a new kind of metadata for labels, DILabel. The format of DILabel is !DILabel(scope: !1, name: "foo", file: !2, line: 3) We hope to keep debug information as much as possible even the code is optimized. So, we create a new kind of intrinsic for label metadata to avoid the metadata is eliminated with basic block. The intrinsic will keep existing if we keep it from optimized out. The format of the intrinsic is llvm.dbg.label(metadata !1) It has only one argument, that is the DILabel metadata. The intrinsic will follow the label immediately. Backend could get the label metadata through the intrinsic's parameter. We also create DIBuilder API for labels to be used by Frontend. Frontend could use createLabel() to allocate DILabel objects, and use insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR. Differential Revision: https://reviews.llvm.org/D45024 Patch by Hsiangkai Wang. llvm-svn: 331841
102 lines
4.2 KiB
LLVM
102 lines
4.2 KiB
LLVM
; RUN: %llc_dwarf -O0 -filetype=obj -o %t.o %s
|
|
; RUN: llvm-dwarfdump -v -debug-info %t.o | FileCheck %s
|
|
; REQUIRES: object-emission
|
|
;
|
|
; Test debug info for variadic function arguments.
|
|
; Created from tools/clang/tests/CodeGenCXX/debug-info-varargs.cpp
|
|
;
|
|
; The ... parameter of variadic should be emitted as
|
|
; DW_TAG_unspecified_parameters.
|
|
;
|
|
; Normal variadic function.
|
|
; void b(int c, ...);
|
|
;
|
|
; CHECK: DW_TAG_subprogram
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_AT_name {{.*}} "a"
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_formal_parameter
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_formal_parameter
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_unspecified_parameters
|
|
;
|
|
; CHECK: DW_TAG_subprogram
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_AT_name {{.*}} "b"
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_formal_parameter
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_variable
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_variable
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_unspecified_parameters
|
|
;
|
|
; Variadic C++ member function.
|
|
; struct A { void a(int c, ...); }
|
|
;
|
|
; Variadic function pointer.
|
|
; void (*fptr)(int, ...);
|
|
;
|
|
; CHECK: DW_TAG_subroutine_type
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_formal_parameter
|
|
; CHECK-NOT: DW_TAG
|
|
; CHECK: DW_TAG_unspecified_parameters
|
|
;
|
|
; ModuleID = 'llvm/tools/clang/test/CodeGenCXX/debug-info-varargs.cpp'
|
|
|
|
%struct.A = type { i8 }
|
|
|
|
; Function Attrs: nounwind ssp uwtable
|
|
define void @_Z1biz(i32 %c, ...) #0 !dbg !14 {
|
|
%1 = alloca i32, align 4
|
|
%a = alloca %struct.A, align 1
|
|
%fptr = alloca void (i32, ...)*, align 8
|
|
store i32 %c, i32* %1, align 4
|
|
call void @llvm.dbg.declare(metadata i32* %1, metadata !21, metadata !DIExpression()), !dbg !22
|
|
call void @llvm.dbg.declare(metadata %struct.A* %a, metadata !23, metadata !DIExpression()), !dbg !24
|
|
call void @llvm.dbg.declare(metadata void (i32, ...)** %fptr, metadata !25, metadata !DIExpression(DW_OP_deref)), !dbg !27
|
|
store void (i32, ...)* @_Z1biz, void (i32, ...)** %fptr, align 8, !dbg !27
|
|
ret void, !dbg !28
|
|
}
|
|
|
|
; Function Attrs: nounwind readnone
|
|
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
|
|
|
|
attributes #0 = { nounwind ssp uwtable }
|
|
attributes #1 = { nounwind readnone }
|
|
|
|
!llvm.dbg.cu = !{!0}
|
|
!llvm.module.flags = !{!18, !19}
|
|
!llvm.ident = !{!20}
|
|
|
|
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !3, globals: !2, imports: !2)
|
|
!1 = !DIFile(filename: "llvm/tools/clang/test/CodeGenCXX/debug-info-varargs.cpp", directory: "radar/13690847")
|
|
!2 = !{}
|
|
!3 = !{!4}
|
|
!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "A", line: 3, size: 8, align: 8, file: !1, elements: !5, identifier: "_ZTS1A")
|
|
!5 = !{!6}
|
|
!6 = !DISubprogram(name: "a", linkageName: "_ZN1A1aEiz", line: 6, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 6, file: !1, scope: !4, type: !7)
|
|
!7 = !DISubroutineType(types: !8)
|
|
!8 = !{null, !9, !10, null}
|
|
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !4)
|
|
!10 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
|
|
!14 = distinct !DISubprogram(name: "b", linkageName: "_Z1biz", line: 13, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 13, file: !1, scope: !15, type: !16, retainedNodes: !2)
|
|
!15 = !DIFile(filename: "llvm/tools/clang/test/CodeGenCXX/debug-info-varargs.cpp", directory: "radar/13690847")
|
|
!16 = !DISubroutineType(types: !17)
|
|
!17 = !{null, !10, null}
|
|
!18 = !{i32 2, !"Dwarf Version", i32 2}
|
|
!19 = !{i32 1, !"Debug Info Version", i32 3}
|
|
!20 = !{!"clang version 3.5 "}
|
|
!21 = !DILocalVariable(name: "c", line: 13, arg: 1, scope: !14, file: !15, type: !10)
|
|
!22 = !DILocation(line: 13, scope: !14)
|
|
!23 = !DILocalVariable(name: "a", line: 16, scope: !14, file: !15, type: !4)
|
|
!24 = !DILocation(line: 16, scope: !14)
|
|
; Manually modifed to avoid dependence on pointer size
|
|
!25 = !DILocalVariable(name: "fptr", line: 18, scope: !14, file: !15, type: !16)
|
|
!26 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !16)
|
|
!27 = !DILocation(line: 18, scope: !14)
|
|
!28 = !DILocation(line: 22, scope: !14)
|