types.go 5.0 KB
Newer Older
D
Dan Mace 已提交
1 2 3 4
package api

// DebuggerState represents the current context of the debugger.
type DebuggerState struct {
D
Derek Parker 已提交
5
	// Breakpoint is the current breakpoint at which the debugged process is
D
Dan Mace 已提交
6
	// suspended, and may be empty if the process is not suspended.
D
Derek Parker 已提交
7
	Breakpoint *Breakpoint `json:"breakPoint,omitempty"`
D
Dan Mace 已提交
8 9
	// CurrentThread is the currently selected debugger thread.
	CurrentThread *Thread `json:"currentThread,omitempty"`
10 11
	// SelectedGoroutine is the currently selected goroutine
	SelectedGoroutine *Goroutine `json:"currentGoroutine,omitempty"`
A
aarzilli 已提交
12 13
	// Information requested by the current breakpoint
	BreakpointInfo *BreakpointInfo `json:"breakPointInfo,omitrempty"`
D
Dan Mace 已提交
14
	// Exited indicates whether the debugged process has exited.
15 16
	Exited     bool `json:"exited"`
	ExitStatus int  `json:"exitStatus"`
A
aarzilli 已提交
17 18 19

	// Filled by RPCClient.Continue, indicates an error
	Err error `json:"-"`
D
Dan Mace 已提交
20 21
}

D
Derek Parker 已提交
22
// Breakpoint addresses a location at which process execution may be
D
Dan Mace 已提交
23
// suspended.
D
Derek Parker 已提交
24
type Breakpoint struct {
D
Dan Mace 已提交
25 26 27 28 29 30 31 32 33 34 35
	// ID is a unique identifier for the breakpoint.
	ID int `json:"id"`
	// Addr is the address of the breakpoint.
	Addr uint64 `json:"addr"`
	// File is the source file for the breakpoint.
	File string `json:"file"`
	// Line is a line in File for the breakpoint.
	Line int `json:"line"`
	// FunctionName is the name of the function at the current breakpoint, and
	// may not always be available.
	FunctionName string `json:"functionName,omitempty"`
A
aarzilli 已提交
36 37 38 39 40 41 42 43

	// tracepoint flag
	Tracepoint bool `json:"continue"`
	// number of stack frames to retrieve
	Stacktrace int `json:"stacktrace"`
	// retrieve goroutine information
	Goroutine bool `json:"goroutine"`
	// variables to evaluate
D
Derek Parker 已提交
44
	Variables []string `json:"variables,omitempty"`
D
Dan Mace 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
}

// Thread is a thread within the debugged process.
type Thread struct {
	// ID is a unique identifier for the thread.
	ID int `json:"id"`
	// PC is the current program counter for the thread.
	PC uint64 `json:"pc"`
	// File is the file for the program counter.
	File string `json:"file"`
	// Line is the line number for the program counter.
	Line int `json:"line"`
	// Function is function information at the program counter. May be nil.
	Function *Function `json:"function,omitempty"`
}

A
aarzilli 已提交
61 62 63 64 65 66 67
type Location struct {
	PC       uint64    `json:"pc"`
	File     string    `json:"file"`
	Line     int       `json:"line"`
	Function *Function `json:"function,omitempty"`
}

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
type Stackframe struct {
	Location
	Locals    []Variable
	Arguments []Variable
}

func (frame *Stackframe) Var(name string) *Variable {
	for i := range frame.Locals {
		if frame.Locals[i].Name == name {
			return &frame.Locals[i]
		}
	}
	for i := range frame.Arguments {
		if frame.Arguments[i].Name == name {
			return &frame.Arguments[i]
		}
	}
	return nil
}

D
Dan Mace 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
// Function represents thread-scoped function information.
type Function struct {
	// Name is the function name.
	Name   string `json:"name"`
	Value  uint64 `json:"value"`
	Type   byte   `json:"type"`
	GoType uint64 `json:"goType"`
	// Args are the function arguments in a thread context.
	Args []Variable `json:"args"`
	// Locals are the thread local variables.
	Locals []Variable `json:"locals"`
}

// Variable describes a variable.
type Variable struct {
	Name  string `json:"name"`
	Value string `json:"value"`
	Type  string `json:"type"`
}

// Goroutine represents the information relevant to Delve from the runtime's
// internal G structure.
type Goroutine struct {
	// ID is a unique identifier for the goroutine.
	ID int `json:"id"`
	// PC is the current program counter for the goroutine.
	PC uint64 `json:"pc"`
	// File is the file for the program counter.
	File string `json:"file"`
	// Line is the line number for the program counter.
	Line int `json:"line"`
	// Function is function information at the program counter. May be nil.
	Function *Function `json:"function,omitempty"`
}

// DebuggerCommand is a command which changes the debugger's execution state.
type DebuggerCommand struct {
	// Name is the command to run.
	Name string `json:"name"`
	// ThreadID is used to specify which thread to use with the SwitchThread
	// command.
	ThreadID int `json:"threadID,omitempty"`
130 131 132
	// GoroutineID is used to specify which thread to use with the SwitchGoroutine
	// command.
	GoroutineID int `json:"goroutineID,omitempty"`
D
Dan Mace 已提交
133 134
}

A
aarzilli 已提交
135 136
// Informations about the current breakpoint
type BreakpointInfo struct {
137 138 139 140
	Stacktrace []Stackframe `json:"stacktrace,omitempty"`
	Goroutine  *Goroutine   `json:"goroutine,omitempty"`
	Variables  []Variable   `json:"variables,omitempty"`
	Arguments  []Variable   `json:"arguments,omitempty"`
A
aarzilli 已提交
141 142
}

143 144 145 146 147
type EvalScope struct {
	GoroutineID int
	Frame       int
}

D
Dan Mace 已提交
148 149 150 151 152 153 154 155 156
const (
	// Continue resumes process execution.
	Continue = "continue"
	// Step continues for a single instruction, entering function calls.
	Step = "step"
	// Next continues to the next source line, not entering function calls.
	Next = "next"
	// SwitchThread switches the debugger's current thread context.
	SwitchThread = "switchThread"
157 158
	// SwitchGoroutine switches the debugger's current thread context to the thread running the specified goroutine
	SwitchGoroutine = "switchGoroutine"
D
Dan Mace 已提交
159 160 161
	// Halt suspends the process.
	Halt = "halt"
)