proc,terminal: read command line of new processes (#3346)

Read the command line of the main target process as well as any other
process Delve attaches to in follow exec mode.
The command line can be viewed using the 'target list' command.

In follow exec mode this command line is used to match the follow exec
regex to decide whether or not to attach to a child process.

On macOS or when using rr the list of arguments is not available for
attached processes since there is no way to use the gdb serial protocol
to read it.

Fixes #2242
This commit is contained in:
Alessandro Arzilli
2023-05-09 20:40:00 +02:00
committed by GitHub
parent 801a9109c7
commit e95ae9c21b
18 changed files with 310 additions and 67 deletions

View File

@ -176,7 +176,7 @@ func New(config *Config, processArgs []string) (*Debugger, error) {
switch d.config.Backend {
case "rr":
d.log.Infof("opening trace %s", d.config.CoreFile)
d.target, err = gdbserial.Replay(d.config.CoreFile, false, false, d.config.DebugInfoDirectories, d.config.RrOnProcessPid)
d.target, 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])
d.target, err = core.OpenCore(d.config.CoreFile, d.processArgs[0], d.config.DebugInfoDirectories)
@ -335,7 +335,7 @@ func (d *Debugger) recordingRun(run func() (string, error)) (*proc.TargetGroup,
return nil, err
}
return gdbserial.Replay(tracedir, false, true, d.config.DebugInfoDirectories, 0)
return gdbserial.Replay(tracedir, false, true, d.config.DebugInfoDirectories, 0, strings.Join(d.processArgs, " "))
}
// Attach will attach to the process specified by 'pid'.
@ -568,6 +568,7 @@ func (d *Debugger) state(retLoadCfg *proc.LoadConfig, withBreakpointInfo bool) (
state = &api.DebuggerState{
Pid: tgt.Pid(),
TargetCommandLine: tgt.CmdLine,
SelectedGoroutine: goroutine,
Exited: exited,
}