Commit Graph

37 Commits

Author SHA1 Message Date
Alessandro Arzilli
6bda7085c7
proc: allow type casts between compatible types (#3149)
Go allows some type casts when the underlying types are the same.
Conform to that behavior.

Fixes #3130
2022-09-29 10:08:19 -07:00
Alessandro Arzilli
2b97231e30
proc,service: pretty print time.Time variables (#2865)
Fixes #999
2022-03-25 13:59:57 -07: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
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
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
polinasok
32f646e3e8
service/dap: auto-loading for fully missing children of nested vars (#2455)
* service/dap: auto-loading for fully missing pointers, structs, maps, slices and arrays

* Add call test

* Add TODO

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-05-04 12:53:42 -07:00
polinasok
2414dcdd30
service/dap: truncate long compound map keys and use unique address suffix for uniqueness (#2399)
* Truncate long compound map keys and use address suffix only for those

* Remove test typo that causes failures

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-03-25 09:44:32 -07:00
polinasok
129a9fe46c
service/dap: detect and report unloaded variables (#2353)
* Detect and report unloaded variables

* Make DeepSource happy

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-02-23 08:29:06 -08:00
polinasok
98728d8fe1
service/dap: improve test coverage for evaluateName feature based on known vscode-go bugs (#2341)
* DAP test for github.com/golang/vscode-go/issues/1056

* DAP test for github.com/golang/vscode-go/issues/884

* DAP test for github.com/golang/vscode-go/issues/851

* DAP test for github.com/golang/vscode-go/issues/1053

* DAP test for github.com/golang/vscode-go/issues/1054

* Make DeepSource happy

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-02-21 08:00:05 -08:00
Alessandro Arzilli
f19d5e5c13
proc: fix embedded field search (#2320)
Both structMember and findMethod implemented a depth-first search in
embedded fields but the Go specification requires a breadth-first
search. They also allowed promotion of fields in the concrete type of
embedded interfaces even though this is not allowed by Go.
Furthermore they both lacked protection from infinite recursion
when a type embeds itself and the user requests a non-existent field.

Fixes #2316
2021-01-29 09:25:31 -08:00
polinasok
58ea3234ef
service/dap: Initial support for scopes and variables requests (#2111)
* Initial support for scopes and variables requests

* Add detailed variables test

* Address review comments

* Fix typo and redudant escaped characters

* Bug fix for uninitialized interfaces; no refs needed for 0-size vars

* Minor cosmetic tweaks

* Add incomplete loading test

* Make DeepSource happy

* Remove unnecessary t.Helper() calls

* Update broken test after merge

* Add missing return

* Rework test harness to abort testvariables2 before stack overflow

* Remove accidentally duplicated disconnet

* Test for invalid interface type with regex

* Drop testvariables3, clean up and test unreadable case

* Respond to review comments

* Make expectVar test helper less fragile

* Make DeepSource happy

* Use proc.LoadConfig directly

* Adjust test to avoid var count discrepency between Go 1.15 and earlier

* Make compound keys in a map unique for correct display

* Remove locals num check that will break if more vars are added

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2020-08-11 08:34:27 -07:00
aarzilli
5a947bceff proc: always resolve array types even if they don't appear in the
program

When evaluating type casts always resolve array types.

Instead of resolving them by looking up the string in debug_info
construct a fake array type so that a type cast to an array type always
works as long as the element type exists.

We already did this for byte arrays, this commit extends this to any
array type. The reason is that we return a fake array type (that
doesn't exist in the target program) for the array of a channel type.

Fixes #1736
2019-10-29 09:04:36 +01:00
Alun Evans
36d688bf14 pkg/terminal: Fix starlark map iteration for maps > 64 entries (#1699)
* Fix starlark map iteration for maps > 64 entries

* Fix TestMapEvaluation
2019-10-07 09:35:58 -07:00
Alessandro Arzilli
ed35dce7a3 terminal: adds embedded scripting language (#1466)
If the argument of 'source' ends in '.star' it will be interpreted as a
starlark script.
If the argument of 'source' is '-' an interactive starlark repl will be
started.

For documentation on how the starlark execution environment works see
Documentation/cli/starlark.md.

The starlark API is autogenerated from the JSON-RPC API by
script/gen-starlark-bindings.go.
In general for each JSON-RPC API a single global starlark function is
created.
When one of those functions is called (through a starlark script) the
arguments are converted to go structs using reflection. See
unmarshalStarlarkValue in pkg/terminal/starbind/conv.go.
If there are no type conversion errors the JSON-RPC call is executed.
The return value of the JSON-RPC call is converted back into a starlark
value by interfaceToStarlarkValue (same file):

* primitive types (such as integers, floats or strings) are converted
  by creating the corresponding starlark value.
* compound types (such as structs and slices) are converted by wrapping
  their reflect.Value object into a type that implements the relevant
  starlark interfaces.
* api.Variables are treated specially so that their Value field can be
  of the proper type instead of always being a string.

Implements #1415, #1443
2019-07-02 10:55:27 -07:00
Alessandro Arzilli
1a75095286 godwarf: fix nil pointer reading recursive types involving an array (#1582)
Fixes #1578
2019-06-12 17:35:00 -07:00
chainhelen
143cf6aebf pkg/proc: extend conversion about string for array/str
Extend `string()`
1.convert `byte/rune array`(not only `slice`) to string.
2.convert string to string(itself), just like `string(str)` in go language.
2018-10-15 09:27:39 -07:00
aarzilli
79a0e216ab proc: add iface.(data) syntax to access concrete value of an interface
With this syntax users do not need to type the concrete type of an
interface variable to access its contents. This also sidesteps the
problem where the serialization of a type by go/printer is different
from the one used for debug_info type names.

Updates #1328
2018-09-27 14:09:26 -07:00
aarzilli
51994aafd3 proc: evaluate var.method expressions
Evaluates var.method expressions into a variable holding the
corresponding method with the receiver variable as a child, in
preparation for extending CallFunction so that it can call methods.
2018-08-16 12:44:02 -07:00
aarzilli
12a3f8bb97 proc: change (*Variable).setValue for use in CallFunction
Changes (*Variable).setValue so that it can be used in CallFunction to
set up the argument frame for the function call, adding the ability to:
- nil nillable types
- set strings to the empty string
- copy from one structure to another (including strings and slices)
- convert any interface type to interface{}
- convert pointer shaped types (map, chan, pointers, and structs
  consisting of a single pointer field) to interface{}

This covers all cases where an assignment statement can be evaluated
without allocating memory or calling functions in the target process.
2018-08-15 10:29:16 -07:00
aarzilli
b9c4a1d68c proc: Short circuit evaluation of && and || like go does
Change evaluation of binary operators so that both && and || only
evaluate their second argument conditionally, like go does.
2018-04-13 15:34:03 -07:00
aarzilli
a708d00e78 proc/eval: strings of different length are never equal 2018-04-10 14:46:31 -07:00
aarzilli
844762a853 proc: support access to chan buffers
Replace the unsafe.Pointer type of the buf field of channels with the
appropriate array type, allow expressions accessing member field of the
channel struct.

Fixes #962
2017-11-20 12:03:35 -08:00
aarzilli
8f16b371d1 proc/eval: support more type casts
* string to []rune
* string to []byte
* []rune to string
* []byte to string
* any pointer to uintptr

The string, []rune, []byte conversion pairs aligns this to the go
language.
The pointer -> uintptr conversion pair is symmetric to the uintptr ->
pointer that we already have.

Also lets the user specify any size for byte array types instead of
just the ones already used by the program, this can be used to read
arbitrary memory.

Fixes #548, #867
2017-10-25 13:20:25 +02:00
aarzilli
25765063fc proc/variables: distinguish between nil and empty slices and maps
Fixes #959
2017-09-11 11:43:37 -07:00
Alessandro Arzilli
8276ba06cd proc/eval: fix interface equality with nil (#914)
Fixes #904
2017-07-07 11:08:36 -07:00
Alessandro Arzilli
d8bb8ed5bf proc/variables: fill Len field of maps when recursion limit is reached (#834)
If we don't fill the Len field there will be no way for the user to
distinguish maps we didn't load from empty maps.
2017-05-30 14:26:10 -07:00
Alessandro Arzilli
cf84483672 proc/variables: bugfix: parsing of maps with zero sized value type (#851)
Buckets of maps with zero sized value types (i.e. map[T]struct{}) have
zero length value arrays.
2017-05-26 11:36:28 -07:00
Alessandro Arzilli
fc0d40144a proc/variables: fix infinite recursion with pointer loop (#725)
loadValue didn't react correctly to pointer loops going through
slice -> interface{} -> slice or pointer -> interface{} -> pointer.
2017-02-09 16:26:38 -08:00
Alessandro Arzilli
d89d115ef9 proc/variables: support NaN/Inf float values (#706)
Unfortunately go/constant does not support NaN and Inf float values so
we need to store this information alongside.

Fixes #705
2017-01-20 14:22:36 -08:00
Alessandro Arzilli
6bff4d1970 proc/variables: extend sign of read negative integers. (#657)
Since we store all signed integers as int64 the sign bit should be
extended, otherwise we read negative integers as their 2-complement
value.
2016-11-02 14:32:48 -07:00
Alessandro Arzilli
54d3eab63a prettyprint: Print type of the elements of arrays of interface type (#591) 2016-10-21 22:14:43 -07:00
Alessandro Arzilli
a7a0cc75e1 proc: allow use of quoted type names in type casts (#434)
If we are unable to correctly guess how a type is serialized in
debug_info let the user specify it directly.

Workaround for #455
2016-04-24 16:14:42 -07:00
Alessandro Arzilli
473b66387c proc: Improvements to Variable printing (#444)
* service/api: Removed unused fields of service/api.Function

* proc/eval: Set return variable name to input expression

* all: fine-grained control of loadValue for better variable printing

Makes proc.(*Variable).loadValue loading parameters configurable
through one extra argument of type LoadConfig.
This interface is also exposed through the API so clients can control
how much of a variable delve should read.
2016-04-24 10:15:39 -07:00
aarzilli
6242c4388e _fixtures: Removed testvariables2 and testvariables4
Moved the code in testvariables2 and testvariables4 into
testvariables3, renamed testvariables3 into testvariables2
2016-02-18 12:16:31 -08:00
aarzilli
8de1a307ee Fix: track recurseLevel in readArray/readSlice
This fix helps avoid infinite recursion.
2015-08-09 20:37:47 -05:00