Skip to content

Commit

Permalink
proc/gdbserver: clean up rr directory on detach
Browse files Browse the repository at this point in the history
We used to autoremove the trace recorded by rr but as a result of
various refactorings done to implement follow exec mode this broke.
Restore the functionality.

Also remove the _fixtures/testfnpos.go file which is autogenerated
during testing.
  • Loading branch information
aarzilli committed Jan 3, 2024
1 parent 3372f5c commit cc73c73
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 22 deletions.
16 changes: 0 additions & 16 deletions _fixtures/testfnpos.go

This file was deleted.

4 changes: 4 additions & 0 deletions pkg/proc/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ func (p *process) Detach(int, bool) error {
return nil
}

func (p *process) Close() error {
return nil
}

// Valid returns whether the process is active. Always returns true
// for core files as it cannot exit or be otherwise detached from.
func (p *process) Valid() (bool, error) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/proc/gdbserial/gdbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ func (p *gdbProcess) Detach(_pid int, kill bool) error {
p.process = nil
}
p.detached = true
return nil
}

func (p *gdbProcess) Close() error {
if p.onDetach != nil {
p.onDetach()
}
Expand Down
1 change: 1 addition & 0 deletions pkg/proc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ProcessGroup interface {
ContinueOnce(*ContinueOnceContext) (Thread, StopReason, error)
StepInstruction(int) error
Detach(int, bool) error
Close() error
}

// Process represents the target of the debugger. This
Expand Down
4 changes: 4 additions & 0 deletions pkg/proc/native/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (procgrp *processGroup) Detach(pid int, kill bool) (err error) {
return
}

func (procgrp *processGroup) Close() error {
return nil
}

// Valid returns whether the process is still attached to and
// has not exited.
func (dbp *nativeProcess) Valid() (bool, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/proc/target_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,12 +1091,13 @@ func skipAutogeneratedWrappersOut(tgt *Target, g *G, thread Thread, startTopfram
if err != nil {
return
}
bi := thread.BinInfo()
for i := 1; i < len(frames); i++ {
frame := frames[i]
if frame.Current.Fn == nil {
return
}
file, line := g.Thread.BinInfo().EntryLineForFunc(frame.Current.Fn)
file, line := bi.EntryLineForFunc(frame.Current.Fn)
if !isAutogeneratedOrDeferReturn(Location{File: file, Line: line, Fn: frame.Current.Fn}) {
return &frames[i-1], &frames[i]
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/proc/target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (grp *TargetGroup) Detach(kill bool) error {
if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n"))
}
return nil
return grp.procgrp.Close()
}

// detachTarget will detach the target from the underlying process.
Expand Down
3 changes: 0 additions & 3 deletions service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,6 @@ func (d *Debugger) Detach(kill bool) error {
d.log.Debug("detaching")
d.targetMutex.Lock()
defer d.targetMutex.Unlock()
if ok, _ := d.target.Valid(); !ok {
return nil
}
return d.detach(kill)
}

Expand Down
3 changes: 2 additions & 1 deletion service/test/integration2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2828,11 +2828,12 @@ func TestRestart_PreserveFunctionBreakpoint(t *testing.T) {
// even if the function changed position in the source file.

dir := protest.FindFixturesDir()
outpath := filepath.Join(dir, "testfnpos.go")
defer os.Remove(outpath)

copy := func(inpath string) {
buf, err := os.ReadFile(inpath)
assertNoError(err, t, fmt.Sprintf("Reading %q", inpath))
outpath := filepath.Join(dir, "testfnpos.go")
assertNoError(os.WriteFile(outpath, buf, 0o666), t, fmt.Sprintf("Creating %q", outpath))
}

Expand Down

0 comments on commit cc73c73

Please sign in to comment.