Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to debug a guest program #115

Open
xlc opened this issue May 6, 2024 · 1 comment
Open

How to debug a guest program #115

xlc opened this issue May 6, 2024 · 1 comment

Comments

@xlc
Copy link

xlc commented May 6, 2024

Any tips on how to debug a guest program? e.g. How to make it log something

@koute
Copy link
Collaborator

koute commented May 6, 2024

For classic printf-style debugging you can use a host function to produce some logs.

You can also set RUST_LOG=trace POLKAVM_BACKEND=interpreter environment variables (assuming you're using env_logger and using Config::from_env) to get it to log whatever it is executing, values of the registers, etc. For example:

[TRACE polkavm::interpreter] 441195: jump 441260 if a0 == 0
[TRACE polkavm::interpreter] 441199: s1 = s1 - 1
[TRACE polkavm::interpreter] s1 = 0x30
[TRACE polkavm::interpreter] 441202: s0 = s0 + 0x18
[TRACE polkavm::interpreter] s0 = 0x8b760
[TRACE polkavm::interpreter] 441205: jump 441182 if s1 != 0
[TRACE polkavm::interpreter] 441182: a1 = u32 [s0]
[TRACE polkavm::interpreter] a1 = u32 [0x8b760]
[TRACE polkavm::interpreter] a1 = 0x1aba4
[TRACE polkavm::interpreter] 441184: a0 = u32 [sp + 4]
[TRACE polkavm::interpreter] a0 = u32 [0xfffefdbc]
[TRACE polkavm::interpreter] a0 = 0xfffefdd4
[TRACE polkavm::interpreter] 441187: ra = 27748, jump 277367

It's also useful to use polkatool disassemble to disassemble your program for debugging.

In the future I want to have a fully fledged debugger for guest programs with nice IDE integration and time-travel debugging, but we're not there yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants