Commit Graph

112 Commits

Author SHA1 Message Date
polinasok
694b45c893
service/dap: fix noDebug mode to handle requests while running (#2658)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-08-16 08:51:23 -07:00
Alessandro Arzilli
e175d68e97
service/dap: fix race condition in TestContinueOnEntry (#2641)
The Threads request sent immediately after the ConfigurationDone
request can be processed in two possible states:

- while the program is being executed, when it will return Id=1,
  Name=Dummy
- after the program terminates, when it will return Id=-1, Name=Current

additionally the response could be received in any order with the
Terminate event.

Remove the problematic Threads request from the test.
2021-08-05 22:19:27 -07:00
polinasok
985eca462c
service/dap: log execution-halted message when setting breakpoints (#2631)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-08-05 10:16:15 -07:00
Alessandro Arzilli
2971fd4c68
service/dap: fix TestNextParked/TestStepInParked (#2643)
The loop searching for a suitable goroutine is not guaranteed to ever
find it, and failing to find one is not an error.

Changes testStepParkedHelper to match the behavior of TestNextParked in
proc_test.go.
Deletes TestStepInParked because it does not test anything meaningful
beyond what's already tested by TestNextParked.
2021-08-04 14:12:58 -07:00
Suzy Mueller
89ed5a0b19
service/dap: page stack frames (#2597)
Returning monotonically increasing totalFrames values for subsequent requests can be used to enforce paging in the client. If we are not at the end of the stackFrames that are returned, we return a higher total frames to suggest to the client that they should request more frames.
2021-07-29 10:34:01 -07:00
Suzy Mueller
b87a1fc55d
service/dap: make next while nexting error more clear (#2622)
To make it more clear that the user can resume the program when they encounter a next while nexting error, make the exception information have instructions for resuming the program. This implements the suggestions outlined by @polinasok in #2443.
2021-07-29 10:27:49 -07:00
Derek Parker
f6681c6090
pkg/proc: Prefer throw instead of fatalthrow (#2616)
* pkg/proc: Prefer throw instead of fatalthrow

Currently there is a breakpoint set at runtime.fatalthrow to catch any
situation where the runtime crashes (e.g. deadlock).
When we do this, we go up a frame in order to parse the crash reason.
The problem is that there is no guarentee the "s" variable we attempt to
parse will still be considered "live".
Since runtime.fatalthrow is never called directly, set a breakpoint on
runtime.throw instead and prevent having
to search up a stack frame in order to
get the throw reason.

Fixes #2602

* service/dap: Fix TestFatalThrowBreakpoint

* Reenable TestFatalThrow DAP test

* service/dap: Don't skip test on < 1.17

* service/dap: Update test constraint for 1.16

* pkg/proc: Reinstate runtime.fatalthrow as switchstack exception
2021-07-27 23:58:02 -07:00
polinasok
aaed14ffcb
service/dap: fix backend parsing in replay mode (#2618)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-23 14:04:53 -07:00
Suzy Mueller
f1edc45f75
service/dap: disable TestFatalThrowBreakpoint for Go 1.17 (#2614)
* service/dap: disable TestFatalThrowBreakpoint for Go 1.17
2021-07-23 10:12:57 -07:00
polinasok
b7d8edcdaf
service/dap: handle unexpected debugger termination (EOF) error (#2574)
Using issue419.go, I observed that the continue command fails with an error when debugger receives and forwards an interrupt. In spite of the stopped event, vscode still shows the state as RUNNING because the threads request is unable to retrieve any threads, but at least one dummy thread is always expected.

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-22 08:52:04 -07:00
Luis Gabriel Gomez
69615b3604
service/dap: Support for replay and core modes (#2367)
This PR aims to add support for rr replay and core actions from the DAP layer. This basically encloses the following:
New launch modes: replay and core

The following modes are added:

    replay: Replays an rr trace, allowing backwards flows (reverse continue and stepback). Requires a traceDirPath property on launch.json pointing to a valid rr trace directory.
    Equivalent to dlv replay <tracedir> command.
    core: Replays a core dump file, showing its callstack and the file matching the callsite. Requires a coreFilePath property on launch.json pointing to a valid coredump file.
    Equivalent to dlv core <exe> <corefile> command.

Dependencies

To achieve this the following additional changes were made:

    Implement the onStepBackRequest and onReverseContinueRequest methods on service/dap
    Adapt onLaunchRequest with the requried validations and logic for these new modes
    Use CapabilitiesEvent responses to enable the StepBack controls on the supported scenarios (see dicussion here)
    Add the corresponding launch.json support on vs code: 

Support for replay and core modes golang/vscode-go#1268
2021-07-21 07:38:04 -07:00
Alessandro Arzilli
38aaf274a9
service/dap: fix TestPreSetBreakpoint (#2600)
TestPreSetBreakpoint sometimes fail because a goroutine is stopped in
some runtime/internal package instead of just 'runtime'.
2021-07-19 08:09:18 -07:00
polinasok
af378d396f
service/dap: add backend launch/attach attribute (#2567)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-18 11:37:41 +02:00
Suzy Mueller
feb55342eb
service/dap: add len as metadata for map (#2584) 2021-07-16 09:50:37 -07:00
polinasok
9df8f1499f
service/dap: variables response must not have null variables array (#2592)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-15 14:15:49 -07:00
Suzy Mueller
890cde3d4c
service/dap: send terminated event when disconnecting (#2587)
* service/dap: send terminated event when disconnecting

If the program terminates while disconnecting, either because it
was killed or otherwise, send a terminated event.
2021-07-14 14:32:46 -07:00
Suzy Mueller
f86ed675d8
service/dap: add panic and throw text to stopped event (#2559)
* service/dap: add panic and throw text to stopped event

We can add more information to the stopped events on errors using
the `Text` field in the stopped event. We already use this to display
the runtime errors. Adding this information to the stopped reason will
also help to show the user additional info when a stopped event is not
associated with a particular goroutine.
2021-07-13 08:38:28 -07:00
Alessandro Arzilli
f0a32c8e1b
Go 1.17 support branch (#2451)
* proc: support new Go 1.17 panic/defer mechanism

Go 1.17 will create wrappers for deferred calls that take arguments.
Change defer reading code so that wrappers are automatically unwrapped.

Also the deferred function is called directly by runtime.gopanic, without going through runtime.callN which means that sometimes when a panic happens the stack is either:

0. deferred function call
1. deferred call wrapper
2. runtime.gopanic

or:

0. deferred function call
1. runtime.gopanic

instead of always being:

0. deferred function call
1. runtime.callN
2. runtime.gopanic

the isPanicCall check is changed accordingly.

* test: miscellaneous minor test fixes for Go 1.17

* proc: resolve inlined calls when stepping out of runtime.breakpoint

Calls to runtime.Breakpoint are inlined in Go 1.17 when inlining is
enabled, resolve inlined calls in stepInstructionOut.

* proc: add support for debugCallV2 with regabi

This change adds support for the new debug call protocol which had to
change for the new register ABI introduced in Go 1.17.

Summary of changes:
- Abstracts over the debug call version depending on the Go version
  found in the binary.
- Uses R12 instead of RAX as the debug protocol register when the binary
  is from Go 1.17 or later.
- Creates a variable directly from the DWARF entry for function
  arguments to support passing arguments however the ABI expects.
- Computes a very conservative stack frame size for the call when
  injecting a call into a Go process whose version is >=1.17.

Co-authored-by: Michael Anthony Knyszek <mknyszek@google.com>
Co-authored-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>

* TeamCity: enable tests on go-tip

* goversion: version compatibility bump

* TeamCity: fix go-tip builds on macOS/arm64

Co-authored-by: Michael Anthony Knyszek <mknyszek@google.com>
2021-07-08 08:47:53 -07:00
Suzy Mueller
e1febcf609
service/dap: send dap error response on dap error (#2561)
The code previously expected the server to close when receiving
a message that it could not decode. However, there may be changes to
the spec that make new requests that we have not handled yet. In
that case, it would be preferable to return an error and continue handling
incoming requests.
2021-07-07 22:27:54 -07:00
Suzy Mueller
0bf3e790cd
service/dap: set hit breakpoint ids (#2550) 2021-07-07 22:08:52 -07:00
Suzy Mueller
1ebfc5c37b
service/dap: add throw reason to exception info (#2524)
We can get the throw reason by looking at the argument "s" in runtime.throw. This is not currently working in Go 1.16 or Go 1.17 (see golang/go#46425), but does work in Go 1.15 and Go 1.14
2021-06-28 08:39:34 -07:00
Suzy Mueller
7b98f5870d
service/dap: add string value of byte/rune slice as child (#2541)
Load limit for metadata string is set to MaxStringLen
2021-06-23 16:51:57 -07:00
Suzy Mueller
0b38b5d4ec
service/dap: fix error string format (#2549) 2021-06-23 20:21:19 +02:00
polinasok
0a19c78021
service/dap: increase default string loading limit and refactor (#2546)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-06-22 08:14:47 -07:00
polinasok
69485a639d
service/dap: separate tests for var value truncation and str loading limits (#2539)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-06-16 13:27:38 -07:00
Suzy Mueller
688f94a4f8
service/dap: truncate value for expandable types in hover (#2529)
On hovers, including the full value for complex types is unnecessary, since the user will likely need to expand the children to inspect the values. Additionally, this can really slow down getting the hover values. This change will allow truncating the value in hover if the variable has a variables reference.

Updates golang/vscode-go#1435
2021-06-11 10:46:49 -07:00
Suzy Mueller
aa377789b0
service/dap: deemphasize internal runtime stack frames (#2522)
Apply a presentation hint to the internal runtime stack frames, so that these can be deemphasized in the UI. This should allow
users to more easily inspect their own code, and will keep the option to view those frames if they choose to.
2021-06-10 10:59:24 -07:00
Suzy Mueller
30b3cc2c6f
service/dap: implement array, slice, and map paging (#2512)
If the client supports paging, we allow them to fetch array and slice items in chunks that we assume will be of a reasonable size. For example, VS Code requests indexed variables in chunks of 100.

Fixes golang/vscode-go#1518
2021-06-10 09:34:20 -07:00
polinasok
fb4d6f1144
service/dap: handle no-such-process error on disconnect and fix flaky test (#2476)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-06-10 09:30:31 -07:00
Suzy Mueller
7a3faca71f
service/dap: make stopped event description more concise (#2523) 2021-06-04 17:35:50 +02:00
Hyang-Ah Hana Kim
152c74e94e
dap: add 'clipboard' support, and truncate a long value (#2513)
- add 'clipboard' capability
- apply a larger string limit for 'hover' and 'clipboard' context
- truncate the string representation of compound (or pointer of compound)
type variable
2021-06-04 09:27:57 +02:00
Suzy Mueller
054e3f8ef2
service/dap: generate continued events for step tests (#2525) 2021-06-03 09:50:53 -07:00
Suzy Mueller
b2afb7cd20
pkg/proc: add support for hit count condition breakpoints (#2490)
* pkg/proc: implement support for hit count breakpoints

* update comment

* udpate hitcount comment

* update HitCond description

* add test for hit condition error

* respond to review

* service/dap: add support for hit count breakpoints

* use amendbps to preserve hit counts

* update test health doc

* fix failing test

* simplify hit conditions

* REmove RequestString, use name instead

* update backend_test_health.md

* document hit count cond

* fix tests
2021-05-28 11:21:53 -07:00
Hyang-Ah Hana Kim
0e5b81528f
dap: clean output executable name for windows (#2514)
If the output binary name does not end with .exe, it can't run on Windows
in noDebug mode. If user-provided output name doesn't have file extension
name (.exe), append it.

Fixes golang/vscode-go#1473
2021-05-27 14:23:32 -07:00
polinasok
680bc9a78d
service/dap: test refactoring (#2508)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-05-26 08:15:39 -07:00
Hyang-Ah Hana Kim
5e12091da2
dap: use larger string type variable load limits in 'repl', 'variables' context (#2418)
* dap: use larger variable load limits in 'repl', 'variables' context

When evaluate requests are triggered in the context of 'repl'
(DEBUG CONSOLE in VSCode) or 'variables' (copy values from VARIABLES
section in VSCode), they are the result of human action and have
more rooms to display. So it is not too bad to apply longer limits.

Variable auto-loading for strings or arrays is nice but currently
it's unclear to me how this should be integrated in the DEBUG
CONSOLE or with the Copy Value feature. Until we have better ideas
and tools, let's go with these larger limits.

Unfortunately, the "Copy Value" from WATCH section triggers evaluate
requests with "watch" context and we don't want to load large data
automatically for "watch". So, users who want to query a large value
should first copy the expression to DEBUG CONSOLE and evaluate it.
Not ideal but not the end of the world either.

Updates golang/vscode-go#1318

* dap: apply large limit only to the string type result

* dap: move string reload logic to convertVariable* where other reload logic is

Currently we are thinking string reload for evaluation as a temporary
workaround until we figure out an intutitive way to present long strings.
So, I hope moving this logic near other reload logic may be better.

And, use the address based expression when reloading - when handling the
function return values, we may not have an expression to use.

* dap: make deep source check happy

* dap: move string reevaluation logic back to onEvaluateRequest

Reloading string variables is tricky if they are in registers.
We don't attempt to reload them but for clarity, move this up
to the onEvaluateRequest handler.

For function call, use a generous limit for string load
since the results are volatile.

* dap: check variable isn't affected by evaluate in other context
2021-05-25 10:23:41 -07:00
Hyang-Ah Hana Kim
c8934dc33b
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 10:05:47 -07:00
Suzy Mueller
95674dd463
service/dap: set function breakpoints while running (#2499) 2021-05-20 10:00:51 -07:00
Suzy Mueller
b72bce30cc
service/dap: support evaluate for hover context (#2496)
We can support evaluate for hover context in order to provide more
useful hover info for our users.

Updates go-delve/delve#2491
Updates golang/vscode-go#1510
2021-05-19 11:17:36 -07:00
Suzy Mueller
745a513179
service/dap: implement function breakpoints (#2450)
* service/dap: implement setFunctionBreakpoints request

* Fix the errors that would not allow func set

* use find locations instead of FindFunctionLocation

* add function breakpoint tests

* return after sending error response

* revert changes to debugger

* exclude regexp function names

* remove switch statement with one case

* remove ReadFile ambiguous test

* Remove TODO for multiple locs

* remove unnecessary setting of bp.Verified on error

* tighten condition for breakpoint name to match function breakpoint

* add tests for different loc types, add FindLocationSpec

* add test using base name of file

* make functionBreakpoint name a constant

* update stop reason to function breakpoint

* remove comment about optimizing onSetFunctionBreakpoints

* respond to review

* add comments to test

* change functionBpPrefix to const

* handle relative paths

* fix capabilites check

* update function breakpoint tests to check for failure

* use negative line number to determine which are errors
2021-05-18 10:25:16 -07:00
Suzy Mueller
4e582fa553
service/dap: send 'continued' event on next/step/stepout requests (#2480)
* service/dap: send 'continued' event on next/step/stepout requests

Next/step/stepout requests assume that execution is only resumed
on the thread that was specified. We cannot resume execution on
only a single thread, so we need to send a continued event to let
the client know that all threads have resumed.

* update set breakpoints test with continued event
2021-05-17 20:34:27 -07:00
polinasok
c10b222bad
service/dap: support pause request (#2466)
* service/dap: support pause request

* service/dap: validate the client configurations in initialize request (#2435)

The client can specify certain configurations in the initialize request.
For example, pathFormat determines the pathFormat. We do not currently
support configuring pathFormat, linesStartAt1, or columnsStartAt1, so
we report an error if the client attempts to set these to an
unsupported value.

* TeamCity: fix Windows builds (#2467)

Bintray is shutting down and the URL we used to install mingw is no
longer available. Use chocolatey instead.

* proc/native: low level support for watchpoints in linux/amd64 (#2301)

Adds the low-level support for watchpoints (aka data breakpoints) to
the native linux/amd64 backend.

Does not add user interface or functioning support for watchpoints
on stack variables.

Updates #279

* simplify pause test

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
Co-authored-by: Suzy Mueller <suzmue@golang.org>
Co-authored-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>
2021-05-17 10:37:15 -07:00
Alessandro Arzilli
bd2a4fe56e
proc/native/linux: better handling of process death due to signals (#2477)
Handle the signaled status for the thread leader like we handle the
exited status, by returning ErrProcessExited and recording the killer
signal  in it.
Prior to this commit we would find out about the death of the thread
later in the loop, the condition would still be reported as
ErrProcessExited, but without recording the signal number anywhere.

Also fixes a bug in TestAttachStopOnEntry where the test would
inadvertently cause a SIGPIPE to be sent to the target process, making
it terminate early.
2021-05-17 09:48:48 -07:00
Suzy Mueller
30cdedae69
service/dap: implement exception info (#2444)
* service/dap: implement exception info

* remove adding additional thread

* Fix tests

* add exceptionInfo tests

* update comments

* map paths to client paths

* remove launch.json

* remove change to ConvertEvalScope

* correct name of supportsExceptionInfoRequest

* Add TODO for deleting output event

* Print Stack header to buffer

* Try to move resolving exception info to onExceptionInfoRequest

* save the error and return if it is the current thread

* rename thread to g

* findgoroutine returns goroutine

* clean up findgoroutine

* log errors

* remove output event

* fix grammar
2021-05-17 09:25:41 -07:00
Suzy Mueller
1e9c5c3b07
service/dap: warn users of debugging optimized functions (#2475)
* service/dap: warn users of debugging optimized functions

* Add test for optimized scopes

* service/dap: warn users of debugging optimized functions

* rename functionscope

* update warning message
2021-05-17 09:21:15 -07:00
polinasok
11cf6e689f
service/dap: support setting breakpoints while running (#2472)
* service/dap: support setting breakpoints while running

* Review comments, faster test

* Fix comments

* Address review comments

* Do not continue automatically

* Add TODO to resume exeuction

* Handle async test messages in either order

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-05-17 09:17:00 -07:00
Suzy Mueller
32021981a7
service/dap: move build error to output event (#2482) 2021-05-17 09:13:25 -07:00
Suzy Mueller
252bcc4ebc
service/dap: fix continueOnEntryTest (#2489)
Accept the empty response in case the threads request arrived after the program
terminated
2021-05-17 09:07:55 +02:00
Suzy Mueller
5fa4a3527c
service/dap: fix flaky TestPreSetBreakpoint test (#2483) 2021-05-15 07:34:59 +02:00
Suzy Mueller
1b8428eb6c
service/dap: add type information to dap variables (#2465)
* service/dap: add type information to dap variables

* add comment explaining map type choice

* rename to setClientCapabilities

* respond to review

* update TypeString definition
2021-05-10 11:34:42 -07:00