anza-xyz / move

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

Debug Info for Move compiler #403

Open jcivlin opened 6 months ago

jcivlin commented 6 months ago

🚀 Feature Request

Add to Move compiler support for creating debug info (dwarf) in llvm

Motivation

Needed for debugger

Pitch

Use llvmdi facility

Additional context

None

jcivlin commented 5 months ago

Our move compiler allows to visualize the control flow per function.

For example for this vector.2.move program:

module 0x101::vector {

    native public fun empty<Element>(): vector<Element>;

    native public fun borrow<Element>(v: &vector<Element>, i: u64): &Element;

    native public fun push_back<Element>(v: &mut vector<Element>, e: Element);

    public fun singleton<Element>(e: Element): vector<Element> {
        let v = empty();
        push_back(&mut v, e);
        v
    }

    public fun test_singleton_contains() {
        let x_int = 1;
        assert!(*borrow(&singleton(x_int), 0) == x_int, 0);
    }
}

One can call compiler:

> move-mv-llvm-compiler  -S -c /home/sol/tmp/vector.2.move -g -o /home/sol/tmp/vector_out/ --dot-out-dir /home/sol/tmp/vector_out --gen-dot-cfg write

and this will produce the bytecode:

public fun vector::test_singleton_contains() {
     var $t0|tmp#$0: vector<u64>
     var $t1|x_int: u64
     var $t2: u64
     var $t3: u64
     var $t4: vector<u64>
     var $t5: &vector<u64>
     var $t6: u64
     var $t7: &u64
     var $t8: u64
     var $t9: u64
     var $t10: bool
     var $t11: u64
  0: $t2 := 1
  1: $t1 := $t2
  2: $t3 := copy($t1)
  3: $t4 := vector::singleton<u64>($t3)
  4: $t0 := $t4
  5: $t5 := borrow_local($t0)
  6: $t6 := 0
  7: $t7 := vector::borrow<u64>($t5, $t6)
  8: $t8 := read_ref($t7)
  9: $t9 := move($t1)
 10: $t10 := ==($t8, $t9)
 11: if ($t10) goto 12 else goto 14
 12: label L1
 13: goto 17
 14: label L0
 15: $t11 := 0
 16: abort($t11)
 17: label L2
 18: return ()
}

and .dot file 0000000000000101_vector_test_singleton.dot, which can be converted to png:

> dot -Tpng -o /home/sol/tmp/vector_out/vector_test_singleton.png  /home/sol/tmp/vector_out/0000000000000101_vector_test_singleton.dot

png:

Screenshot 2024-01-12 at 10 47 45 PM