anza-xyz / move

Move compiler targeting llvm supported backends
https://discord.gg/wFgfjG9J
Apache License 2.0
109 stars 34 forks source link

Dwarf for structs, functions, vectors #402

Closed jcivlin closed 9 months ago

jcivlin commented 9 months ago

Example of the debug info produced for this module/function/vector: (see line !5 with DISubrange, typical for vectors)

module 0x101::vector {
    struct Foo has copy, drop { x: u64, y: bool }

    public fun singleton<Element>(e: Element): vector<Element> {
        let v = empty();
        push_back(&mut v, e);
        v
    }
; ModuleID = '0x101__vector.dbg_info'
source_filename = "/home/sol/tmp/vector.1.move"

!llvm.dbg.cu = !{!0}
!unspecified\20type = !{!2, !2, !2, !2, !2, !2, !2}
!struct.vector__Foo = !{!6}
!test_singleton_contains = !{!14}
!singleton = !{!19}

!0 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !1, producer: "move-mv-llvm-compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/")
!1 = !DIFile(filename: "vector.1.move", directory: "/home/sol/tmp")
!2 = !DICompositeType(tag: DW_TAG_array_type, baseType: !3, size: 192, align: 8, flags: DIFlagVector, elements: !4)
!3 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "unspecified type")
!4 = !{!5}
!5 = !DISubrange(count: 1, lowerBound: 0)
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "struct.vector__Foo__ptr", baseType: !7, size: 64, align: 64, dwarfAddressSpace: 0)
!7 = !DICompositeType(tag: DW_TAG_structure_type, name: "struct.vector__Foo", scope: !8, file: !1, line: 17, size: 128, align: 8, flags: DIFlagObjcClassComplete, elements: !9)
!8 = !DINamespace(name: "struct.vector__Foo", scope: !1)
!9 = !{!10, !12}
!10 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !8, file: !1, line: 17, baseType: !11, size: 64, align: 64)
!11 = !DIBasicType(name: "u64", size: 64)
!12 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !8, file: !1, line: 18, baseType: !13, size: 1, align: 8, offset: 64)
!13 = !DIBasicType(name: "bool", size: 8)
!14 = distinct !DISubprogram(name: "test_singleton_contains", linkageName: "test_singleton_contains", scope: !15, file: !1, line: 70, type: !16, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !18)
!15 = !DINamespace(name: "test_singleton_contains", scope: !1)
!16 = !DISubroutineType(types: !17)
!17 = !{}
!18 = <temporary!> !{}
!19 = distinct !DISubprogram(name: "singleton", linkageName: "singleton", scope: !20, file: !1, line: 64, type: !21, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !24)
!20 = !DINamespace(name: "singleton", scope: !1)
!21 = !DISubroutineType(types: !22)
!22 = !{!23}
!23 = !DILocalVariable(name: "e", scope: !20, file: !1, type: !7)
!24 = <temporary!> !{}

Missing:

  1. Functions will be enriched with Basic Block chains.
  2. Vectors may be updated with better base type info.
jcivlin commented 9 months ago

This PR is a part of #403 work.