aionnetwork / AVM

Enabling Java code to run in a blockchain environment
https://theoan.com/
MIT License
49 stars 25 forks source link

Support debugging of transformed DApps #322

Closed aionbot closed 5 years ago

aionbot commented 5 years ago

Issue created by jeff-aion (on Wednesday Nov 28, 2018 at 23:34 GMT)

We want developers building DApps to be able to test/debug them locally, against the real AVM. Currently, this is not directly possible since we strip all debug data from the user code on deployment.

Supporting this requires that we define a sort of "debug mode" for the AVM where a deployment will re-add the stripped debug data, before running <clinit> methods on deployment, saving this version for successive call debugging.

We also have to decide how/if we expose AVM-internal data such as the hash code and persistence token.

aion-shidokht commented 5 years ago

We can keep the debug information by storing (at least) the mapping between source line numbers and bytecode instructions, and local variable names in source code and local variable slots in bytecode.

ClassReader.SKIP_DEBUG removes the debug info required and should not be set as a parsingOption.

After some experimentation with ASM, I believe changing the method names in a class or adding new methods to it, does not prevent debugging. However, when the class (or package) names are changed, debugger does not stop at the break-point set in the smart contract/class.

aion-shidokht commented 5 years ago

Since in the debug mode user package prefixes are not added, AvmClassLoader could not function correctly. It was modified to load different classes in the following order:

  1. Local cache
  2. Bytecode
  3. User classes wrapped with the ArrayWrappingPrefix

Otherwise the class will be loaded by the parent class loader (AvmSharedClassLoader)