Commit Graph

157 Commits

Author SHA1 Message Date
Fabio Falzoi
79d5db24a5
Automatically disable breakpoints with hitcount conditions that will never be satisfied again (#2833)
* service/debugger: disable breakpoints with hitcond not satisfiable

To avoid slowing down the debugged process unnecessarily, we disable
breakpoints with a hit condition that can no longer be hit again.

* test: add integration tests for hit conditions no more satisfiable

* proc/test: fix typo in breakpoints related tests

* test: use the new API for hitcond integration tests
2022-01-06 09:00:46 -08:00
Suzy Mueller
5842c1fe9e
service/dap: fix race in no debug test (#2766)
Check for a possible output event when disconnecting from a
process that has already exited.

Fixes #2763
2022-01-04 12:03:20 +01:00
polinasok
fcc9561cbe
service/dap: update request inventory comments and labels in Server.handleRequest (#2854)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2022-01-03 10:58:13 +01:00
polinasok
2f13672765
service/dap: fix compile error from merge conflict (#2818)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-12-08 11:37:35 +01:00
Suzy Mueller
a4ac69e87d
service/dap: support goroutine filters in dap (#2759)
* service/dap: filter goroutines

* adjust defaults

* add tests

* remove label change

* fix typos

* send invalidated areas

* respond to review, and allow to clear goroutineFilters
2021-12-07 09:23:55 -08:00
polinasok
d0898e4de1
service/dap: misc remote attach improvements (#2778)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-12-07 09:23:26 -08:00
Suzy Mueller
3833c3d029
service/dap: move presentationHint to frame from source (#2810) 2021-12-01 10:57:03 +01:00
polinasok
9013a121d8
server/dap: stop running command if conn closed - fixes nil dereference bug (#2781)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-11-09 09:24:26 +01:00
Suzy Mueller
19ce116bb2
service/dap: allow expression evaluation in log messages (#2747)
From the DAP spec:

If this attribute exists and is non-empty, the backend must not 'break' (stop) but log the message instead.
Expressions within {} are interpolated.
This change parses the log messages and stores the parsed values as a format string and list of expressions to evaluate and get the string value of.

Updates golang/vscode-go#123
2021-10-29 19:41:30 -07:00
Suzy Mueller
f8deab8522
service/dap: fix goroutine id selection for hardcoded breakpoints (#2748)
* service/dap: fix goroutine id selection for hardcoded breakpoints

Determining the stopped goroutine id on a breakpoint required
checking for breakpoints since some may be tracepoints. However,
there may be goroutines stopped on hardcoded breakpoints with
no breakpoint. We fix this by checking for runtime.breakpoint or
StopReason=proc.StopHardcodedBreakpoint.
2021-10-29 19:40:16 -07:00
Suzy Mueller
922c4cebd4
service/dap: add config expressions to evaluate requests (#2750)
We want to provide more flexibility for users to make changes to their configurations while the debug session is running. This could be accomplished by creating a custom request, but that were require a new UI as well, and every client of dlv dap to provide its own UI for this. By using the evaluate context, users can use the already existing debug console to change their configurations.

This change includes a refactor of the terminal code in order to share the code with the dap package.

This change provides a very similar to UI as the terminal package, but there are different configuration options that are DAP specific. We plan to use this same mechanism to expose a few other commands including "sources" to help users debug an ineffective substitutePath configuration.
2021-10-29 19:35:13 -07:00
polinasok
b48ceec161
service/dap: improve shutdown logic and test coverage (#2749)
This high-level goal is to push more shutdown logic into Session and not rely Server.Stop() because dap's version of Stop() is different from rpccommon. That means triggering the same shutdown steps in multiple places, so additional safeguards are added to make some of the duplicate steps no-ops to avoid errors, extra logging, etc.

This includes the following changes:

close client conn when request loop in serveDAPCodec exits (to match rpccommon)
exit request loop after processing a disconnect request (instead of relying on next read to fail because conn got closed by triggered Stop(), which is skipped in case of accept-multiclient and is not closed in Stop() in rpccommon)
reset debugger to nil to avoid shutting it down more than once and causing duplicate logging (in case stopDebugSession is called from onDisconnectRequest and Server.Stop or Session.Close as things shut down)
reset binaryToRemove to "" upon removal to avoid duplicate error (in case Close() is called more than once outside of Stop(), which technically is not the case right now)
expand testing for all possible server shutdown triggers
testing for Session-only shutdown as it will be integrated into rpccommon without dap.Server wrapper
updates golang/vscode-go#1830
updates #2328

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-26 10:11:55 -07:00
polinasok
b31565d8aa
service/dap: support JSON-RPC and DAP on the same port from "dlv debug/exec/test/attach" (#2755)
* Support JSON-RPC and DAP on the same port

* Fix test

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-25 12:39:28 -07:00
Suzy Mueller
b99d5f5971
service/dap: add option to hide system goroutines (#2743) 2021-10-18 13:13:12 -07:00
Suzy Mueller
99f03597c3
service/dap: add registers configuration for variables response (#2742) 2021-10-15 13:57:50 +02:00
polinasok
c8f6c3a685
service/dap: support remote-attaching to running debugger (#2737)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-14 10:58:53 -07:00
Suzy Mueller
ce5238944d
service/dap: support disassemble request (#2728)
This adds support for disassembling a region of code using the instructionPointerReference value returned in the stack trace request.
2021-10-14 10:44:36 -07:00
polinasok
64f2200202
service/dap: fix data race for noDebugProcess.ProcessState (#2735)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-13 18:38:22 -07:00
polinasok
8a9f141d51
service/dap: log parsed and applied launch configs (#2732)
* service/dap: log parsed and applied launch configs

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-10-13 12:05:47 -07:00
Hyang-Ah Hana Kim
98a0bcf772
cmd/dlv: add --client-addr flag to run dap with a predefined client (#2568)
This adds a new `--client-addr=host:port` flag to `dlv dap`.
If it is supplied, the dap process will dial into the tcp port where
a DAP client is waiting, and work with only the DAP client.
The DAP client is supposed to start the normal DAP message
exchange starting with the 'initialize' request after the dlv dap
process dials in and the connection is set up. 

VS Code Go extension plans to use this mode for

* reliably detecting `dlv dap` readiness. Currently it depends on
watching the log stream. After this PR, it can listen on a network port.
* running `dlv dap` from any terminal (part of RunInTerminal workflow
implementation).
2021-10-13 11:43:47 -07:00
Suzy Mueller
6c4029c765
service/dap: auto resume execution when setting breakpoints (#2726)
A set breakpoints request could come in while the program is running. For a seamless user experience, the server should set the breakpoint and then continue program execution.

Updates golang/vscode-go#1676
2021-10-13 08:52:06 -07:00
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
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
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
Alessandro Arzilli
b8f8cd82a6
service/rpccommon,service/dap: warn about listening to remote connections (#2721)
Updates #2669
2021-09-29 09:53:27 +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
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
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
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
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
513751573e
service: fix sameuser check (#2642)
Change the socket search to check both the remote and local fields of the
socket match the socket we want to find.

Sockets are identified by the 4-uple

	local_addr, local_port, remote_addr, remote_port

Two socket can differ by a single one of this four elements.
It is possible for the same local_port to be used by two different sockets,
as long as they are connecting to different remote addresses (or remote
ports).

An example of this bug in action can be seen at:

https://github.com/golang/vscode-go/runs/3141270564?check_suite_focus=true

There the server starts listening on 127.0.0.1:46011 and rejects a valid
client connection by finding the following socket:

60: 0100007F:DD82 0100007F:962D 06 00000000:00000000 03:00000133 00000000     0        0 0 3 0000000000000000

the local address of this socket is 0100007F:DD82 (127.0.0.1:56706), and the
remote address is 0100007F:962D (127.0.0.1:38445).

The reported error is:

	closing connection from different user (127.0.0.1:56706): connections to localhost are only accepted from the same UNIX user for security reasons

note how the local port does match the socket line (56706) but the remote
port is wrong (38445 instead of 46011).

Note also that the state of this socket is 06, or TIME_WAIT, which would be
impossible if this was the right socket, since the right socket would still
be open.

Fixes https://github.com/golang/vscode-go/issues/1555
2021-08-10 11:40:39 +02:00
Suzy Mueller
c426c5b38d
pkg/proc: configure target to not clear stepping breakpoints (#2635)
In order for DAP to support halting the program (either manually or on a breakpoint) performing some action and then resuming execution, there needs to be a way to stop the program without clearing the internal breakpoints. This is necessary for log points and stopping the program to set breakpoints.

The debugging UI makes it seem like a user should be able to set or clear a breakpoint at any time. Adding this ability to complete synchronous requests while the program is running is thus important to create a seamless user experience.

This change just adds a configuration to determine whether the target should clear the stepping breakpoints, and changes the server to use this new mode. Using the new mode means that the DAP server must determine when it expect the next to be canceled and do this manually.
2021-08-09 10:56:20 -07:00
Alessandro Arzilli
4264bf00f2
proc,terminal,service: support stack watchpoints (#2521)
* terminal,service: add way to see internal breakpoints

Now that Delve has internal breakpoints that survive for long periods
of time it will be useful to have an option to display them.

* proc,terminal,service: support stack watchpoints

Adds support for watchpoints on stack allocated variables.

When a stack variable is watched, in addition to the normal watchpoint
some support breakpoints are created:

- one breakpoint inside runtime.copystack, used to adjust the address
  of the watchpoint when the stack is resized
- one or more breakpoints used to detect when the stack variable goes
  out of scope, those are similar to the breakpoints set by StepOut.

Implements #279
2021-08-09 10:41:25 -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
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
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