Example #1
0
// State returns the current state of the debugger.
func (d *Debugger) State() (*api.DebuggerState, error) {
	if d.process.Exited() {
		return nil, proc.ProcessExitedError{Pid: d.ProcessPid()}
	}

	var (
		state     *api.DebuggerState
		goroutine *api.Goroutine
	)

	if d.process.SelectedGoroutine != nil {
		goroutine = api.ConvertGoroutine(d.process.SelectedGoroutine)
	}

	state = &api.DebuggerState{
		SelectedGoroutine: goroutine,
		Exited:            d.process.Exited(),
	}

	for i := range d.process.Threads {
		th := api.ConvertThread(d.process.Threads[i])
		state.Threads = append(state.Threads, th)
		if i == d.process.CurrentThread.ID {
			state.CurrentThread = th
		}
	}

	return state, nil
}