2020-02-21 17:05:30 +00:00
|
|
|
// Package daptest provides a sample client with utilities
|
|
|
|
// for DAP mode testing.
|
2020-02-15 19:52:53 +00:00
|
|
|
package daptest
|
|
|
|
|
2021-05-06 09:11:45 +00:00
|
|
|
//go:generate go run ./gen/main.go -o ./resp.go
|
|
|
|
|
2020-02-15 19:52:53 +00:00
|
|
|
import (
|
|
|
|
"bufio"
|
2021-05-06 09:11:45 +00:00
|
|
|
"encoding/json"
|
2020-02-15 19:52:53 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"path/filepath"
|
2021-05-06 09:11:45 +00:00
|
|
|
"reflect"
|
2021-04-12 21:50:15 +00:00
|
|
|
"regexp"
|
2020-02-24 17:36:34 +00:00
|
|
|
"testing"
|
2020-02-15 19:52:53 +00:00
|
|
|
|
|
|
|
"github.com/google/go-dap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Client is a debugger service client that uses Debug Adaptor Protocol.
|
|
|
|
// It does not (yet?) implement service.Client interface.
|
|
|
|
// All client methods are synchronous.
|
|
|
|
type Client struct {
|
|
|
|
conn net.Conn
|
|
|
|
reader *bufio.Reader
|
|
|
|
// seq is used to track the sequence number of each
|
|
|
|
// requests that the client sends to the server
|
|
|
|
seq int
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient creates a new Client over a TCP connection.
|
|
|
|
// Call Close() to close the connection.
|
|
|
|
func NewClient(addr string) *Client {
|
|
|
|
fmt.Println("Connecting to server at:", addr)
|
|
|
|
conn, err := net.Dial("tcp", addr)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("dialing:", err)
|
|
|
|
}
|
|
|
|
c := &Client{conn: conn, reader: bufio.NewReader(conn)}
|
2020-03-10 19:29:06 +00:00
|
|
|
c.seq = 1 // match VS Code numbering
|
2020-02-15 19:52:53 +00:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2020-02-21 17:05:30 +00:00
|
|
|
// Close closes the client connection.
|
2020-02-15 19:52:53 +00:00
|
|
|
func (c *Client) Close() {
|
|
|
|
c.conn.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) send(request dap.Message) {
|
|
|
|
dap.WriteProtocolMessage(c.conn, request)
|
|
|
|
}
|
|
|
|
|
2020-02-27 04:45:48 +00:00
|
|
|
func (c *Client) ReadMessage() (dap.Message, error) {
|
|
|
|
return dap.ReadProtocolMessage(c.reader)
|
|
|
|
}
|
|
|
|
|
2021-04-08 09:09:41 +00:00
|
|
|
func (c *Client) ExpectMessage(t *testing.T) dap.Message {
|
2020-02-24 17:36:34 +00:00
|
|
|
t.Helper()
|
|
|
|
m, err := dap.ReadProtocolMessage(c.reader)
|
2020-02-15 19:52:53 +00:00
|
|
|
if err != nil {
|
2021-04-08 09:09:41 +00:00
|
|
|
t.Fatal(err)
|
2020-02-15 19:52:53 +00:00
|
|
|
}
|
2020-02-24 17:36:34 +00:00
|
|
|
return m
|
2020-02-15 19:52:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 09:11:45 +00:00
|
|
|
func (c *Client) ExpectInvisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
|
2020-02-24 17:36:34 +00:00
|
|
|
t.Helper()
|
2021-05-06 09:11:45 +00:00
|
|
|
er := c.ExpectErrorResponse(t)
|
2020-11-12 23:24:31 +00:00
|
|
|
if er.Body.Error.ShowUser {
|
|
|
|
t.Errorf("\ngot %#v\nwant ShowUser=false", er)
|
|
|
|
}
|
|
|
|
return er
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ExpectVisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
|
|
|
|
t.Helper()
|
2021-05-06 09:11:45 +00:00
|
|
|
er := c.ExpectErrorResponse(t)
|
2020-11-12 23:24:31 +00:00
|
|
|
if !er.Body.Error.ShowUser {
|
|
|
|
t.Errorf("\ngot %#v\nwant ShowUser=true", er)
|
|
|
|
}
|
|
|
|
return er
|
2020-02-24 17:36:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 19:24:44 +00:00
|
|
|
func (c *Client) expectErrorResponse(t *testing.T, id int, message string) *dap.ErrorResponse {
|
2020-02-24 17:36:34 +00:00
|
|
|
t.Helper()
|
2021-05-06 09:11:45 +00:00
|
|
|
er := c.ExpectErrorResponse(t)
|
2020-05-01 19:24:44 +00:00
|
|
|
if er.Body.Error.Id != id || er.Message != message {
|
|
|
|
t.Errorf("\ngot %#v\nwant Id=%d Message=%q", er, id, message)
|
|
|
|
}
|
|
|
|
return er
|
|
|
|
}
|
|
|
|
|
2021-05-06 09:11:45 +00:00
|
|
|
func (c *Client) ExpectInitializeResponseAndCapabilities(t *testing.T) *dap.InitializeResponse {
|
2020-02-24 17:36:34 +00:00
|
|
|
t.Helper()
|
2021-05-06 09:11:45 +00:00
|
|
|
initResp := c.ExpectInitializeResponse(t)
|
|
|
|
wantCapabilities := dap.Capabilities{
|
|
|
|
// the values set by dap.(*Server).onInitializeRequest.
|
|
|
|
SupportsConfigurationDoneRequest: true,
|
|
|
|
SupportsConditionalBreakpoints: true,
|
|
|
|
SupportsDelayedStackTraceLoading: true,
|
|
|
|
SupportTerminateDebuggee: true,
|
2021-05-17 16:25:41 +00:00
|
|
|
SupportsExceptionInfoRequest: true,
|
dap: handle SetVariable requests (#2440)
* dap: handle SetVariable requests
The handler invokes debugger.SetVariableInScope, except for
string type variables. For which, we rely on the `call` command.
Moved the call expression handling logic to the new `doCall`
function, so it can be reused by the SetVariable requenst
handler.
With this PR, every successful SetVariable request triggers
a StoppedEvent - that's a hack to reset the variablesHandle
map internally and notify the client of this change. It will
be nice if we can just update cached data corresponding to
the updated variable. But I cannot find an easy and safe way
to achieve this yet.
Also fixed a small bug in the call expression evaluation -
Previously, dlv dap returned an error "Unable to evaluate
expression: call stopped" if the call expression is for
variable assignment. (e.g. "call animal = "rabbit").
* dap: address comments from aarzilli
resetHandlesForStop & sendStoppedEvent unconditionally after
call command is left as a TODO - This is an existing code path
(just refactored) and an preexisting bug. Fixing it here
requires updates in TestEvaluateCallRequest and I prefer
addressing it in a separate cl.
Disabled call injection testing on arm64. Separated TestSetVariable
into two, one that doesn't involve call injection and another that
may involve call injection.
Fixed variableByName by removing unnecessary recursion.
* dap: address polina's comments
- removed the hard reset for every variable set
- added tests for various variable types
- added tests that involves interrupted function calls. (breakpoint/panic)
And,
- changed to utilize EvalVariableInScope to access the variable instead
of searching the children by name.
- changed to utilize evaluate requests when verifying whether the variable
is changed as expected in testing. Since now we avoid resetting the variable
handles after variable reset, either we need to trigger scope changes
explicitly, or stop depending on the variables request.
* dap: address comments
- Discuss the problem around the current doCall implementation
and the implication.
- Refine the description on how VS Code handles after setVariable
and evaluate request (there could be followup scopes/evaluate requests).
- Use the explicit line numbers for breakpoints in the SetVariable tests.
- Do not use errors.Is - we could've used golang.org/x/xerrors polyfill
but that's an additional dependency, and we will remove this check once
tests that depend on old behavior are fixed.
* dap: remove errTerminated and adjust the test
* dap: evaluate in the outer frame, instead of advancing to the next bp
2021-05-20 17:05:47 +00:00
|
|
|
SupportsSetVariable: true,
|
2021-05-18 17:25:16 +00:00
|
|
|
SupportsFunctionBreakpoints: true,
|
2021-05-19 18:17:36 +00:00
|
|
|
SupportsEvaluateForHovers: true,
|
2021-06-04 07:27:57 +00:00
|
|
|
SupportsClipboardContext: true,
|
2021-05-06 09:11:45 +00:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(initResp.Body, wantCapabilities) {
|
|
|
|
t.Errorf("capabilities in initializeResponse: got %+v, want %v", pretty(initResp.Body), pretty(wantCapabilities))
|
2020-02-15 19:52:53 +00:00
|
|
|
}
|
2020-02-24 17:36:34 +00:00
|
|
|
return initResp
|
|
|
|
}
|
|
|
|
|
2021-05-06 09:11:45 +00:00
|
|
|
func pretty(v interface{}) string {
|
|
|
|
s, _ := json.MarshalIndent(v, "", "\t")
|
|
|
|
return string(s)
|
2020-02-24 17:36:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 09:11:45 +00:00
|
|
|
func (c *Client) ExpectNotYetImplementedErrorResponse(t *testing.T) *dap.ErrorResponse {
|
2020-02-24 17:36:34 +00:00
|
|
|
t.Helper()
|
2021-05-06 09:11:45 +00:00
|
|
|
return c.expectErrorResponse(t, 7777, "Not yet implemented")
|
2020-02-24 17:36:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 09:11:45 +00:00
|
|
|
func (c *Client) ExpectUnsupportedCommandErrorResponse(t *testing.T) *dap.ErrorResponse {
|
2020-08-24 17:21:51 +00:00
|
|
|
t.Helper()
|
2021-05-06 09:11:45 +00:00
|
|
|
return c.expectErrorResponse(t, 9999, "Unsupported command")
|
2020-08-24 17:21:51 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:50:15 +00:00
|
|
|
func (c *Client) ExpectOutputEventRegex(t *testing.T, want string) *dap.OutputEvent {
|
|
|
|
t.Helper()
|
2021-05-06 09:11:45 +00:00
|
|
|
e := c.ExpectOutputEvent(t)
|
2021-04-12 21:50:15 +00:00
|
|
|
if matched, _ := regexp.MatchString(want, e.Body.Output); !matched {
|
|
|
|
t.Errorf("\ngot %#v\nwant Output=%q", e, want)
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ExpectOutputEventProcessExited(t *testing.T, status int) *dap.OutputEvent {
|
|
|
|
t.Helper()
|
|
|
|
return c.ExpectOutputEventRegex(t, fmt.Sprintf(`Process [0-9]+ has exited with status %d\n`, status))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ExpectOutputEventDetaching(t *testing.T) *dap.OutputEvent {
|
|
|
|
t.Helper()
|
|
|
|
return c.ExpectOutputEventRegex(t, `Detaching\n`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ExpectOutputEventDetachingKill(t *testing.T) *dap.OutputEvent {
|
|
|
|
t.Helper()
|
|
|
|
return c.ExpectOutputEventRegex(t, `Detaching and terminating target process\n`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ExpectOutputEventDetachingNoKill(t *testing.T) *dap.OutputEvent {
|
|
|
|
t.Helper()
|
|
|
|
return c.ExpectOutputEventRegex(t, `Detaching without terminating target process\n`)
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:52:53 +00:00
|
|
|
// InitializeRequest sends an 'initialize' request.
|
|
|
|
func (c *Client) InitializeRequest() {
|
|
|
|
request := &dap.InitializeRequest{Request: *c.newRequest("initialize")}
|
|
|
|
request.Arguments = dap.InitializeRequestArguments{
|
|
|
|
AdapterID: "go",
|
|
|
|
PathFormat: "path",
|
|
|
|
LinesStartAt1: true,
|
|
|
|
ColumnsStartAt1: true,
|
|
|
|
SupportsVariableType: true,
|
|
|
|
SupportsVariablePaging: true,
|
|
|
|
SupportsRunInTerminalRequest: true,
|
|
|
|
Locale: "en-us",
|
|
|
|
}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2021-05-06 07:56:29 +00:00
|
|
|
// InitializeRequestWithArgs sends an 'initialize' request with specified arguments.
|
|
|
|
func (c *Client) InitializeRequestWithArgs(args dap.InitializeRequestArguments) {
|
|
|
|
request := &dap.InitializeRequest{Request: *c.newRequest("initialize")}
|
|
|
|
request.Arguments = args
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:22:51 +00:00
|
|
|
// LaunchRequest sends a 'launch' request with the specified args.
|
2021-04-08 09:09:41 +00:00
|
|
|
func (c *Client) LaunchRequest(mode, program string, stopOnEntry bool) {
|
2020-02-15 19:52:53 +00:00
|
|
|
request := &dap.LaunchRequest{Request: *c.newRequest("launch")}
|
|
|
|
request.Arguments = map[string]interface{}{
|
|
|
|
"request": "launch",
|
2020-03-04 17:22:51 +00:00
|
|
|
"mode": mode,
|
2020-02-15 19:52:53 +00:00
|
|
|
"program": program,
|
|
|
|
"stopOnEntry": stopOnEntry,
|
|
|
|
}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:22:51 +00:00
|
|
|
// LaunchRequestWithArgs takes a map of untyped implementation-specific
|
|
|
|
// arguments to send a 'launch' request. This version can be used to
|
|
|
|
// test for values of unexpected types or unspecified values.
|
|
|
|
func (c *Client) LaunchRequestWithArgs(arguments map[string]interface{}) {
|
|
|
|
request := &dap.LaunchRequest{Request: *c.newRequest("launch")}
|
|
|
|
request.Arguments = arguments
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-12-28 17:14:15 +00:00
|
|
|
// AttachRequest sends an 'attach' request with the specified
|
|
|
|
// arguments.
|
|
|
|
func (c *Client) AttachRequest(arguments map[string]interface{}) {
|
2020-05-01 19:24:44 +00:00
|
|
|
request := &dap.AttachRequest{Request: *c.newRequest("attach")}
|
2020-12-28 17:14:15 +00:00
|
|
|
request.Arguments = arguments
|
2020-05-01 19:24:44 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:52:53 +00:00
|
|
|
// DisconnectRequest sends a 'disconnect' request.
|
|
|
|
func (c *Client) DisconnectRequest() {
|
|
|
|
request := &dap.DisconnectRequest{Request: *c.newRequest("disconnect")}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-12-28 17:14:15 +00:00
|
|
|
// DisconnectRequest sends a 'disconnect' request with an option to specify
|
|
|
|
// `terminateDebuggee`.
|
|
|
|
func (c *Client) DisconnectRequestWithKillOption(kill bool) {
|
|
|
|
request := &dap.DisconnectRequest{Request: *c.newRequest("disconnect")}
|
|
|
|
request.Arguments.TerminateDebuggee = kill
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:52:53 +00:00
|
|
|
// SetBreakpointsRequest sends a 'setBreakpoints' request.
|
|
|
|
func (c *Client) SetBreakpointsRequest(file string, lines []int) {
|
2020-10-02 16:18:33 +00:00
|
|
|
c.SetConditionalBreakpointsRequest(file, lines, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBreakpointsRequest sends a 'setBreakpoints' request with conditions.
|
|
|
|
func (c *Client) SetConditionalBreakpointsRequest(file string, lines []int, conditions map[int]string) {
|
2020-02-15 19:52:53 +00:00
|
|
|
request := &dap.SetBreakpointsRequest{Request: *c.newRequest("setBreakpoints")}
|
|
|
|
request.Arguments = dap.SetBreakpointsArguments{
|
|
|
|
Source: dap.Source{
|
|
|
|
Name: filepath.Base(file),
|
|
|
|
Path: file,
|
|
|
|
},
|
|
|
|
Breakpoints: make([]dap.SourceBreakpoint, len(lines)),
|
|
|
|
}
|
|
|
|
for i, l := range lines {
|
|
|
|
request.Arguments.Breakpoints[i].Line = l
|
2020-10-02 16:18:33 +00:00
|
|
|
cond, ok := conditions[l]
|
|
|
|
if ok {
|
|
|
|
request.Arguments.Breakpoints[i].Condition = cond
|
|
|
|
}
|
2020-02-15 19:52:53 +00:00
|
|
|
}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2021-05-28 18:21:53 +00:00
|
|
|
// SetBreakpointsRequest sends a 'setBreakpoints' request with conditions.
|
|
|
|
func (c *Client) SetHitConditionalBreakpointsRequest(file string, lines []int, conditions map[int]string) {
|
|
|
|
request := &dap.SetBreakpointsRequest{Request: *c.newRequest("setBreakpoints")}
|
|
|
|
request.Arguments = dap.SetBreakpointsArguments{
|
|
|
|
Source: dap.Source{
|
|
|
|
Name: filepath.Base(file),
|
|
|
|
Path: file,
|
|
|
|
},
|
|
|
|
Breakpoints: make([]dap.SourceBreakpoint, len(lines)),
|
|
|
|
}
|
|
|
|
for i, l := range lines {
|
|
|
|
request.Arguments.Breakpoints[i].Line = l
|
|
|
|
cond, ok := conditions[l]
|
|
|
|
if ok {
|
|
|
|
request.Arguments.Breakpoints[i].HitCondition = cond
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:52:53 +00:00
|
|
|
// SetExceptionBreakpointsRequest sends a 'setExceptionBreakpoints' request.
|
|
|
|
func (c *Client) SetExceptionBreakpointsRequest() {
|
|
|
|
request := &dap.SetBreakpointsRequest{Request: *c.newRequest("setExceptionBreakpoints")}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigurationDoneRequest sends a 'configurationDone' request.
|
|
|
|
func (c *Client) ConfigurationDoneRequest() {
|
|
|
|
request := &dap.ConfigurationDoneRequest{Request: *c.newRequest("configurationDone")}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContinueRequest sends a 'continue' request.
|
|
|
|
func (c *Client) ContinueRequest(thread int) {
|
|
|
|
request := &dap.ContinueRequest{Request: *c.newRequest("continue")}
|
|
|
|
request.Arguments.ThreadId = thread
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-05-01 19:24:44 +00:00
|
|
|
// NextRequest sends a 'next' request.
|
2020-08-24 17:21:51 +00:00
|
|
|
func (c *Client) NextRequest(thread int) {
|
2020-05-01 19:24:44 +00:00
|
|
|
request := &dap.NextRequest{Request: *c.newRequest("next")}
|
2020-08-24 17:21:51 +00:00
|
|
|
request.Arguments.ThreadId = thread
|
2020-05-01 19:24:44 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StepInRequest sends a 'stepIn' request.
|
2020-08-24 17:21:51 +00:00
|
|
|
func (c *Client) StepInRequest(thread int) {
|
2020-05-01 19:24:44 +00:00
|
|
|
request := &dap.NextRequest{Request: *c.newRequest("stepIn")}
|
2020-08-24 17:21:51 +00:00
|
|
|
request.Arguments.ThreadId = thread
|
2020-05-01 19:24:44 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StepOutRequest sends a 'stepOut' request.
|
2020-08-24 17:21:51 +00:00
|
|
|
func (c *Client) StepOutRequest(thread int) {
|
2020-05-01 19:24:44 +00:00
|
|
|
request := &dap.NextRequest{Request: *c.newRequest("stepOut")}
|
2020-08-24 17:21:51 +00:00
|
|
|
request.Arguments.ThreadId = thread
|
2020-05-01 19:24:44 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PauseRequest sends a 'pause' request.
|
2021-05-17 17:37:15 +00:00
|
|
|
func (c *Client) PauseRequest(threadId int) {
|
|
|
|
request := &dap.PauseRequest{Request: *c.newRequest("pause")}
|
|
|
|
request.Arguments.ThreadId = threadId
|
2020-05-01 19:24:44 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-03-10 19:29:06 +00:00
|
|
|
// ThreadsRequest sends a 'threads' request.
|
|
|
|
func (c *Client) ThreadsRequest() {
|
|
|
|
request := &dap.ThreadsRequest{Request: *c.newRequest("threads")}
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StackTraceRequest sends a 'stackTrace' request.
|
2020-07-01 18:01:17 +00:00
|
|
|
func (c *Client) StackTraceRequest(threadID, startFrame, levels int) {
|
2020-03-10 19:29:06 +00:00
|
|
|
request := &dap.StackTraceRequest{Request: *c.newRequest("stackTrace")}
|
2020-07-01 18:01:17 +00:00
|
|
|
request.Arguments.ThreadId = threadID
|
|
|
|
request.Arguments.StartFrame = startFrame
|
|
|
|
request.Arguments.Levels = levels
|
2020-03-10 19:29:06 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-05-01 19:24:44 +00:00
|
|
|
// ScopesRequest sends a 'scopes' request.
|
2020-08-11 15:34:27 +00:00
|
|
|
func (c *Client) ScopesRequest(frameID int) {
|
2020-05-01 19:24:44 +00:00
|
|
|
request := &dap.ScopesRequest{Request: *c.newRequest("scopes")}
|
2020-08-11 15:34:27 +00:00
|
|
|
request.Arguments.FrameId = frameID
|
2020-05-01 19:24:44 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-08-11 15:34:27 +00:00
|
|
|
// VariablesRequest sends a 'variables' request.
|
|
|
|
func (c *Client) VariablesRequest(variablesReference int) {
|
|
|
|
request := &dap.VariablesRequest{Request: *c.newRequest("variables")}
|
|
|
|
request.Arguments.VariablesReference = variablesReference
|
2020-05-01 19:24:44 +00:00
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2021-06-10 16:34:20 +00:00
|
|
|
// IndexedVariablesRequest sends a 'variables' request.
|
|
|
|
func (c *Client) IndexedVariablesRequest(variablesReference, start, count int) {
|
|
|
|
request := &dap.VariablesRequest{Request: *c.newRequest("variables")}
|
|
|
|
request.Arguments.VariablesReference = variablesReference
|
|
|
|
request.Arguments.Filter = "indexed"
|
|
|
|
request.Arguments.Start = start
|
|
|
|
request.Arguments.Count = count
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
2020-05-01 19:24:44 +00:00
|
|
|
// TeriminateRequest sends a 'terminate' request.
|
|
|
|
func (c *Client) TerminateRequest() {
|
|
|
|
c.send(&dap.TerminateRequest{Request: *c.newRequest("terminate")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// RestartRequest sends a 'restart' request.
|
|
|
|
func (c *Client) RestartRequest() {
|
|
|
|
c.send(&dap.RestartRequest{Request: *c.newRequest("restart")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetFunctionBreakpointsRequest sends a 'setFunctionBreakpoints' request.
|
2021-05-18 17:25:16 +00:00
|
|
|
func (c *Client) SetFunctionBreakpointsRequest(breakpoints []dap.FunctionBreakpoint) {
|
|
|
|
c.send(&dap.SetFunctionBreakpointsRequest{
|
|
|
|
Request: *c.newRequest("setFunctionBreakpoints"),
|
|
|
|
Arguments: dap.SetFunctionBreakpointsArguments{
|
|
|
|
Breakpoints: breakpoints,
|
|
|
|
},
|
|
|
|
})
|
2020-05-01 19:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StepBackRequest sends a 'stepBack' request.
|
|
|
|
func (c *Client) StepBackRequest() {
|
|
|
|
c.send(&dap.StepBackRequest{Request: *c.newRequest("stepBack")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReverseContinueRequest sends a 'reverseContinue' request.
|
|
|
|
func (c *Client) ReverseContinueRequest() {
|
|
|
|
c.send(&dap.ReverseContinueRequest{Request: *c.newRequest("reverseContinue")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVariableRequest sends a 'setVariable' request.
|
dap: handle SetVariable requests (#2440)
* dap: handle SetVariable requests
The handler invokes debugger.SetVariableInScope, except for
string type variables. For which, we rely on the `call` command.
Moved the call expression handling logic to the new `doCall`
function, so it can be reused by the SetVariable requenst
handler.
With this PR, every successful SetVariable request triggers
a StoppedEvent - that's a hack to reset the variablesHandle
map internally and notify the client of this change. It will
be nice if we can just update cached data corresponding to
the updated variable. But I cannot find an easy and safe way
to achieve this yet.
Also fixed a small bug in the call expression evaluation -
Previously, dlv dap returned an error "Unable to evaluate
expression: call stopped" if the call expression is for
variable assignment. (e.g. "call animal = "rabbit").
* dap: address comments from aarzilli
resetHandlesForStop & sendStoppedEvent unconditionally after
call command is left as a TODO - This is an existing code path
(just refactored) and an preexisting bug. Fixing it here
requires updates in TestEvaluateCallRequest and I prefer
addressing it in a separate cl.
Disabled call injection testing on arm64. Separated TestSetVariable
into two, one that doesn't involve call injection and another that
may involve call injection.
Fixed variableByName by removing unnecessary recursion.
* dap: address polina's comments
- removed the hard reset for every variable set
- added tests for various variable types
- added tests that involves interrupted function calls. (breakpoint/panic)
And,
- changed to utilize EvalVariableInScope to access the variable instead
of searching the children by name.
- changed to utilize evaluate requests when verifying whether the variable
is changed as expected in testing. Since now we avoid resetting the variable
handles after variable reset, either we need to trigger scope changes
explicitly, or stop depending on the variables request.
* dap: address comments
- Discuss the problem around the current doCall implementation
and the implication.
- Refine the description on how VS Code handles after setVariable
and evaluate request (there could be followup scopes/evaluate requests).
- Use the explicit line numbers for breakpoints in the SetVariable tests.
- Do not use errors.Is - we could've used golang.org/x/xerrors polyfill
but that's an additional dependency, and we will remove this check once
tests that depend on old behavior are fixed.
* dap: remove errTerminated and adjust the test
* dap: evaluate in the outer frame, instead of advancing to the next bp
2021-05-20 17:05:47 +00:00
|
|
|
func (c *Client) SetVariableRequest(variablesRef int, name, value string) {
|
|
|
|
request := &dap.SetVariableRequest{Request: *c.newRequest("setVariable")}
|
|
|
|
request.Arguments.VariablesReference = variablesRef
|
|
|
|
request.Arguments.Name = name
|
|
|
|
request.Arguments.Value = value
|
|
|
|
c.send(request)
|
2020-05-01 19:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RestartFrameRequest sends a 'restartFrame' request.
|
|
|
|
func (c *Client) RestartFrameRequest() {
|
|
|
|
c.send(&dap.RestartFrameRequest{Request: *c.newRequest("restartFrame")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GotoRequest sends a 'goto' request.
|
|
|
|
func (c *Client) GotoRequest() {
|
|
|
|
c.send(&dap.GotoRequest{Request: *c.newRequest("goto")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetExpressionRequest sends a 'setExpression' request.
|
|
|
|
func (c *Client) SetExpressionRequest() {
|
|
|
|
c.send(&dap.SetExpressionRequest{Request: *c.newRequest("setExpression")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// SourceRequest sends a 'source' request.
|
|
|
|
func (c *Client) SourceRequest() {
|
|
|
|
c.send(&dap.SourceRequest{Request: *c.newRequest("source")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// TerminateThreadsRequest sends a 'terminateThreads' request.
|
|
|
|
func (c *Client) TerminateThreadsRequest() {
|
|
|
|
c.send(&dap.TerminateThreadsRequest{Request: *c.newRequest("terminateThreads")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// EvaluateRequest sends a 'evaluate' request.
|
2020-11-12 23:24:31 +00:00
|
|
|
func (c *Client) EvaluateRequest(expr string, fid int, context string) {
|
|
|
|
request := &dap.EvaluateRequest{Request: *c.newRequest("evaluate")}
|
|
|
|
request.Arguments.Expression = expr
|
|
|
|
request.Arguments.FrameId = fid
|
|
|
|
request.Arguments.Context = context
|
|
|
|
c.send(request)
|
2020-05-01 19:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StepInTargetsRequest sends a 'stepInTargets' request.
|
|
|
|
func (c *Client) StepInTargetsRequest() {
|
|
|
|
c.send(&dap.StepInTargetsRequest{Request: *c.newRequest("stepInTargets")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GotoTargetsRequest sends a 'gotoTargets' request.
|
|
|
|
func (c *Client) GotoTargetsRequest() {
|
|
|
|
c.send(&dap.GotoTargetsRequest{Request: *c.newRequest("gotoTargets")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// CompletionsRequest sends a 'completions' request.
|
|
|
|
func (c *Client) CompletionsRequest() {
|
|
|
|
c.send(&dap.CompletionsRequest{Request: *c.newRequest("completions")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExceptionInfoRequest sends a 'exceptionInfo' request.
|
2021-05-17 16:25:41 +00:00
|
|
|
func (c *Client) ExceptionInfoRequest(threadID int) {
|
|
|
|
request := &dap.ExceptionInfoRequest{Request: *c.newRequest("exceptionInfo")}
|
|
|
|
request.Arguments.ThreadId = threadID
|
|
|
|
c.send(request)
|
2020-05-01 19:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LoadedSourcesRequest sends a 'loadedSources' request.
|
|
|
|
func (c *Client) LoadedSourcesRequest() {
|
|
|
|
c.send(&dap.LoadedSourcesRequest{Request: *c.newRequest("loadedSources")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// DataBreakpointInfoRequest sends a 'dataBreakpointInfo' request.
|
|
|
|
func (c *Client) DataBreakpointInfoRequest() {
|
|
|
|
c.send(&dap.DataBreakpointInfoRequest{Request: *c.newRequest("dataBreakpointInfo")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDataBreakpointsRequest sends a 'setDataBreakpoints' request.
|
|
|
|
func (c *Client) SetDataBreakpointsRequest() {
|
|
|
|
c.send(&dap.SetDataBreakpointsRequest{Request: *c.newRequest("setDataBreakpoints")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadMemoryRequest sends a 'readMemory' request.
|
|
|
|
func (c *Client) ReadMemoryRequest() {
|
|
|
|
c.send(&dap.ReadMemoryRequest{Request: *c.newRequest("readMemory")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisassembleRequest sends a 'disassemble' request.
|
|
|
|
func (c *Client) DisassembleRequest() {
|
|
|
|
c.send(&dap.DisassembleRequest{Request: *c.newRequest("disassemble")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// CancelRequest sends a 'cancel' request.
|
|
|
|
func (c *Client) CancelRequest() {
|
|
|
|
c.send(&dap.CancelRequest{Request: *c.newRequest("cancel")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// BreakpointLocationsRequest sends a 'breakpointLocations' request.
|
|
|
|
func (c *Client) BreakpointLocationsRequest() {
|
|
|
|
c.send(&dap.BreakpointLocationsRequest{Request: *c.newRequest("breakpointLocations")})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModulesRequest sends a 'modules' request.
|
|
|
|
func (c *Client) ModulesRequest() {
|
|
|
|
c.send(&dap.ModulesRequest{Request: *c.newRequest("modules")})
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:52:53 +00:00
|
|
|
// UnknownRequest triggers dap.DecodeProtocolMessageFieldError.
|
2020-02-27 04:45:48 +00:00
|
|
|
func (c *Client) UnknownRequest() {
|
2020-02-15 19:52:53 +00:00
|
|
|
request := c.newRequest("unknown")
|
|
|
|
c.send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnknownEvent triggers dap.DecodeProtocolMessageFieldError.
|
|
|
|
func (c *Client) UnknownEvent() {
|
|
|
|
event := &dap.Event{}
|
|
|
|
event.Type = "event"
|
|
|
|
event.Seq = -1
|
|
|
|
event.Event = "unknown"
|
|
|
|
c.send(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// KnownEvent passes decode checks, but delve has no 'case' to
|
|
|
|
// handle it. This behaves the same way a new request type
|
|
|
|
// added to go-dap, but not to delve.
|
|
|
|
func (c *Client) KnownEvent() {
|
|
|
|
event := &dap.Event{}
|
|
|
|
event.Type = "event"
|
|
|
|
event.Seq = -1
|
|
|
|
event.Event = "terminated"
|
|
|
|
c.send(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) newRequest(command string) *dap.Request {
|
|
|
|
request := &dap.Request{}
|
|
|
|
request.Type = "request"
|
|
|
|
request.Command = command
|
|
|
|
request.Seq = c.seq
|
|
|
|
c.seq++
|
|
|
|
return request
|
|
|
|
}
|