anza-xyz / move

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

Dwarf: debug_info for call instruction and tracing locals #415

Closed jcivlin closed 8 months ago

jcivlin commented 9 months ago

Motivation

Tracing updates in the variables requires an insertion of additional (debug-only) node into compilation graph. This however is impossible if we produce debug info in a separate module.

Therefore a design change was required and this PR implements it. In here we are removing a module dedicated for debug only: starting from this PR the DI builder writes to the same module as the compiler Builder. The added debug info consists of:

Also keep in mind that any debug related changes in the compiler graph (nodes or metadata) are activated only with "-g" compilation option. If "-g" is not set any call to a DIBuilder->func (or similar) is void.

Notable changes

  1. All named local variables, %local_1 in the example below, appended with an extra debug call @llvm.dbg.declare
    store i1 %par_2_bool, ptr %local_1, align 1
    ...
    %load_store_tmp = load i1, ptr %local_1, align 1, !dbg !38
    ...
    call void @llvm.dbg.declare(metadata ptr %local_1, metadata !39, metadata !DIExpression()), !dbg !38
  2. Call to a regular function is annotated with corresponding line in debug_info (only lines !2 and !39 are shown)
    %retval = call %struct.M__MyStruct @"0000000000000101_M_fun_1_AcLtMspYikxikv"(), !dbg !39
    ...
    !39 = !DILocation(line: 11, column: 39, scope: !2)
    !2 = distinct !DISubprogram(name: "fun_2", linkageName: "fun_2", scope: !1, file: !1, line: 7, type: !3, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !4)

Ref issue

https://github.com/anza-xyz/move/issues/403

ksolana commented 8 months ago

Please move the patch from 'Draft' to 'in-review'

jcivlin commented 8 months ago

Thx!