Commit Graph

1376 Commits

Author SHA1 Message Date
Derek Parker
de6682d291 pkg/proc/test: Eval symlinks for test source (#1452)
Some build environments (such as when building RPMs) enjoy symlinking
things. This unfortunately causes our tests to fail as we record the
path of fixtures and use that when looking up file:line information.
However, the debug info in the binary records the original file
location, not the location of the symlink.
2019-01-04 11:03:16 +01:00
aarzilli
34e802a42b proc: make structMember work on pointer Variables created through cast
When casting an integer into a struct pointer we make a fake pointer
variable that doesn't have an address, maybeDereference and
structMember should still work on this kind of Variable.

Fixes #1432
2018-12-03 10:00:22 -08:00
aarzilli
d7d4c144c8 cmd/dlv,terminal: fix accept-multiclient behavior
1. Check IsMulticlient and send stop request before doing anything
   else.
2. Allow init file to call 'exit'

Fixes #1430
2018-12-03 09:58:29 -08:00
aarzilli
cb386d0966 proc/native/linux: ignore EIO after PTRACE_GETREGSET
PTRACE_GETREGSET was added in Linux 2.6.34, running this request in an
older kernel will report EIO, as documented on the manpage.

Fixes #1197
2018-12-03 09:54:31 -08:00
aarzilli
7d06d2c032 pkg/proc: align memory size of tls arena to pointer sized boundary
The size of the TLS memory arena needs to be aligned to pointer sized
boundaries on 86x64 architectures, otherwise some programs using cgo
will not have the correct offset for the g struct.

No tests because reproducing this problem depends on behavior of the
GNU ld linker caused by unclear influences.

Fixes #1428.
2018-11-29 09:49:13 -08:00
aarzilli
2210debf6c proc: handle gid == 0 in FindGoroutine
Goroutine id == 0 is special (there can be many goroutines with id 0).
If the caller of FindGoroutine asks for gid==0 and current thread is
running a goroutine 0 (i.e. either no goroutine or a special
goroutine) return whatever goroutine is running on the current thread.

Updates #1428
2018-11-29 09:49:13 -08:00
Chandrashekhara A
6611fbe919 pkg/config: Using current directory for config as fallback (#1425)
*  pkg/config: Using current directory to store config if getting user details fails.

    This patch is to use current directory to store config file.
    user.Current() call fails when dlv is run inside a container. (Alpine)

* Addressing comments

* Removed whitespace
2018-11-28 13:21:21 -08:00
zavla
a4a5d4b7f6 main_test: Fix "gopath mode" detection in projectRoot() (#1426)
* main_test: Fix "gopath mode" detection in projectRoot()

Fails detect that this is a "gopath mode" when GOPATH contains several paths ex. "d:\\dir\\gopath;f:\\dir\\gopath2"
2018-11-28 19:22:11 +01:00
zavla
c7399ac278 terminal: correctly gueses path separator used in source files paths (#1418)
Fixes an error in wrongly appending os.PathSeparator to source file path on Windows in case of path substitution config option.
2018-11-27 13:42:21 -08:00
aarzilli
53957e9f4d proc: do not panic if we can't satisfy a composite location for a slice var
The fix in 7f53117 for Issue #1416 had a bug, fix it and add a test.

Fixes #1419
2018-11-26 11:05:00 -08:00
Sergio Lopez
dc208bc0c3 pkg/config: Use a default value for DebugInfoDirectories
If DebugInfoDirectories is empty, set it to same value as we have in the
default configuration.

This is useful for users which already have an older config file.
2018-11-26 09:54:31 -08:00
Sergio Lopez
46923142cb pkg/config: Rewind *File after writeDefaultConfig
Otherwise the later call to ioutil.ReadAll will return an empty array.

This issue is visible from the user's perspective due to the new
debug-info-directories parameter, which does have a value in the default
config.

As a consequence, the first 'dlv' invocation fails to find the separate
debug info files, while the second one works as expected:

$ ./dlv core /usr/bin/dockerd-current /case/dockerd.1234
could not find external debug info file
$ ./dlv core /usr/bin/dockerd-current /case/dockerd.1234
Type 'help' for list of commands.
(dlv) exit
2018-11-26 09:54:31 -08:00
aarzilli
85e4ba439c proc/core: add support for windows minidumps
Minidumps are the windows equivalent of unix core files.
This commit updates pkg/proc/core so that it can open and read windows
minidumps.

Updates #794
2018-11-21 12:17:16 -08:00
aarzilli
31fff84519 proc: move windows register handling code to winutil package
Move windows register handling code to winutil package in preparation
for using it in proc/core to read minidump files.
2018-11-21 12:17:16 -08:00
aarzilli
3048b9605a proc: correctly extract name of functions that have been inlined
If a function can be inlined it will appear as two entries in
debug_info. A DW_TAG_subprogram entry with DW_AT_inlined = true (that
will be used as the abstract origin) and a second DW_TAG_subprogram
entry with an abstract origin.
To retrieve the name of this second entry we must load its abstract
origin.
2018-11-20 12:57:25 -08:00
aarzilli
b8ed126bf6 proc/*: allow stepping into functions without debug_info symbols
If proc.Step encounters a CALL instruction that points to an address
that isn't associated with any function it should still follow the
CALL.

The circumstances creating this problem do not normally occur, it was
encountered in the process of fixing a bug created by Go1.12.
2018-11-20 12:57:25 -08:00
aarzilli
f813520e9b tests: minor fixes for Go 1.12 2018-11-20 12:57:25 -08:00
aarzilli
f8c0c37f30 proc: remove inversion of return variables from returnBreakpointInfo
It was never true that return variables were in the inverse order.
Instead in Go1.11 return variables are saved in debug_info in an
arbitrary order and inverting them just happened to work for this
specific example.

This bug was fixed in Go 1.12, regardless we should attempt to
rearrange return variables anyway.
2018-11-20 12:57:25 -08:00
aarzilli
7f53117ea9 proc: do not panic if we can't satisfy a composite location
When a location expression requests a register check that we have as
many bytes in the register as requested and if we don't report the
error.

Updates #1416
2018-11-19 14:46:35 -08:00
Sergio Lopez
11accd4d71 proc/proc: Extend GoroutinesInfo to allow specifying a range
Instead of unconditionally returning all present goroutines,
GoroutinesInfo now allows specifying a range (start and count). In
addition to the array of goroutines and the error, it now also returns
the next goroutine to be processed, to be used as 'start' argument on
the next call, or 0 if all present goroutines have already been
processed.

This way clients can avoid eating large amounts of RAM while debugging
core dumps and processes with a exceptionally high amount of goroutines.

Fixes #1403
2018-11-19 10:06:38 -08:00
Derek Parker
3cfb00b2cc pkg/proc: Cleanup duplicated panic breakpoint code 2018-11-15 18:16:16 +01:00
Derek Parker
d61cd1c0d7 pkg/proc: Refactor process post initialization
This patch is a slight refactor to share more code used for genericprocess initialization. There will always be OS/backend specificinitialization, but as much as can be shared should be to preventduplicating of any logic (setting internal breakpoints, loading bininfo,etc).
2018-11-15 18:16:16 +01:00
Derek Parker
91953dd49c cmd/dlv: Fix tests for use with modules 2018-11-14 09:00:49 +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
Derek Parker
a2346ef69a pkg/proc: Unexport exported members of unexported type 2018-11-08 10:16:42 -08:00
Derek Parker
7a414662c0 pkg/proc: Reorganize struct members 2018-11-08 10:16:42 -08:00
Derek Parker
2f746e1d3c pkg/config: Clean up godoc lint issues 2018-11-08 10:16:42 -08:00
Derek Parker
4927bc6c7a *: Switch to using Go modules 2018-11-07 08:44:06 +01:00
aarzilli
7d0d2cb3e6 pkg/core: make code in core.go OS/arch agnostic
Make code in core.go OS and architecture agnostic in preparation for
adding Windows minidump support.
2018-11-06 11:20:38 -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
Derek Parker
810b22a633 pkg/dwarf: Remove exec bit from reader.go
For some reason the Go file pkg/dwarf/reader/reader.go had the exec bit
set on it. This patch removes that.
2018-11-01 06:44:16 +01:00
aarzilli
ea3428550d proc/native,proc/core: deduplicate linux register handling code
The linux version of proc/native and proc/core contained largely
overlapping implementations of the register handling code, deduplicate
it by moving it into proc/linutil.
2018-10-22 12:19:09 -07:00
Derek Parker
3129aa7330 *: Show return values on CLI trace
This patch allows the `trace` CLI subcommand to display return values of
a function. Additionally, it will also display information on where the
function exited, which could also be helpful in determining the path
taken during function execution.

Fixes #388
2018-10-19 20:32:27 +02:00
aarzilli
4db9939845 proc/native: Mask MS_VC_EXCEPTION [windows]
Some libraries (for example steam_api64.dll) will send this exception
code to set the thread name on Microsoft VisualC.
In theory it should be fine to send the exception back to the target,
which is responsible for setting a handler for it, in practice in some
cases (steam_api64.dll) this will crash the program. So we'll mask it
instead.

Fixes #1383
2018-10-19 10:33:40 -07:00
aarzilli
d0f0a872a7 Documentation,Makefile: better error when gencert.sh fails
Fixes #1378
2018-10-18 09:47:29 -07:00
Derek Parker
ff760d87aa cmd: Add --exec and --test flags for trace sub cmd
Adds an --exec flag for the trace subcommand allowing users to specify a
pre-compiled binary to exec and trace.

Also adds a --test flag as a convienance for compiling and tracing a
test binary.

Fixes #1073
2018-10-18 11:46:03 +02:00
Derek Parker
c920630082 cmd: Fix trace bug when no package specified
Fix a bug where the regexp would be used as a package string
incorrectly. This would manifest when trying to execute the trace
subcommand as `dlv trace <regexp>` without specifying a package
identifier. The `<regexp>` would be passed to the Go build command
causing an error.
2018-10-18 11:42:25 +02:00
aarzilli
b5cf584564 proc/gdbserial: backward continue should stop at start of process
ContinueOnce didn't detect the way RR signals that it has reached the
start of the process and would never finish.

Fixes #1376
2018-10-17 09:07:36 -07:00
aarzilli
f72c48c034 proc: Continue should always work after CallFunction
Continue did not resume execution after a call to CallFunction if the
point where the process was stopped, before the call CallFunction, was
a breakpoint.

Fixes #1374
2018-10-17 09:07:36 -07:00
aarzilli
d7ea38b89a Documentation: rename "where" parameter of checkpoint to "note"
The name "where" may confuse users into thinking that this parameter
actually does something where in fact it's just arbitrary text used to
identify the checkpoint.

Fixes #1373
2018-10-17 09:07:36 -07:00
aarzilli
b59032516e proc,service,terminal: eval expressions in the scope of a deferred call
Add ability to evaluate variables on the scope of a deferred call's
argument frame.
2018-10-16 08:40:07 -07: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
Russ Magee
4e4ed02948 config,terminal: Add source-list-line-color configuration option
This change adds a config flag to specify the foreground color of
line numbers for the source list command.
2018-10-10 11:24:29 -07:00
chainhelen
ea54a6b2af cmd,service: remove temporary def of Server interface in func
Use the defination of Server interface in service package, instead of
temporary in func.
2018-10-09 07:56:48 -07:00
aarzilli
ca0596724f cmd,service: in non-headless mode use an in-memory connection
Replace the socket connection with an in-memory connection (created by net.Pipe) for non-headless uses of delve.
This is faster and more secure.

Fixes #1332
2018-10-08 15:11:13 -07:00
aarzilli
910f90c3c8 proc/native,Makefile: allow compiling on macOS without native backend
On macOS 10.14 Apple changed the command line tools so that system
headers now need to be manually installed.

Instead of adding one extra install step to the install procedure add a
build tag to allow compilation of delve without the native backend on
macOS. By default (i.e. when using `go get`) this is how delve will be
compiled on macOS, the make script is changed to enable compiling the
native backend if the required dependencies have been installed.

Insure that both configuration still build correctly on Travis CI and
change the documentation to describe how to compile the native backend
and that it isn't normally needed.

Fixes #1359
2018-10-02 10:46:09 -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