Commit Graph

147 Commits

Author SHA1 Message Date
Derek Parker
2de4930ad1 pkg/proc: Avoid passing BinaryInfo when not needed
This is going towards untangling proc in order to clean it up.
2019-08-09 18:15:44 +02:00
Robert Ayrapetyan
df65be43ae *: FreeBSD initial support (#1480)
* FreeBSD initial support

* first code review fixes

* regs slice upd

* execPtraceFunc wrap

* disabled concurrency tests
fixed kill() issue

* disabled concurrency tests
fixed kill() issue

* cleanup vendor related code

* cleanup ptrace calls

* vendoring latest changes

* Revert "vendoring latest changes"

This reverts commit 833cb87b

* vendoring latest changes

* requested changes
2019-07-12 18:28:04 -07:00
David Chase
a25d2a2b24 proc: added *BinaryInfo.AllPCsForFileLine for faster bulk queries (#1592)
Support for bulk queries makes the DWARF quality checker
(github.com/dr2chase/dwarf-goodness/cmd/dwarf-goodness)
run much more efficiently (replace quadratic cost with
linear).
2019-06-27 19:39:15 -07:00
Alessandro Arzilli
a7c2d837d5 proc: add LocationCover method to BinaryInfo (#1573)
Also fixes findCompileUnitForOffset which was broken in some edge cases
(when looking up an offset inside the last child of the compilation
unit) which don't happen in normal executables (we only look up types, and those
are always direct childs of compile units).
2019-06-24 08:02:14 -07:00
Alessandro Arzilli
215e13e81b proc: simplify partial unit support (#1565)
Instead of reading partial units as we see them skip them entirely and
then re-read them when they are imported, directly into the destination
compile unit.

This avoids a lot of duplicate code in the loadDebugInfoMaps function
and will simplify implementing logical breakpoints and support for the
new DW_AT_go_package_name attribute added in Go 1.13.
2019-05-31 09:08:20 -07:00
tschundler
9076056c70 proc: Less confusing error message for requesting break on blank line. (#1556)
The current wording is confusing - the file exists and the line exists, so what is the problem? I suspect this ambiguity is behind #1496 and likely others.

Also I updated the style to return values like the rest of the code in the file, which is also more readable (IMO and per https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters)
2019-05-30 08:11:21 -07:00
Justin Clift
6f258d91a5 proc: trivial typo fix (#1561) 2019-05-30 08:02:27 -07:00
Alessandro Arzilli
f3b149bda7 proc: support debugging plugins (#1414)
This change splits the BinaryInfo object into a slice of Image objects
containing information about the base executable and each loaded shared
library (note: go plugins are shared libraries).

Delve backens are supposed to call BinaryInfo.AddImage whenever they
detect that a new shared library has been loaded.

Member fields of BinaryInfo that are used to speed up access to dwarf
(Functions, packageVars, consts, etc...) remain part of BinaryInfo and
are updated to reference the correct image object. This simplifies this
change.

This approach has a few shortcomings:

1. Multiple shared libraries can define functions or globals with the
   same name and we have no way to disambiguate between them.

2. We don't have a way to handle library unloading.

Both of those affect C shared libraries much more than they affect go
plugins. Go plugins can't be unloaded at all and a lot of name
collisions are prevented by import paths.

There's only one problem that is concerning: if two plugins both import
the same package they will end up with multiple definition for the same
function.
For example if two plugins use fmt.Printf the final in-memory image
(and therefore our BinaryInfo object) will end up with two copies of
fmt.Printf at different memory addresses. If a user types
  break fmt.Printf
a breakpoint should be created at *both* locations.
Allowing this is a relatively complex change that should be done in a
different PR than this.

For this reason I consider this approach an acceptable and sustainable
stopgap.

Updates #865
2019-05-08 14:06:38 -07:00
Alessandro Arzilli
af1ffc8504 proc,proc/native,proc/gdbserial: initial plugin support (#1413)
Adds initial support for plugins, this is only the code needed to keep
track of loaded plugins on linux (both native and gdbserial backend).

It does not actually implement support for debugging plugins on linux.

Updates #865
2019-03-20 10:32:51 -07:00
Alessandro Arzilli
3ba4bcf488 proc: do not crash if executable doesn't have a PT_TLS section (#1483)
Fixes #1481
2019-02-26 09:17:05 -08:00
Alessandro Arzilli
ff7b81c407 proc: better error message when we don't have debug_info (#1490)
Do not mention external debug info files when the problem might just be
that the executable was stripped.
2019-02-21 09:11:54 -08:00
aarzilli
2e0a331fdc proc: fix nil pointer exception when Attach fails
Fixes #1471
2019-01-28 15:47:58 -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
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
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
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
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
9335c54014 proc: use (*Variable).setValue in fncall 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
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
440b440562 proc: support GNU compressed debug sections (go1.11 support)
Go1.11 switched to the zlib-gnu compression format for debug sections.
Change proc and and a test in dwarf/line to support this change.

Also deletes some dead code from pkg/proc/bininfo.go that hadn't been
used in a long time.
2018-06-22 11:20:38 -07:00
Sergio Lopez
774b5c7ce2 proc: add support for separate debug info
To save disk space, some distributions strip the debugging information
from the binaries, putting it in separate files, usually distributed in
separate packages.

To locate the file containing the debug information for a certain
binary, an ELF note named ".note.gnu.build-id" is added to the latter,
which contains a header and a build identification. This identification
can be used to compose a path with this form:

/usr/lib/debug/.build-id/BUILDID[:2]/BUILDID[2:].debug

With this patch, if Delve can't find the debug information in the main
binary, it'll try to locate and parse ".note.gnu.build-id", to compose
and attempt to open a path with the format described above.

Fixes #1206
2018-06-21 11:08:00 -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
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
Jay Mundrawala
c7cde8b151 Keep searching for file:line until found
Go seems to be generating multiple compilation units that have
the same file. I think this happens for functions that get inlined.
Without this patch, those inlined functions break the ability to set
a breakpoint at other lines in the file. I was able to load the same
binary in gdb and set a breakpoints throughout the file without issue.

```
➜ objdump --dwarf=decodedline automate-gateway | grep handler/users.go
.../handler/users.go:[++]
s/.../handler/users.go           20            0xb6dd88
.../handler/users.go:[++]
s/.../handler/users.go           20            0xb6e50f
.../handler/users.go:[++]
s/automate-gateway/handler/users.go           32            0xb66640
```

Inlined functions are still a little weird. setting a breakpoint on
a function that gets inlined picks the first occurence. That being
said, I think delve should still do something reasonable for the rest
of the lines in the file.
2018-05-15 15:41:23 -07:00
aarzilli
290e8e7528 proc: support inlining
Go 1.10 added inlined calls to debug_info, this commit adds support
for DW_TAG_inlined_call to delve, both for stack traces (where
inlined calls will appear as normal stack frames) and to correct
the behavior of next, step and stepout.

The calls to Next and Frame of stackIterator continue to work
unchanged and only return real stack frames, after reading each line
appendInlinedCalls is called to unpacked all the inlined calls that
involve the current PC.

The fake stack frames produced by appendInlinedCalls are
distinguished from real stack frames by having the Inlined attribute
set to true. Also their Current and Call locations are treated
differently. The Call location will be changed to represent the
position inside the inlined call, while the Current location will
always reference the real stack frame. This is done because:

* next, step and stepout need to access the debug_info entry of
the real function they are stepping through
* we are already manipulating Call in different ways while Current
is just what we read from the call stack

The strategy remains mostly the same, we disassemble the function
and we set a breakpoint on each instruction corresponding to a
different file:line. The function in question will be the one
corresponding to the first real (i.e. non-inlined) stack frame.

* If the current function contains inlined calls, 'next' will not
set any breakpoints on instructions that belong to inlined calls. We
do not do this for 'step'.

* If we are inside an inlined call that makes other inlined
functions, 'next' will not set any breakpoints that belong to
inlined calls that are children of the current inlined call.

* If the current function is inlined the breakpoint on the return
address won't be set, because inlined frames don't have a return
address.

* The code we use for stepout doesn't work at all if we are inside
an inlined call, instead we call 'next' but instruct it to remove
all PCs belonging to the current inlined call.
2018-03-26 14:30:38 -04: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
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
aarzilli
1758f8523a pkg/terminal: print DWARF location expression with whatis
Adds a configuration option (show-location-expr) that when activated
will cause the whatis command to also print the DWARF location
expression for a variable.
2017-12-20 16:34:47 -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
f098915192 proc/tests: testing apparatus for complex location expressions 2017-11-21 11:51:02 -08:00
aarzilli
73a39b985a pkg/dwarf/line: improve performance
1. Use a slice instead of a map to access standard and extended opcodes
   (reduces BenchmarkStateMachine from ~12ms/op to ~7ms/op)

2. Cache StateMachine values for the entry point of functions.
2017-11-03 20:57:04 +01: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
9ee21686e6 proc: report errors when loading executable on attach
Fixes #940
2017-08-30 11:20:20 -07: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
heschik
7d2834a963 proc: read G struct offset from runtime.tlsg if possible (#883)
When a Go program is externally linked, the external linker is
responsible for picking the TLS offset. It records its decision in the
runtime.tlsg symbol. Read the offset from that rather than guessing -16.

This implementation causes a regression: 1.4 and earlier will no longer
work.
2017-06-21 15:40:42 -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
aarzilli
c8d9352522 proc: Implement target.Interface for gdbserver backend 2017-04-18 13:25:11 -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