llvm.org GIT mirror llvm / cf493b8
Some formatting and spelling fixes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90182 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
1 changed file(s) with 68 addition(s) and 62 deletion(s). Raw diff Collapse all Expand all
779779
780780
781781
782

In many languages, the local variables in functions can have their lifetime

783 or scope limited to a subset of a function. In the C family of languages,
782

In many languages, the local variables in functions can have their lifetimes

783 or scopes limited to a subset of a function. In the C family of languages,
784784 for example, variables are only live (readable and writable) within the
785785 source block that they are defined in. In functional languages, values are
786786 only readable after they have been defined. Though this is a very obvious
787 concept, it is also non-trivial to model in LLVM, because it has no notion of
787 concept, it is non-trivial to model in LLVM, because it has no notion of
788788 scoping in this sense, and does not want to be tied to a language's scoping
789789 rules.

790790
791

In order to handle this, the LLVM debug format uses the metadata attached

792 with llvm instructions to encode line nuber and scoping information.
793 Consider the following C fragment, for example:

791

In order to handle this, the LLVM debug format uses the metadata attached to

792 llvm instructions to encode line nuber and scoping information. Consider the
793 following C fragment, for example:

794794
795795
796796

                  
                
810810
811811
812812

                  
                
813 nounwind ssp {
813 define void @foo() nounwind ssp {
814814 entry:
815815 %X = alloca i32, align 4 ; [#uses=4]
816816 %Y = alloca i32, align 4 ; [#uses=4]
866866
867867
868868
869

This example illustrates a few important details about the LLVM debugging

870 information. In particular, it shows how the llvm.dbg.declare intrinsic
871 and location information, attached with an instruction, are applied
872 together to allow a debugger to analyze the relationship between statements,
873 variable definitions, and the code used to implement the function.

874
875
876
 

                  
                
877 call void @llvm.dbg.declare({ }* %0, metadata !0), !dbg !7
878
879
880

This first intrinsic

869

This example illustrates a few important details about LLVM debugging

870 information. In particular, it shows how the llvm.dbg.declare
871 intrinsic and location information, which are attached to an instruction,
872 are applied together to allow a debugger to analyze the relationship between
873 statements, variable definitions, and the code used to implement the
874 function.

875
876
877
 

                  
                
878 call void @llvm.dbg.declare({ }* %0, metadata !0), !dbg !7
879
880
881
882

The first intrinsic

881883 %llvm.dbg.declare
882 encodes debugging information for variable X. The metadata,
883 !dbg !7 attached with the intrinsic provides scope information for
884 the variable X.

885
886

                  
                
887 !7 = metadata !{i32 2, i32 7, metadata !1, null}
888 !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
889 !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo",
890 metadata !"foo", metadata !"foo", metadata !3, i32 1,
891 metadata !4, i1 false, i1 true}; [DW_TAG_subprogram ]
892
893
894
895

Here !7 is a metadata providing location information. It has four

896 fields : line number, column number, scope and original scope. The original
897 scope represents inline location if this instruction is inlined inside
898 a caller. It is null otherwise. In this example scope is encoded by
884 encodes debugging information for the variable X. The metadata
885 !dbg !7 attached to the intrinsic provides scope information for the
886 variable X.

887
888
889

                  
                
890 !7 = metadata !{i32 2, i32 7, metadata !1, null}
891 !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
892 !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo",
893 metadata !"foo", metadata !"foo", metadata !3, i32 1,
894 metadata !4, i1 false, i1 true}; [DW_TAG_subprogram ]
895
896
897
898

Here !7 is metadata providing location information. It has four

899 fields: line number, column number, scope, and original scope. The original
900 scope represents inline location if this instruction is inlined inside a
901 caller, and is null otherwise. In this example, scope is encoded by
899902 !1. !1 represents a lexical block inside the scope
900903 !2, where !2 is a
901 subprogram descriptor.
902 This way the location information attched with the intrinsics indicates
903 that the variable X is declared at line number 2 at a function level
904 scope in function foo.

904 subprogram descriptor. This way the
905 location information attached to the intrinsics indicates that the
906 variable X is declared at line number 2 at a function level scope in
907 function foo.

905908
906909

Now lets take another example.

907910
908
909
 

                  
                
910 call void @llvm.dbg.declare({ }* %2, metadata !12), !dbg !14
911
912
913 <p>This intrinsic
911 <div class="doc_code">
912
 

                  
                
913 call void @llvm.dbg.declare({ }* %2, metadata !12), !dbg !14
914
915
916
917

The second intrinsic

914918 %llvm.dbg.declare
915 encodes debugging information for variable Z. The metadata,
916 !dbg !14 attached with the intrinsic provides scope information for
917 the variable Z.

918
919

                  
                
920 !13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
921 !14 = metadata !{i32 5, i32 9, metadata !13, null}
922
923
924
925

Here !14 indicates that Z is declaread at line number 5,

926 column number 9 inside a lexical scope !13. This lexical scope
927 itself resides inside lexcial scope !1 described above.

928
929

The scope information attached with each instruction provides a straight

930 forward way to find instructions covered by a scope.

919 encodes debugging information for variable Z. The metadata
920 !dbg !14 attached to the intrinsic provides scope information for
921 the variable Z.

922
923
924

                  
                
925 !13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
926 !14 = metadata !{i32 5, i32 9, metadata !13, null}
927
928
929
930

Here !14 indicates that Z is declaread at line number 5 and

931 column number 9 inside of lexical scope !13. The lexical scope
932 itself resides inside of lexical scope !1 described above.

933
934

The scope information attached with each instruction provides a

935 straightforward way to find instructions covered by a scope.

936
931937
932938
933939