Commit Graph

33 Commits

Author SHA1 Message Date
Alessandro Arzilli
b9c842b456 proc: drop support for reading interfaces in Go <= 1.6 (#1501)
Go 1.6 is now unsupported by the Go team and 3 years old and
runtimeTypeToDIE can use some simplification.
2019-02-26 08:49:03 -08:00
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
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
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
a2346ef69a pkg/proc: Unexport exported members of unexported type 2018-11-08 10:16:42 -08: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
Derek Parker
c3f50742b9 *: Misc refactors, and doc additions
Refactors some code, adds a bunch of docstrings and just generally fixes
a bunch of linter complaints.
2018-09-19 20:59:35 +02: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
7c42fc51d7 proc: support calls to methods directly and through interface 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
Derek Parker
49bfbe6d24 proc: Increase inline function support
This patch makes it so inlined functions are returned in the
function
list, and also allows users to set breakpoints on the call site of
inlined functions.

Fixes #1261
2018-08-08 11:08:34 +02:00
aarzilli
c53c43d140 *: Fix log level setting in logrus
Setting the Level field of a logrus logger doesn't actually do anything
since the Level field simply reports the log level of the last log
message emitted on the logger.
The right way to do that is to set logger.Logger.Level.
Also cleans up newline characters from log messages emitted through
logrus and fixes the direction of the arrows in the messages emitted by
rpccommon, which was inconsistent with the arrows of gdbserial.
2018-07-02 09:31:53 -07:00
Derek Parker
a208c89719 *: Use structured logging
Implements structured logging via Logrus. This gives us a logger per
boundry that we care about, allowing for easier parsing of logs if users
have more than one log option enabled. Also, cleans up a lot of
conditionals in the code by simply silencing the logger at creation as
opposed to conditionally logging everywhere.
2018-06-22 09:45:10 +02:00
aarzilli
e19cbcefa9 proc,command: fix optimized function warning in 1.9
A user complained on the mailing list about having continuous
"optimized function warnings" on non-optimized functions when using 1.9.
This commit fixes the problem by disabling optimized function detection
on 1.9 and earlier (where it's impossible) and adds a test so we don't
break it again in the future.
2018-06-20 07:56:32 -07:00
aarzilli
8bbccb3e66 proc: use new extended attribute to resolve concrete type of interfaces
go1.11 adds a new extended attribute to all type DIEs containing the
address of the corresponding runtime._type struct, use this attribute
to find the DIE of the concrete type of interface variables when
available.
2018-06-11 11:09:02 -07:00
aarzilli
42747a0951 proc: correctly set G struct offset for 1.11
The offset of G changed in go1.11 from 0x8a0 to 0x30. See:
https://github.com/golang/go/issues/23617
2018-06-11 11:09:02 -07:00
aarzilli
5155ef047f proc,dwarf/line: support is_stmt and prologue_end flags
Go1.11 uses the is_stmt flag of .debug_line to communicate which
assembly instructions are good places for breakpoints, we should
respect this flag.

These changes were introduced by:
* https://go-review.googlesource.com/c/go/+/102435/

Additionally when setting next breakpoints ignore all PC addresses that
belong to the same line as the one currently under at the cursor. This
matches the behavior of gdb and avoids stopping multiple times at the
heading line of a for statement with go1.11.

Change: https://go-review.googlesource.com/c/go/+/110416 adds the
prologue_end flag to the .debug_line section to communicate the end of
the stack-split prologue. We should use it instead of pattern matching
the disassembly when available.

Fixes #550

type of interfaces
'c7cde8b'.
2018-06-11 11:09:02 -07:00
Sergio Lopez
38307f92d4 proc: add support for dwz compressed DWARF
'dwz' is a tool that reduces the size of DWARF sections by
deduplicating symbols. The deduplicated symbols are moved from their
original 'compile unit' to a 'partial unit', which is then referenced
from its original location with an 'imported unit' tag.

In the case of Go binaries, all symbols are located in a single
'compile unit', and the name of each symbol contains a reference to its
package, so 'dwz' is not able to deduplicate them. But still, some C
symbols included in the binary are deduplicated, which also alters the
structure of the DWARF sections, making delve unable to parse them
(crashing in the attempt).

While it would've been possible to simply ignore the C symbols, or
blindly loading all then into BinaryInfo members (packageVars,
Functions...), for correctness sake this change tries to do the right
thing, staging symbols into temporary partialUnit objects, moving them
to BinaryInfo when they are actually requested  by a 'imported unit'
tag.
2018-05-23 13:59:45 -07:00
aarzilli
ec8dc3a10d proc,vendor: show global variables in disassembly
updates vendored version of x86asm, adds a symbol lookup function to
pass to the disassembler.

This will show global symbol names in the disassembly like go tool
objdump does.
2018-03-22 10:01:00 -07:00
Josh Soref
1d3b41f64e all: Spelling 2018-03-20 11:05:35 +01:00
aarzilli
dc7a4ccb16 proc: support interface type resolution for packages containing a dot
If the last entry of the package path contains a '.' the corresponding
DIEs for its types will replace the '.' character with '%2e'. We must
do the same when resolving the package path of the concrete type of an
interface variable.

Fixes #1137
2018-03-05 10:07:11 -08:00
aarzilli
4f813b8101 proc, terminal: use DW_AT_producer to warn user about optimized code 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
99cad1044b pkg/proc, pkg/dwarf/op: support DW_OP_piece, DW_OP_regX, DW_OP_fbreg
These are emitted by C compilers but also by the current development
version of the go compiler with the dwarflocationlists flag.
2017-11-21 11:51:02 -08:00
aarzilli
6d40517944 proc: replace all uses of gosymtab/gopclntab with uses of debug_line
gosymtab and gopclntab only contain informations about go code, linked
C code isn't there, we should use debug_line instead to also cover C.

Updates #935
2017-11-03 20:57:04 +01: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
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
aarzilli
1e3ff49610 pkg/dwarf/godwarf: split out type parsing from x/debug/dwarf
Splits out type parsing and go-specific Type hierarchy from
x/debug/dwarf, replace x/debug/dwarf with debug/dwarf everywhere,
remove x/debug/dwarf from vendoring.
2017-08-01 11:20:25 -06:00
Alessandro Arzilli
222cf7fc55 proc/eval: optimize variable lookup (#925)
Variable lookup is slow because it requires a full scan of debug_info
to check for package variables, this doesn't matter much in interactive
use but can slow down evaluation of breakpoint conditions
significantly.

Providing benchmark proof for this is hard since this effect doesn't
show for small programs with small debug_info sections.
2017-07-18 12:55:24 -06: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
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
Alessandro Arzilli
436a3c2149 proc refactor: split out BinaryInfo implementation (#745)
* proc: refactor BinaryInfo part of proc.Process to own type

The data structures and associated code used by proc.Process
to implement target.BinaryInfo will also be useful to support a
backend for examining core dumps, split this part of proc.Process
to a different type.

* proc: compile support for all executable formats unconditionally

So far we only compiled in support for loading the executable format
supported by the host operating system.
Once support for core files is introduced it is however useful to
support loading in all executable formats, there is no reason why it
shouldn't be possible to examine a linux coredump on windows, or
viceversa.

* proc: bugfix: do not resume threads on detach if killing

* Replace BinaryInfo interface with BinInfo() method returning proc.BinaryInfo
2017-04-06 11:14:01 -07:00
Derek Parker
53f0d24057 Move top-level packages into pkg 2017-02-08 12:17:19 -08:00