Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Debug Info for Move compiler #403

Open
jcivlin opened this issue Jan 4, 2024 · 1 comment
Open

Debug Info for Move compiler #403

jcivlin opened this issue Jan 4, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jcivlin
Copy link
Collaborator

jcivlin commented Jan 4, 2024

🚀 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
Copy link
Collaborator Author

jcivlin commented Jan 13, 2024

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant