terminal: print something when continue errors even if we don't have a file

We should print something when we exit from continue/next/step/stepout
even if we don't have a source file for the instruction that we are
stopped on.

This is mostly important on macOS where a SIGSEGV will cause 'continue'
to fail with a 'bad access' error (see #852) and the output can be
confusing.

Fixes #1244
This commit is contained in:
aarzilli
2018-09-01 15:18:34 +02:00
committed by Derek Parker
parent 43d43316cd
commit 3a9431388a

View File

@ -848,10 +848,12 @@ func restart(t *Term, ctx callContext, args string) error {
return nil return nil
} }
func printfileNoState(t *Term) { func printcontextNoState(t *Term) {
if state, _ := t.client.GetState(); state != nil && state.CurrentThread != nil { state, _ := t.client.GetState()
printfile(t, state.CurrentThread.File, state.CurrentThread.Line, true) if state == nil || state.CurrentThread == nil {
return
} }
printcontext(t, state)
} }
func (c *Commands) cont(t *Term, ctx callContext, args string) error { func (c *Commands) cont(t *Term, ctx callContext, args string) error {
@ -860,7 +862,7 @@ func (c *Commands) cont(t *Term, ctx callContext, args string) error {
var state *api.DebuggerState var state *api.DebuggerState
for state = range stateChan { for state = range stateChan {
if state.Err != nil { if state.Err != nil {
printfileNoState(t) printcontextNoState(t)
return state.Err return state.Err
} }
printcontext(t, state) printcontext(t, state)
@ -880,7 +882,7 @@ func continueUntilCompleteNext(t *Term, state *api.DebuggerState, op string) err
var state *api.DebuggerState var state *api.DebuggerState
for state = range stateChan { for state = range stateChan {
if state.Err != nil { if state.Err != nil {
printfileNoState(t) printcontextNoState(t)
return state.Err return state.Err
} }
printcontext(t, state) printcontext(t, state)
@ -916,7 +918,7 @@ func (c *Commands) step(t *Term, ctx callContext, args string) error {
c.frame = 0 c.frame = 0
state, err := exitedToError(t.client.Step()) state, err := exitedToError(t.client.Step())
if err != nil { if err != nil {
printfileNoState(t) printcontextNoState(t)
return err return err
} }
printcontext(t, state) printcontext(t, state)
@ -934,7 +936,7 @@ func (c *Commands) stepInstruction(t *Term, ctx callContext, args string) error
} }
state, err := exitedToError(t.client.StepInstruction()) state, err := exitedToError(t.client.StepInstruction())
if err != nil { if err != nil {
printfileNoState(t) printcontextNoState(t)
return err return err
} }
printcontext(t, state) printcontext(t, state)
@ -951,7 +953,7 @@ func (c *Commands) next(t *Term, ctx callContext, args string) error {
} }
state, err := exitedToError(t.client.Next()) state, err := exitedToError(t.client.Next())
if err != nil { if err != nil {
printfileNoState(t) printcontextNoState(t)
return err return err
} }
printcontext(t, state) printcontext(t, state)
@ -967,7 +969,7 @@ func (c *Commands) stepout(t *Term, ctx callContext, args string) error {
} }
state, err := exitedToError(t.client.StepOut()) state, err := exitedToError(t.client.StepOut())
if err != nil { if err != nil {
printfileNoState(t) printcontextNoState(t)
return err return err
} }
printcontext(t, state) printcontext(t, state)
@ -981,7 +983,7 @@ func (c *Commands) call(t *Term, ctx callContext, args string) error {
state, err := exitedToError(t.client.Call(args)) state, err := exitedToError(t.client.Call(args))
c.frame = 0 c.frame = 0
if err != nil { if err != nil {
printfileNoState(t) printcontextNoState(t)
return err return err
} }
printcontext(t, state) printcontext(t, state)
@ -1591,7 +1593,7 @@ func printStack(stack []api.Stackframe, ind string, offsets bool) {
} }
} }
func printcontext(t *Term, state *api.DebuggerState) error { func printcontext(t *Term, state *api.DebuggerState) {
for i := range state.Threads { for i := range state.Threads {
if (state.CurrentThread != nil) && (state.Threads[i].ID == state.CurrentThread.ID) { if (state.CurrentThread != nil) && (state.Threads[i].ID == state.CurrentThread.ID) {
continue continue
@ -1603,7 +1605,7 @@ func printcontext(t *Term, state *api.DebuggerState) error {
if state.CurrentThread == nil { if state.CurrentThread == nil {
fmt.Println("No current thread available") fmt.Println("No current thread available")
return nil return
} }
var th *api.Thread var th *api.Thread
@ -1618,14 +1620,14 @@ func printcontext(t *Term, state *api.DebuggerState) error {
} }
if th == nil { if th == nil {
printcontextLocation(state.SelectedGoroutine.CurrentLoc) printcontextLocation(state.SelectedGoroutine.CurrentLoc)
return nil return
} }
} }
if th.File == "" { if th.File == "" {
fmt.Printf("Stopped at: 0x%x\n", state.CurrentThread.PC) fmt.Printf("Stopped at: 0x%x\n", state.CurrentThread.PC)
t.Println("=>", "no source available") t.Println("=>", "no source available")
return nil return
} }
printcontextThread(t, th) printcontextThread(t, th)
@ -1633,8 +1635,6 @@ func printcontext(t *Term, state *api.DebuggerState) error {
if state.When != "" { if state.When != "" {
fmt.Println(state.When) fmt.Println(state.When)
} }
return nil
} }
func printcontextLocation(loc api.Location) { func printcontextLocation(loc api.Location) {