Skip to content

Commit

Permalink
improve debug
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Dec 24, 2024
1 parent 6b34c21 commit 35f5986
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions internal/runtime/hostfunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,22 +713,16 @@ func hostEd25519BatchVerify(ctx context.Context, mod api.Module, msgs_ptr, sigs_
// hostDebug implements debug
func hostDebug(ctx context.Context, mod api.Module, msgPtr uint32) {
mem := mod.Memory()

// Read message from memory (null-terminated string)
var msg []byte
offset := msgPtr
for {
// Read one byte at a time
b, err := readMemory(mem, offset, 1)
if err != nil || len(b) == 0 || b[0] == 0 {
break
}
msg = append(msg, b[0])
offset++
msg, err := readMemory(mem, msgPtr, 1024) // Read up to 1024 bytes
if err != nil {
return
}

// Print debug message
fmt.Printf("Debug: %s\n", string(msg))
// Find null terminator
length := 0
for length < len(msg) && msg[length] != 0 {
length++
}
fmt.Printf("Debug: %s\n", string(msg[:length]))
}

// hostQueryChain implements query_chain with signature (req_ptr i32) -> i32
Expand Down Expand Up @@ -829,6 +823,14 @@ func RegisterHostFunctions(runtime wazero.Runtime, env *RuntimeEnvironment) (waz
WithParameterNames("key_ptr", "key_len", "val_ptr", "val_len").
Export("db_set")

builder.NewFunctionBuilder().
WithFunc(func(ctx context.Context, m api.Module, keyPtr, keyLen, valPtr, valLen uint32) {
ctx = context.WithValue(ctx, envKey, env)
hostSet(ctx, m, keyPtr, keyLen, valPtr, valLen)
}).
WithParameterNames("key_ptr", "key_len", "val_ptr", "val_len").
Export("db_write")

// Register interface_version_8 function
builder.NewFunctionBuilder().
WithFunc(func(ctx context.Context, m api.Module) {
Expand Down
2 changes: 1 addition & 1 deletion lib_libwasmvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const (
TESTING_PRINT_DEBUG = false
TESTING_GAS_LIMIT = uint64(500_000_000_000) // ~0.5ms
TESTING_MEMORY_LIMIT = 32 // MiB
TESTING_MEMORY_LIMIT = 64 // MiB
TESTING_CACHE_SIZE = 100 // MiB
)

Expand Down

0 comments on commit 35f5986

Please sign in to comment.