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

@ -41,7 +41,8 @@ type Target struct {
proc ProcessInternal
recman RecordingManipulationInternal
pid int
pid int
CmdLine string
// StopReason describes the reason why the target process is stopped.
// A process could be stopped for multiple simultaneous reasons, in which
@ -160,7 +161,7 @@ func DisableAsyncPreemptEnv() []string {
// newTarget returns an initialized Target object.
// The p argument can optionally implement the RecordingManipulation interface.
func (grp *TargetGroup) newTarget(p ProcessInternal, pid int, currentThread Thread, path string) (*Target, error) {
func (grp *TargetGroup) newTarget(p ProcessInternal, pid int, currentThread Thread, path, cmdline string) (*Target, error) {
entryPoint, err := p.EntryPoint()
if err != nil {
return nil, err
@ -182,6 +183,7 @@ func (grp *TargetGroup) newTarget(p ProcessInternal, pid int, currentThread Thre
fncallForG: make(map[int64]*callInjection),
currentThread: currentThread,
pid: pid,
CmdLine: cmdline,
}
if recman, ok := p.(RecordingManipulationInternal); ok {