llvm.org GIT mirror llvm / 6f8c0c0
Add DWARF discriminator support to DILexicalBlocks. This adds support for emitting discriminators from DILexicalBlocks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202736 91177308-0d34-0410-b5e6-96231b3b80d8 Diego Novillo 6 years ago
7 changed file(s) with 84 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
318318 metadata,;; Reference to context descriptor
319319 i32, ;; Line number
320320 i32, ;; Column number
321 i32, ;; DWARF path discriminator value
321322 i32 ;; Unique ID to identify blocks from a template function
322323 }
323324
723724 !15 = metadata !{i32 786688, metadata !16, metadata !"Z", metadata !5, i32 5,
724725 metadata !11, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [Z] \
725726 [line 5]
726 !16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0} \
727 !16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0,
728 i32 0} \
727729 ; [ DW_TAG_lexical_block ] [/private/tmp/t.c]
728730 !17 = metadata !{i32 5, i32 0, metadata !16, null}
729731 !18 = metadata !{i32 6, i32 0, metadata !16, null}
775777
776778 .. code-block:: llvm
777779
778 !16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0}
780 !16 = metadata !{i32 786443, metadata !1, metadata !4, i32 4, i32 0, i32 0,
781 i32 0}
779782 ; [ DW_TAG_lexical_block ] [/private/tmp/t.c]
780783 !17 = metadata !{i32 5, i32 0, metadata !16, null}
781784
632632
633633 /// createLexicalBlock - This creates a descriptor for a lexical block
634634 /// with the specified parent context.
635 /// @param Scope Parent lexical scope.
636 /// @param File Source file
637 /// @param Line Line number
638 /// @param Col Column number
635 /// @param Scope Parent lexical scope.
636 /// @param File Source file.
637 /// @param Line Line number.
638 /// @param Col Column number.
639 /// @param Discriminator DWARF path discriminator value.
639640 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
640 unsigned Line, unsigned Col);
641 unsigned Line, unsigned Col,
642 unsigned Discriminator);
641643
642644 /// \brief Create a descriptor for an imported module.
643645 /// @param Context The scope this module is imported into
521521 DIScope getContext() const { return getFieldAs(2); }
522522 unsigned getLineNumber() const { return getUnsignedField(3); }
523523 unsigned getColumnNumber() const { return getUnsignedField(4); }
524 unsigned getDiscriminator() const { return getUnsignedField(5); }
524525 bool Verify() const;
525526 };
526527
18241824 StringRef Fn;
18251825 StringRef Dir;
18261826 unsigned Src = 1;
1827 unsigned Discriminator = 0;
18271828 if (S) {
18281829 DIDescriptor Scope(S);
18291830
18471848 DILexicalBlock DB(S);
18481849 Fn = DB.getFilename();
18491850 Dir = DB.getDirectory();
1851 Discriminator = DB.getDiscriminator();
18501852 } else
18511853 llvm_unreachable("Unexpected scope info");
18521854
18531855 Src = getOrCreateSourceID(
18541856 Fn, Dir, Asm->OutStreamer.getContext().getDwarfCompileUnitID());
18551857 }
1856 Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0, 0, Fn);
1858 Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, Flags, 0,
1859 Discriminator, Fn);
18571860 }
18581861
18591862 //===----------------------------------------------------------------------===//
11851185 }
11861186
11871187 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1188 unsigned Line, unsigned Col) {
1188 unsigned Line, unsigned Col,
1189 unsigned Discriminator) {
11891190 // Defeat MDNode uniquing for lexical blocks by using unique id.
11901191 static unsigned int unique_id = 0;
11911192 Value *Elts[] = {
11941195 getNonCompileUnitScope(Scope),
11951196 ConstantInt::get(Type::getInt32Ty(VMContext), Line),
11961197 ConstantInt::get(Type::getInt32Ty(VMContext), Col),
1198 ConstantInt::get(Type::getInt32Ty(VMContext), Discriminator),
11971199 ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
11981200 };
11991201 DILexicalBlock R(MDNode::get(VMContext, Elts));
599599
600600 /// \brief Verify that the lexical block descriptor is well formed.
601601 bool DILexicalBlock::Verify() const {
602 return isLexicalBlock() && DbgNode->getNumOperands() == 6;
602 return isLexicalBlock() && DbgNode->getNumOperands() == 7;
603603 }
604604
605605 /// \brief Verify that the file-scoped lexical block descriptor is well formed.
0 ; RUN: llc -mtriple=i386-unknown-unknown %s -o %t -filetype=obj
1 ; RUN: llvm-dwarfdump -debug-dump=line %t | FileCheck %s
2 ;
3 ; Generated from:
4 ;
5 ; int foo(int i) {
6 ; if (i < 10) return i - 1;
7 ; return 0;
8 ; }
9 ;
10 ; Manually generated debug nodes !14 and !15 to incorporate an
11 ; arbitrary discriminator with value 42.
12
13 define i32 @foo(i32 %i) #0 {
14 entry:
15 %retval = alloca i32, align 4
16 %i.addr = alloca i32, align 4
17 store i32 %i, i32* %i.addr, align 4
18 %0 = load i32* %i.addr, align 4, !dbg !10
19 %cmp = icmp slt i32 %0, 10, !dbg !10
20 br i1 %cmp, label %if.then, label %if.end, !dbg !10
21
22 if.then: ; preds = %entry
23 %1 = load i32* %i.addr, align 4, !dbg !14
24 %sub = sub nsw i32 %1, 1, !dbg !14
25 store i32 %sub, i32* %retval, !dbg !14
26 br label %return, !dbg !14
27
28 if.end: ; preds = %entry
29 store i32 0, i32* %retval, !dbg !12
30 br label %return, !dbg !12
31
32 return: ; preds = %if.end, %if.then
33 %2 = load i32* %retval, !dbg !13
34 ret i32 %2, !dbg !13
35 }
36
37 attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
38
39 !llvm.dbg.cu = !{!0}
40 !llvm.module.flags = !{!7, !8}
41 !llvm.ident = !{!9}
42
43 !0 = metadata !{i32 786449, metadata !1, i32 12, metadata !"clang version 3.5 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [./discriminator.c] [DW_LANG_C99]
44 !1 = metadata !{metadata !"discriminator.c", metadata !"."}
45 !2 = metadata !{}
46 !3 = metadata !{metadata !4}
47 !4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"foo", metadata !"foo", metadata !"", i32 1, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 (i32)* @foo, null, null, metadata !2, i32 1} ; [ DW_TAG_subprogram ] [line 1] [def] [foo]
48 !5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [./discriminator.c]
49 !6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !2, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
50 !7 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}
51 !8 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
52 !9 = metadata !{metadata !"clang version 3.5 "}
53 !10 = metadata !{i32 2, i32 0, metadata !11, null}
54 !11 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [./discriminator.c]
55 !12 = metadata !{i32 3, i32 0, metadata !4, null}
56 !13 = metadata !{i32 4, i32 0, metadata !4, null}
57 !14 = metadata !{i32 2, i32 0, metadata !15, null}
58 !15 = metadata !{i32 786443, metadata !1, metadata !4, i32 2, i32 0, i32 42, i32 1} ; [ DW_TAG_lexical_block ] [./discriminator.c]
59
60 ; CHECK: Address Line Column File ISA Discriminator Flags
61 ; CHECK: ------------------ ------ ------ ------ --- ------------- -------------
62 ; CHECK: 0x0000000000000011 2 0 1 0 42 is_stmt