Commit Graph

127 Commits

Author SHA1 Message Date
Derek Parker
4c9a72e486 *: Update import name to github.com/go-delve/delve
The repository is being switched from the personal account
github.com/derekparker/delve to the organization account
github.com/go-delve/delve. This patch updates imports and docs, while
preserving things which should not be changed such as my name in the
CHANGELOG and in TODO comments.
2019-01-04 19:43:13 +01:00
aarzilli
89c8da65b6 proc: Improve performance of loadMap on very large sparse maps
Users can create sparse maps in two ways, either by:
a) adding lots of entries to a map and then deleting most of them, or
b) using the make(mapType, N) expression with a very large N

When this happens reading the resulting map will be very slow
because loadMap needs to scan many buckets for each entry it finds.

Technically this is not a bug, the user just created a map that's
very sparse and therefore very slow to read. However it's very
annoying to have the debugger hang for several seconds when trying
to read the local variables just because one of them (which you
might not even be interested into) happens to be a very sparse map.

There is an easy mitigation to this problem: not reading any
additional buckets once we know that we have already read all
entries of the map, or as many entries as we need to fulfill the
MaxArrayValues parameter.

Unfortunately this is mostly useless, a VLSM (Very Large Sparse Map)
with a single entry will still be slow to access, because the single
entry in the map could easily end up in the last bucket.

The obvious solution to this problem is to set a limit to the
number of buckets we read when loading a map. However there is no
good way to set this limit.
If we hardcode it there will be no way to print maps that are beyond
whatever limit we pick.
We could let users (or clients) specify it but the meaning of such
knob would be arcane and they would have no way of picking a good
value (because there is no objectively good value for it).

The solution used in this commit is to set an arbirtray limit on
the number of buckets we read but only when loadMap is invoked
through API calls ListLocalVars and ListFunctionArgs. In this way
`ListLocalVars` and `ListFunctionArgs` (which are often invoked
automatically by GUI clients) remain fast even in presence of a
VLSM, but the contents of the VLSM can still be inspected using
`EvalVariable`.
2018-11-09 08:12:45 -08:00
Derek Parker
51c342c6b7 pkg/prog: Improve support for external debug info
Adds a config file option to allow specifying a list of directories to
search in when looking for seperate external debug info files.

Fixes #1353
2018-11-08 10:16:42 -08:00
aarzilli
73d636f7d7 tests: rename _fixtures/vendor to _fixtures/internal
Some tests used a fake vendor directory placed inside _fixtures to
import some support packages.
In go.mod mode vendor directory are only supported on the root of the
project, which breaks some of our tests.
Since vendor directories outside the root of the project are so rare
anyway it's possible that a future version of go will stop supporting
it even in GOPATH mode.
Also it was weird and unnecessary in the first place anyawy.
2018-11-06 08:52:06 -08:00
aarzilli
d2904322fa proc: add flag to disable escape checking in function calls
Fix escape checking in function calls  and add a flag to disable it.
2018-10-15 09:31:35 -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
74c98bc961 proc: support position independent executables (PIE)
Support for position independent executables (PIE) on the native linux
backend, the gdbserver backend on linux and the core backend.
Also implemented in the windows native backend, but it can't be tested
because go doesn't support PIE on windows yet.
2018-10-11 11:21:27 -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
50419b61da proc: implement conversion of integers to string
Go allows converting a single integer value to string, resulting in a
string containing a single unicode rune with the same code as the value
of the integer.
Allow the same conversion to happen.

Fixes #1322
2018-09-25 09:52:04 -07:00
aarzilli
0461af8392 proc: fix type of some struct global variables
Normally variables that have a named struct as a type will get a
typedef entry as their type, sometimes however the Go linker will
decide to use the DW_TAG_structure_type entry instead.

For consistency always wrap a struct type into a typedef when we are
creating a new variables (see comment in newVariable for exceptions).

This fixes a bug where it would be impossible to call methods on a
global variable.
2018-08-29 16:16:20 -07:00
aarzilli
19ba86c0c9 proc: support calls through function pointers 2018-08-16 12:44:02 -07:00
aarzilli
7c42fc51d7 proc: support calls to methods directly and through interface 2018-08-16 12:44:02 -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
9335c54014 proc: use (*Variable).setValue in fncall 2018-08-15 10:29:16 -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
2925c0310a *: function call injection for go 1.11
Implements the function call injection protocol introduced in go 1.11
by https://go-review.googlesource.com/c/go/+/109699.

This is only the basic support, see TODO comments in pkg/proc/fncall.go
for a list of missing features.

Updates #119
2018-07-13 13:37:54 -07:00
aarzilli
2a2d1040e9 proc: allow "package/path".varname syntax
If the application being debugged imports two packages with the same
name (but different paths) there was no way to disambiguate the two,
since the character '/' can not appear inside a go identifier.

By allowing users to use a string literal as the package name a package
path can be specified.
2018-06-14 09:29:23 -07:00
aarzilli
cc86bde549 proc/native,proc/gdbserial: let target access terminal
Change the linux verison of proc/native and proc/gdbserial (with
debugserver) so that they let the target process use the terminal when
delve is launched in headless mode.

Windows already worked, proc/gdbserial (with rr) already worked.
I couldn't find a way to make proc/gdbserial (with lldb-server) work.

No tests are added because I can't think of a way to test for
foregroundness of a process.

Fixes #65
2018-05-18 09:53:29 -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
84ce278352 proc: allow evaluating constants specified with a partial package path
Fixes #1151
2018-03-20 09:46:35 -07:00
aarzilli
e47599d09a proc: remove proc.Process.Halt
The proper way to stop a running process is to call RequestManualStop,
which most code already did with the exception of some old test code.
2018-03-06 09:06:19 -08:00
Alessandro Arzilli
0c40a8f52a dwarf/reader,proc: support DW_AT_abstract_origin (#1111)
debug_info entries can use DW_AT_abstract_origin to inherit the
attributes of another entry, supporting this attribute is necessary to
support DW_TAG_inlined_subroutine.

Go, starting with 1.10, emits DW_TAG_inlined_subroutine entries when
inlining is enabled.
2018-02-13 09:20:45 -08:00
Alessandro Arzilli
bec6a65b15
proc,prettyprint: guard against autodereferenced escaped pointers (#1077)
Much like the bug in issue #1031 and commit
f6f6f0bf13e4c708cb501202b83a6327a0f00e31 pointers can also escape to
the heap and then have a zero address (and no children) when we
autodereference.

1. Mark autodereferenced escaped variables with a 0 address as
   unreadable.
2. Add guards to the pretty printers for unsafe.Pointer and pointers.

Fixes #1075
2018-01-19 15:50:28 +01:00
aarzilli
07c716818e proc/test: miscellaneous test changes for go1.10 2017-12-13 12:18:18 -08:00
aarzilli
8b4392dc46 pkg/proc: use constants to describe variable value 2017-12-13 12:18:18 -08:00
aarzilli
5f0f77f414 proc: automatically dereference interfaces on member access
If 'iv' is an interface variable with a struct as a concrete value let
'iv.A' evaluate to the access to field 'A' of the concrete value of
'iv'.
2017-11-20 12:03:35 -08: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
aarzilli
9ee21686e6 proc: report errors when loading executable on attach
Fixes #940
2017-08-30 11:20:20 -07:00
aarzilli
1128c26b87 cmd/dlv: do not pass "linkmode internal" for windows on go1.9 and later
go1.9 no longer needs "linkmode internal" on windows.

Fixes #755
Fixes #477
Fixes #631
2017-08-01 11:20:25 -06:00
aarzilli
a17de32c23 proc/variables: support embedded struct fields on go1.9
Before go1.9 embedded struct fields had name == "" in runtime and ==
type name in DWARF. After go1.9 both runtime and DWARF use a simplified
version of the type as name.
Embedded structs are distinguished from normal fields by setting a flag
in the runtime.structfield, for runtime, and by adding a custom
attribute in DWARF.
2017-08-01 11:20:25 -06:00
Alessandro Arzilli
8276ba06cd proc/eval: fix interface equality with nil (#914)
Fixes #904
2017-07-07 11:08:36 -07:00
Alessandro Arzilli
293c508757 proc/variables: dereference concrete value of interface variables (#905)
The concrete value of an interface is always stored as a pointer inside
an interface variable. So far we have followed the memory layout and
reported the type of the 'data' attribute of interfaces as a pointer,
however this makes it impossible to distinguish interfaces with
concrete value of type 'A' from interfaces of concrete value of type
'*A'.

With this changeset when we autodereference pointers when the concrete
type of an interface is not a pointer.
2017-06-29 11:17:52 -07:00
Florin Pățan
32a005de2b Fix various issues detected by megacheck (#880)
* Fix various issues detected by megacheck

I've ran honnef.co/go/tools/cmd/megacheck and fixed a few of the
things that came up there.

* Cleanup using Gogland
2017-06-29 11:15:59 -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
a843f7944e proc/gdbserial: mozilla rr support (#804)
Implements #727
2017-05-05 15:17:52 -07:00
Nathan Bruer
43f26fb4d6 pkg/proc: Fixed delve's version extraction to allow propsals (#798)
Go recently introduced proposal tags to their version tags, we
are simply allowing delve to handle it appropriately.

See:
0954fdd51e
2017-04-21 17:45:20 -07:00
aarzilli
b6fe5aebaf proc: refactoring: merge target into proc
- moved target.Interface into proc as proc.Process
- rename proc.IThread to proc.Thread
- replaced interfaces DisassembleInfo, Continuable and
  EvalScopeConvertible with Process.
- removed superfluous Gdbserver prefix from types in the gdbserial
  backend.
- removed superfluous Core prefix from types in the core backend.
2017-04-21 14:00:04 -07:00
aarzilli
15bac71979 proc: refactoring: split backends to separate packages
- move native backend to pkg/proc/native
- move gdbserver backend to pkg/proc/gdbserial
- move core dumps backend to pkg/proc/core
2017-04-21 14:00:04 -07:00
Hana Kim
92dad944d7 service/test: change test package name to service_test
According to https://golang.org/cmd/go/#hdr-Test_packages
service_test is more appropriate becuase this directory contains
no non-test code and the intention is to compile these *_test.go
files as a separate package and link/run with the main test package.
2017-04-19 10:09:36 -07:00
aarzilli
c8d9352522 proc: Implement target.Interface for gdbserver backend 2017-04-18 13:25:11 -07:00
aarzilli
3dacc25d2e proc: refactor Continue to work on any Process implementation 2017-04-18 13:25:11 -07:00
aarzilli
510b7db2a7 proc: introduce IThread interface to abstract threads 2017-04-18 13:25:11 -07:00
Alessandro Arzilli
b5a06f7aa8 proc refactoring: make stack, disassemble and eval independent of proc.Process (#786)
* proc: Refactor stackIterator to use memoryReadWriter and BinaryInfo

* proc: refactor EvalScope to use memoryReadWriter and BinaryInfo

* proc: refactor Disassemble to use memoryReadWriter and BinaryInfo
2017-04-13 16:19:57 -07:00
Derek Parker
53f0d24057 Move top-level packages into pkg 2017-02-08 12:17:19 -08:00
Derek Parker
26ad5f1d82 Introduce target interface 2017-02-08 12:16:51 -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
Evgeny L
4064d6acc0 Flag to set working directory (#650)
* proc: Add `wd` to Launch

This change adds the `wd` arg which specify working directory of the
program.

Fixes #295

* service/debugger: Add `Wd` field to debugger.Config

This change adds the `Wd` field which specify working directory of the
program launched by debugger.

Fixes #295

* service: Add `Wd` to service.Config

This change adds the `Wd` field which specify working directory of the
program debugger will launch.

Fixes #295

* cmd/dlv: Add `Wd` flag

This change adds `Wd` flag which specify working directory of the
program which launched by debugger.

Fixes #295

* only set the Linux working directory if it is set,
stub out param in darwin and windows

* set working directory for Windows
https://godoc.org/golang.org/x/sys/windows#CreateProcess
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

* Windows workingDir must be an *uint16

* attempt to chdir on darwin via @yuntan

* proc/exec_darwin.c: fix working directory for darwin

* Add tests to check if working directory works.
* Fix darwin implementation of fork/exec, which paniced if
  child fork returned.

* cmd, service: rename Wd to WorkingDir
2016-11-01 12:58:42 -07:00
aarzilli
f62bf8d1e3 proc: Names of concrete types of interfaces parsing their runtime._type
Generate names of the concrete types stored inside interface variables
by fully parsing their runtime._type instead of simply using the str
field.

This allows delve to read the contents of an interface variable when
the program imports multiple packages that have the same name. It also
allows delve to correctly interpret some complex anonymous types.

Fixes #455
2016-10-27 09:56:15 +02: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
f2c1789c64 Changed TestIssue426 to work with go 1.8 (#627)
go1.8 changed the way anonymous struct names are generated for DWARF.
2016-09-06 10:26:56 -07:00
Alessandro Arzilli
9bc6ad4f46 Go 1.7 compatibility (#524)
* tests: update to cope with go1.7 SSA compiler

* de-vendored golang.org/x/debug/dwarf

We need our own tweaked version

* dwarf/debug/dwarf: always use the entry's name attribute

Using the name attribute leads to better type names as well as fixes
inconsistencies between 1.5, 1.6 and 1.7.

* proc: Updated loadInterface to work with go1.7

go1.7 changed the internal representation of types, removing the string
field from runtime._type.
Updated loadInterface to use the new str field.
2016-05-29 12:20:09 -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
Alessandro Arzilli
af4798e2a9 service,terminal: APIv2 plus method to select API version (#460)
New API version with better backwards compatibility plus mechanism to
select the API version that a headless instance should use.

Adds service/test/cmd/typecheckrpc.go to type check the RPC interface.
2016-04-18 12:20:20 -07:00
aarzilli
82ef3cce78 debugger: bugfix: make delve API thread safe
proc.(*Process) methods are not thread safe, multiple clients
connecting simultaneously to a delve server (Issue #383) or a even
a single over-eager client (Issue #408) can easily crash it.
Additionally (Issue #419) calls to client.(*RPCClient).Halt can
crash the server because they can result in calling the function
debug/dwarf.(*Data).Type simultaneously in multiple threads which
will cause it to return incompletely parsed dwarf.Type values.

Fixes #408, #419 (partial)
2016-02-24 17:49:30 -08: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
51e87386da proc: Bug loading maps
Past the maximum recursion depth maps shouldn't be loaded at all,
adding map children and not loading them breaks assumptions in
the prettyprinter.

Fixes #406
2016-02-10 08:27:48 -08:00
aarzilli
54f1c9b3d4 proc: replace debug/dwarf with golang.org/x/debug/dwarf
Typedefs that resolve to slices are not recorded in DWARF as typedefs
but instead as structs in a way that there is no way to know they
are really slices using debug/dwarf.
Using golang.org/x/debug/dwarf instead this problem is solved and
as a bonus some types are printed with a nicer names: (struct string
→ string, struct []int → []int, etc)

 Fixes #356 and #293
2016-01-24 15:41:41 -08:00
aarzilli
7e0d3fc244 workaround: proc/eval: go sometimes inserts &v instead of v 2016-01-04 16:20:23 +01:00
aarzilli
8872b53e80 proc/variables: bugfix: makes TestEvalExpression more robust
Fixes #320
2015-12-26 14:47:43 -08:00
aarzilli
c859a880b6 Makes TestEvalExpression work on go1.6beta1
Go1.6 changed the behaviour of go/constants.
2015-12-23 10:53:49 +01:00
aarzilli
38716dcc26 proc/variables: bugfix: ifaces with types in user defined packages
The concrete type of an interface only contains the abbreviated
package name, we must construct a map from package names to package
paths to be able to resolve the concrete type of an interface.
2015-12-15 15:18:52 -08:00
aarzilli
8346a6ee08 proc/variables: bugfix: disable cast to maps and channels
It's was implemented unintentionally and the unintentional
implementation doesn't work and causes a crash.
2015-12-15 15:18:52 -08:00
aarzilli
141fc4ed21 proc/eval: support for simple builtin functions
supported: len, cap, imag, real, complex
2015-12-15 15:18:52 -08:00
aarzilli
48e13a9045 proc/variables: Support for interface types 2015-12-15 15:18:52 -08:00
aarzilli
2deb7fba20 proc/eval: fix panic slicing or indexing 'nil' 2015-12-15 15:18:52 -08:00
aarzilli
ff3e2344c4 proc/eval: Support type casts between basic types 2015-12-15 15:18:52 -08:00
aarzilli
e45443b3c4 proc/eval: Return an error when slicing a map over its length
Fixes #288
2015-11-07 11:48:40 +01:00
aarzilli
7a36967b5e proc/variables: unsafe.Pointer support 2015-11-06 17:01:38 -08:00
aarzilli
943c12030a proc/variables: map types support
Use m[n:] to skip the first n keys of a map
Map indexing is implemented with a linear scan

Implements #61, #122
2015-11-06 17:01:38 -08:00
aarzilli
988d529e91 proc/variables: Support chan types
Pretty print will print them with the format:
chan <element type> <queued elements>/<queue size>
2015-11-06 17:01:38 -08:00
aarzilli
43b64ec39e proc: Implements expression interpreter
Supported operators:

- All (binary and unary) operators between basic types except <-,
++ and -- (includes & to take the address of an expression)
- Comparison operators between supported compound types
- Typecast of integer constants into pointer types
- struct members
- indexing of arrays, slices and strings
- slicing of arrays, slices and strings
- pointer dereferencing
- true, false and nil constants

Implements #116, #117 and #251
2015-11-04 12:28:48 +01:00
aarzilli
50b5fc92e2 Changed api.Variable to have a machine readable value
The new contents of api.Variable are documented in
proc/variables.go.

Implements #243
2015-10-28 18:28:58 -07:00