From 40670aadc24aae2770a5d661a4f39c9215ae4a08 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Fri, 24 May 2024 20:33:23 +0200 Subject: [PATCH] proc/gdbserial: add environment variables to configure rr invocation (#3726) Adds two environment variables to configure rr invocations. Fixes #3670 --- Documentation/usage/dlv_backend.md | 5 +++++ cmd/dlv/cmds/commands.go | 5 +++++ pkg/proc/gdbserial/rr.go | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/Documentation/usage/dlv_backend.md b/Documentation/usage/dlv_backend.md index d4c2bcbb16..02c833f230 100644 --- a/Documentation/usage/dlv_backend.md +++ b/Documentation/usage/dlv_backend.md @@ -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 diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index ff6f24ca8a..e8e2343788 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -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{ diff --git a/pkg/proc/gdbserial/rr.go b/pkg/proc/gdbserial/rr.go index 3fdff59b93..03cd781e6d 100644 --- a/pkg/proc/gdbserial/rr.go +++ b/pkg/proc/gdbserial/rr.go @@ -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 @@ -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() @@ -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...)