Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from stealthrocket/trace
Browse files Browse the repository at this point in the history
replay: support -T,--trace flag like run command
  • Loading branch information
chriso committed May 27, 2023
2 parents 4ed7316 + 714e318 commit 68c28f3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/cmd/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"errors"
"fmt"
"os"

"github.com/google/uuid"
"github.com/stealthrocket/wasi-go"

"github.com/stealthrocket/timecraft/internal/timemachine"
"github.com/stealthrocket/timecraft/internal/timemachine/wasicall"
Expand All @@ -20,15 +22,18 @@ Usage: timecraft replay [options] <process id>
Options:
-h, --help Show this usage information
-r, --registry path Path to the timecraft registry (default to ~/.timecraft)
-T, --trace Enable strace-like logging of host function calls
`

func replay(ctx context.Context, args []string) error {
var (
registryPath = "~/.timecraft"
trace = false
)

flagSet := newFlagSet("timecraft replay", replayUsage)
stringVar(flagSet, &registryPath, "r", "registry")
boolVar(flagSet, &trace, "T", "trace")
flagSet.Parse(args)

args = flagSet.Args()
Expand Down Expand Up @@ -89,7 +94,10 @@ func replay(ctx context.Context, args []string) error {
fallback := wasicall.NewObserver(nil, func(ctx context.Context, s wasicall.Syscall) {
panic(fmt.Sprintf("system call made after log EOF: %s", s.ID()))
}, nil)
system := wasicall.NewFallbackSystem(replay, fallback)
var system wasi.System = wasicall.NewFallbackSystem(replay, fallback)
if trace {
system = &wasi.Tracer{Writer: os.Stderr, System: system}
}

// TODO: need to figure this out dynamically:
hostModule := wasi_snapshot_preview1.NewHostModule(wasi_snapshot_preview1.WasmEdgeV2)
Expand Down

0 comments on commit 68c28f3

Please sign in to comment.