Skip to content

Commit

Permalink
Add flag to replay for rr onprocess pid
Browse files Browse the repository at this point in the history
Add `-p` or `rr-onprocess-pid` to replay
command to pass `-p` or `--onprocess` pid
to `rr`.
  • Loading branch information
jcpowermac committed Feb 20, 2023
1 parent cf65f94 commit 9b5fc5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Documentation/usage/dlv_replay.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ dlv replay [trace directory] [flags]
### Options

```
-h, --help help for replay
-h, --help help for replay
-p, --onprocess int Pass onprocess pid to rr.
```

### Options inherited from parent commands
Expand Down
7 changes: 7 additions & 0 deletions cmd/dlv/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ var (

conf *config.Config
loadConfErr error

rrOnProcessPid int
)

const dlvCommandLongDesc = `Delve is a source level debugger for Go programs.
Expand Down Expand Up @@ -368,6 +370,10 @@ https://github.com/mozilla/rr
os.Exit(execute(0, []string{}, conf, args[0], debugger.ExecutingOther, args, buildFlags))
},
}

replayCommand.Flags().IntVarP(&rrOnProcessPid, "onprocess", "p", 0,
"Pass onprocess pid to rr.")

rootCommand.AddCommand(replayCommand)
}

Expand Down Expand Up @@ -981,6 +987,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile
TTY: tty,
Redirects: redirects,
DisableASLR: disableASLR,
RrOnProcessPid: rrOnProcessPid,
},
})
default:
Expand Down
15 changes: 12 additions & 3 deletions pkg/proc/gdbserial/rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,21 @@ func Record(cmd []string, wd string, quiet bool, redirects [3]string) (tracedir

// Replay starts an instance of rr in replay mode, with the specified trace
// directory, and connects to it.
func Replay(tracedir string, quiet, deleteOnDetach bool, debugInfoDirs []string) (*proc.Target, error) {
func Replay(tracedir string, quiet, deleteOnDetach bool, debugInfoDirs []string, rrOnProcessPid int) (*proc.Target, error) {
if err := checkRRAvailable(); err != nil {
return nil, err
}

rrcmd := exec.Command("rr", "replay", "--dbgport=0", tracedir)
args := []string{
"replay",
"--dbgport=0",
}
if rrOnProcessPid != 0 {
args = append(args, fmt.Sprintf("--onprocess=%d", rrOnProcessPid))
}
args = append(args, tracedir)

rrcmd := exec.Command("rr", args...)
rrcmd.Stdout = os.Stdout
stderr, err := rrcmd.StderrPipe()
if err != nil {
Expand Down Expand Up @@ -284,7 +293,7 @@ func RecordAndReplay(cmd []string, wd string, quiet bool, debugInfoDirs []string
if tracedir == "" {
return nil, "", err
}
t, err := Replay(tracedir, quiet, true, debugInfoDirs)
t, err := Replay(tracedir, quiet, true, debugInfoDirs, 0)
return t, tracedir, err
}

Expand Down
6 changes: 4 additions & 2 deletions service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ type Config struct {

// DisableASLR disables ASLR
DisableASLR bool

RrOnProcessPid int
}

// New creates a new Debugger. ProcessArgs specify the commandline arguments for the
Expand Down Expand Up @@ -175,7 +177,7 @@ func New(config *Config, processArgs []string) (*Debugger, error) {
switch d.config.Backend {
case "rr":
d.log.Infof("opening trace %s", d.config.CoreFile)
p, err = gdbserial.Replay(d.config.CoreFile, false, false, d.config.DebugInfoDirectories)
p, err = gdbserial.Replay(d.config.CoreFile, false, false, d.config.DebugInfoDirectories, d.config.RrOnProcessPid)
default:
d.log.Infof("opening core file %s (executable %s)", d.config.CoreFile, d.processArgs[0])
p, err = core.OpenCore(d.config.CoreFile, d.processArgs[0], d.config.DebugInfoDirectories)
Expand Down Expand Up @@ -338,7 +340,7 @@ func (d *Debugger) recordingRun(run func() (string, error)) (*proc.Target, error
return nil, err
}

return gdbserial.Replay(tracedir, false, true, d.config.DebugInfoDirectories)
return gdbserial.Replay(tracedir, false, true, d.config.DebugInfoDirectories, 0)
}

// Attach will attach to the process specified by 'pid'.
Expand Down

0 comments on commit 9b5fc5d

Please sign in to comment.