Skip to content

Commit

Permalink
feat: print a message when the debuggee process exits
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeng-grabtaxi committed Nov 27, 2024
1 parent 822014b commit 1580380
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc
state.Exited = true
state.ExitStatus = errProcessExited.Status
state.Err = errProcessExited
d.maybePrintUnattendedStopWarning(proc.StopExited, state.CurrentThread, clientStatusCh)
return state, nil
}
return nil, err
Expand All @@ -1341,7 +1342,7 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc
d.amendBreakpoint(bp)
}

d.maybePrintUnattendedBreakpointWarning(d.target.Selected.StopReason, state.CurrentThread, clientStatusCh)
d.maybePrintUnattendedStopWarning(d.target.Selected.StopReason, state.CurrentThread, clientStatusCh)
return state, err
}

Expand Down Expand Up @@ -2499,7 +2500,7 @@ func attachErrorMessageDefault(pid int, err error) error {
return fmt.Errorf("could not attach to pid %d: %s", pid, err)
}

func (d *Debugger) maybePrintUnattendedBreakpointWarning(stopReason proc.StopReason, currentThread *api.Thread, clientStatusCh <-chan struct{}) {
func (d *Debugger) maybePrintUnattendedStopWarning(stopReason proc.StopReason, currentThread *api.Thread, clientStatusCh <-chan struct{}) {
select {
case <-clientStatusCh:
// the channel will be closed if the client that sends the command has left
Expand All @@ -2508,6 +2509,17 @@ func (d *Debugger) maybePrintUnattendedBreakpointWarning(stopReason proc.StopRea
return
}

if currentThread == nil || currentThread.Breakpoint == nil {
switch stopReason {
case proc.StopManual:
// print nothing
return
default:
fmt.Fprintln(os.Stderr, "Stop reason: "+stopReason.String())
return
}
}

const defaultStackTraceDepth = 50
frames, err := d.stacktrace(currentThread.GoroutineID, defaultStackTraceDepth, 0)
if err != nil {
Expand All @@ -2522,17 +2534,6 @@ func (d *Debugger) maybePrintUnattendedBreakpointWarning(stopReason proc.StopRea
}

bp := currentThread.Breakpoint
if bp == nil {
switch stopReason {
case proc.StopManual:
// print nothing
return
default:
fmt.Fprintln(os.Stderr, "Stop reason: "+stopReason.String())
return
}
}

switch bp.Name {
case proc.FatalThrow, proc.UnrecoveredPanic:
fmt.Fprintln(os.Stderr, "\n** execution is paused because your program is panicking **")
Expand Down

0 comments on commit 1580380

Please sign in to comment.