Commit Graph

137 Commits

Author SHA1 Message Date
Suzy Mueller
d1c888f22a
service/dap: set instruction breakpoints (#2716)
Support setting instruction breakpoints, this is newly supported in VS Code for the disassembly view.
2021-10-13 08:34:09 -07:00
polinasok
d613f8ec45
service/dap: use constants for testing error codes (#2741)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-10 15:57:06 +02:00
polinasok
3515be1db1
service/dap: support accept-multiclient shutdown in remote attach mode (#2731)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-10 15:52:52 +02:00
Suzy Mueller
69634d5d60
service/dap: allow "instruction" stepping granularity (#2713) 2021-10-08 08:58:19 +02:00
polinasok
0baf3b7cf1
service/dap: fix nil dereference when byte array cannot be converted to string (#2733)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-08 08:57:51 +02:00
polinasok
b3b177dc40
service/dap: rename delveCwd to dlvCwd and clarify comments (#2734)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-07 11:28:15 +02:00
polinasok
b2a2b32336
service/dap: Dap => DAP (#2739)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-07 11:27:04 +02:00
Suzy Mueller
b48dd09251
service/dap: log goroutine id and include source info (#2730) 2021-10-05 18:29:46 -07:00
Suzy Mueller
70df230e72
service/dap: merge arguments and local scopes (#2717) 2021-10-05 10:35:14 -07:00
Hyang-Ah Hana Kim
fa10cec9fa
dap: support delveCwd and use a temporary file as default debug binary (#2660) 2021-10-05 13:40:17 +02:00
polinasok
dc2f615c9a
service/dap: refactor the server into two layers (#2729)
* service/dap: refactor the server into two layers

* Add delay before setting debugger in remote tests

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-04 09:13:17 -07:00
aarzilli
cf58ba4380 tests: miscellaneus test fixes for Go 1.18 2021-10-02 15:44:30 +02:00
Suzy Mueller
4b30ba4228
service/dap: add basic log points (#2634)
Log points are special kinds of breakpoints that do not 'break' but instead log a message and then continue. This change implements basic log points that simply log the provided message, without any interpolation.

In order to resume execution after hitting a breakpoint, I added a new lock resumeMu and tracked the running state within the DAP server. resumeMu must be held in order to issue a debugger request that would start execution. This means it can be used to make sure that another goroutine does not resume execution while you are holding the lock.

Most of the synchronization logic is taken from PR #2530

Updates golang/vscode-go#123
2021-09-24 15:22:32 -07:00
Suzy Mueller
e00670b901
service/debugger: return correct exit status on manual halt (#2674)
* service/dap: add test for nonzero exit status
2021-09-24 15:18:28 -07:00
polinasok
2b306e32a6
service/dap: initial remote attach (handler support only) (#2709) 2021-09-24 13:43:46 +02:00
Suzy Mueller
c7e2a9b6fb
service/dap: remove unused test helper arg (#2714) 2021-09-22 21:29:05 -07:00
polinasok
a3897eafa7
service/dap: client must treat non-build launch/attach errors as visible (#2671)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-09-22 21:12:48 -07:00
polinasok
cf10647360
service/dap: fix test setup for forcing server stop, add extra test (#2702)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-09-20 08:53:01 -07:00
Suzy Mueller
ab38d71147
service/dap: show decimal and hex values for uint (#2694) 2021-09-16 12:19:01 +02:00
Suzy Mueller
0979847100
service/dap: do not send a halt request if the debuggee is not running (#2686)
updates go-delve/delve#2685
2021-09-09 08:49:11 -07:00
polinasok
47d07e095c
service/dap: add test coverage for Stop() (#2678)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-09-01 09:59:51 -07:00
Suzy Mueller
88b163d038
service/dap: include selected goroutine in threads request (#2683)
When we set a limit on the number of threads that would be
returned, it was possible that the selected thread was not
included in the list of threads. This could cause issues
because the stopped reason is associated with the selected
goroutine, so users could be missing out on important info.

This change makes sure that the selected goroutine is included
by adding it to the end of the list.
2021-09-01 09:58:42 -07:00
Hyang-Ah Hana Kim
1433c07957
dap: define LaunchConfig/AttachConfig types (#2571)
Formally define these types and document their meaning.
We will auto-generate the dlv-dap documentation from these Go type doc.

mapToStruct is a helper that sets the given struct's fields with the
info in map[string]interface{} (launch/attach's Arguments). We achieve
this by reencoding map[string]interface{} to json and decoding back to
the target struct. If go-dap left the implementation-specific arguments
as json.RawMessage and let the implementation decode as needed, this
reencoding could've been avoided.

encoding/json itself does not have mean to enforce required fields.
There was a test case that checks substitutePath elements must set
both from/to fields. Path.UnmarshalJSON implements the check.
I am not yet sure about the need for distinction between missing
'from/to' and empty strings yet. (empty value is useful when dealing with
a binary built with trimpath, right?)

A minor behavior change - previously, if noDebug is not a boolean type,
we ignored the attribute silently. Since we use json decoding, any
mismatched types will cause an error and this non-boolean type noDebug
attribute will result in launch failure.
2021-08-26 14:42:58 +02:00
polinasok
7cdf48605b
service/dap: clarify handling of relative program path (#2653)
* service/dap: add test verifying handling of relative program path

* Add exec test, log build dir and document in --help

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-08-23 11:27:49 -07:00
polinasok
a4d416d5f1
service/dap: add test that verifies output path is relative to wd (#2656)
* service/dap: add test that verifies output path is relative to wd

* Use cleanExeName to get the right output name on Win

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-08-17 11:40:31 -07:00
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