Skip to content

Commit

Permalink
proc/gdbserial: add environment variables to configure rr invocation (g…
Browse files Browse the repository at this point in the history
…o-delve#3726)

Adds two environment variables to configure rr invocations.

Fixes go-delve#3670
  • Loading branch information
aarzilli authored May 24, 2024
1 parent 35ebb08 commit 40670aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Documentation/usage/dlv_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ are:
lldb Uses lldb-server or debugserver.
rr Uses mozilla rr (https://github.com/mozilla/rr).

Some backends can be configured using environment variables:

* DELVE_DEBUGSERVER_PATH specifies the path of the debugserver executable for the lldb backend
* DELVE_RR_RECORD_FLAGS specifies additional flags used when calling 'rr record'
* DELVE_RR_REPLAY_FLAGS specifies additional flags used when calling 'rr replay'


### Options
Expand Down
5 changes: 5 additions & 0 deletions cmd/dlv/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ are:
lldb Uses lldb-server or debugserver.
rr Uses mozilla rr (https://github.com/mozilla/rr).
Some backends can be configured using environment variables:
* DELVE_DEBUGSERVER_PATH specifies the path of the debugserver executable for the lldb backend
* DELVE_RR_RECORD_FLAGS specifies additional flags used when calling 'rr record'
* DELVE_RR_REPLAY_FLAGS specifies additional flags used when calling 'rr replay'
`})

rootCommand.AddCommand(&cobra.Command{
Expand Down
7 changes: 7 additions & 0 deletions pkg/proc/gdbserial/rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
"github.com/go-delve/delve/pkg/proc"
)

const (
delveRecordFlagsEnvVar = "DELVE_RR_RECORD_FLAGS"
delveReplayFlagsEnvVar = "DELVE_RR_REPLAY_FLAGS"
)

// RecordAsync configures rr to record the execution of the specified
// program. Returns a run function which will actually record the program, a
// stop function which will prematurely terminate the recording of the
Expand All @@ -31,6 +36,7 @@ func RecordAsync(cmd []string, wd string, quiet bool, stdin string, stdout proc.

args := make([]string, 0, len(cmd)+2)
args = append(args, "record", "--print-trace-dir=3")
args = append(args, config.SplitQuotedFields(os.Getenv(delveRecordFlagsEnvVar), '"')...)
args = append(args, cmd...)
rrcmd := exec.Command("rr", args...)
var closefn func()
Expand Down Expand Up @@ -141,6 +147,7 @@ func Replay(tracedir string, quiet, deleteOnDetach bool, debugInfoDirs []string,
if rrOnProcessPid != 0 {
args = append(args, fmt.Sprintf("--onprocess=%d", rrOnProcessPid))
}
args = append(args, config.SplitQuotedFields(os.Getenv(delveReplayFlagsEnvVar), '\'')...)
args = append(args, tracedir)

rrcmd := exec.Command("rr", args...)
Expand Down

0 comments on commit 40670aa

Please sign in to comment.