Debugging
Debugging Programs
Huione programs run on-chain, so debugging them in the wild can be challenging. To make debugging programs easier, developers can write unit tests that directly test their program's execution via the Huione runtime, or run a local cluster that will allow RPC clients to interact with their program.
Running unit tests
Logging
During program execution both the runtime and the program log status and error messages.
For information about how to log from a program see the language specific documentation:
When running a local cluster the logs are written to stdout as long as they are enabled via the RUST_LOG log mask. From the perspective of program development it is helpful to focus on just the runtime and program logs and not the rest of the cluster logs. To focus in on program specific information the following log mask is recommended:
export RUST_LOG=put_runtime::system_instruction_processor=trace,huione_runtime::message_processor=info,put_bpf_loader=debug,put_rbpf=debug
Log messages coming directly from the program (not the runtime) will be displayed in the form:
Program log:
Error Handling
The amount of information that can be communicated via a transaction error is limited but there are many points of possible failures. The following are possible failure points and information about what errors to expect and where to get more information:
In the case of Virtual Machine Failed To Run Program errors, more information about the specifics of what failed are written to the program's execution logs.
For example, an access violation involving the stack will look something like this:
BPF program 4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM failed: out of bounds memory store (insn #615), addr 0x200001e38/8
Monitoring Compute Budget Consumption
The program can log the remaining number of compute units it will be allowed before program execution is halted. Programs can use these logs to wrap operations they wish to profile.
See compute budget for more information.
ELF Dump
The BPF shared object internals can be dumped to a text file to gain more insight into a program's composition and what it may be doing at runtime.
Instruction Tracing
During execution the runtime BPF interpreter can be configured to log a trace message for each BPF instruction executed. This can be very helpful for things like pin-pointing the runtime context leading up to a memory access violation.
The trace logs together with the ELF dump can provide a lot of insight (though the traces produce a lot of information).
To turn on BPF interpreter trace messages in a local cluster configure the huione_rbpf level in RUST_LOG to trace. For example:
export RUST_LOG=huione_rbpf=trace
Last updated