WIP: get program state and source code #367
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The intent with this PR is to enable users and applications like aos-web and betteridea to perform analysis on a live process to view the actual currently running code and variables. It analyzes the lua globals via the
_G
global, and the packages loaded from the luapackage
system.The achieve this, we use the
.getinfo
utiil from thedebug
introspective stdlib.Actually being able to retrieve the function source required modifying how the
load
method is used in theeval
handler. Rather than the function name of "aos" being passed in, we pass the entire expression. This can then be used to traverse the lines where the function is defined in the source file.A current limitation of this is being able to show modules that are precompiled - for us to have context of the string where the function is defined (those loaded with the
eval
handler) they must have been loaded into the current program state.Still need to do some further experimentation in conjunction with the AO dev-cli, in particular here: https://github.com/permaweb/ao/blob/e2088442a399e871db552fb5031ae73bbf36c9b9/dev-cli/container/src/core/main.lua#L15
Where I suspect its just a matter of updating those load uses as well.
check out the ant-state.json for example output for program state :)
Still needs some refining, in particular the Handlers code retrieval, which I hope will become more visible with dev-cli updates.
Hopefully this will grant greater debugging utilities and program versioning.