Commit Graph

147 Commits

Author SHA1 Message Date
Alessandro Arzilli
29eae8f617
*: clean up staticcheck problems (#2723)
Fix problems that can be fixed, ignore the ones that don't make sense
2021-09-28 12:07:42 -07:00
Derek Parker
914e1bc80e
pkg/proc: attempt to leverage debuginfod-find (#2670)
If we cannot find debug information locally on the system, try and
invoke debuginfod-find in order to ask the linux distribution we're on
to find the debug information for us.
2021-08-25 13:29:28 +02:00
Alessandro Arzilli
fdb5189e8c
dwarf/op,proc: implement more DWARF expression opcodes (#2606) 2021-08-03 09:51:15 -07:00
Alessandro Arzilli
e9b20d5ee1
proc: use signed comparison when searching image for module data (#2621)
StaticBase is the difference between the entry point declared in the
image file and the entry point as loaded in memory, since this
difference could be a negative number we have to use a signed
comparison when searching for a mapping.

Causes intermittent test failures on windows when resolving interface
types for position independent executables.

Fixes #2620
2021-07-26 08:40:12 -07:00
Alessandro Arzilli
39274f6028
proc: make moduleDataToImage more robust (#2613)
Conversion form a moduledata object into an image object was
implemented by looking for a function covering the start address of the
text section of the moduledata object, and then converting that into
its corresponding image.

Unfortunately this seems to not always work. In particular it does not
work on linux/386 with go1.17 (but it might also fail on other
combinations): the start address of the text section is, for whatever
reason, not part of any function.

As a fallback simply scan all images we know of and return the closest
one that has start address less than or equal to the start address of
the text section we are looking for.

Fixes TestPluginVariables on go1.17/linux/386.

Fixes #2611

Co-authored-by: a <a@kra>
2021-07-23 09:21:24 -07:00
Alessandro Arzilli
f0a32c8e1b
Go 1.17 support branch (#2451)
* proc: support new Go 1.17 panic/defer mechanism

Go 1.17 will create wrappers for deferred calls that take arguments.
Change defer reading code so that wrappers are automatically unwrapped.

Also the deferred function is called directly by runtime.gopanic, without going through runtime.callN which means that sometimes when a panic happens the stack is either:

0. deferred function call
1. deferred call wrapper
2. runtime.gopanic

or:

0. deferred function call
1. runtime.gopanic

instead of always being:

0. deferred function call
1. runtime.callN
2. runtime.gopanic

the isPanicCall check is changed accordingly.

* test: miscellaneous minor test fixes for Go 1.17

* proc: resolve inlined calls when stepping out of runtime.breakpoint

Calls to runtime.Breakpoint are inlined in Go 1.17 when inlining is
enabled, resolve inlined calls in stepInstructionOut.

* proc: add support for debugCallV2 with regabi

This change adds support for the new debug call protocol which had to
change for the new register ABI introduced in Go 1.17.

Summary of changes:
- Abstracts over the debug call version depending on the Go version
  found in the binary.
- Uses R12 instead of RAX as the debug protocol register when the binary
  is from Go 1.17 or later.
- Creates a variable directly from the DWARF entry for function
  arguments to support passing arguments however the ABI expects.
- Computes a very conservative stack frame size for the call when
  injecting a call into a Go process whose version is >=1.17.

Co-authored-by: Michael Anthony Knyszek <mknyszek@google.com>
Co-authored-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>

* TeamCity: enable tests on go-tip

* goversion: version compatibility bump

* TeamCity: fix go-tip builds on macOS/arm64

Co-authored-by: Michael Anthony Knyszek <mknyszek@google.com>
2021-07-08 08:47:53 -07:00
Derek Parker
544a803a80
proc,dwarf: Improve DWARF v5 support (#2544)
While Go still mostly uses DWARF v4, newer versions of GCC will emit
DWARF v5 by default. This patch improves support for DWARF v5 by parsing
the .debug_line_str section and using that during file:line lookups.

This patch only includes support for files, not directories.

Co-authored-by: Derek Parker <deparker@redhat.com>
2021-06-22 13:37:46 +02:00
Alessandro Arzilli
83fe779193
proc: fix runtimeTypeToDIE setup (#2486)
The code populating runtimeTypeToDIE was incorrectly adding StaticBase
to the offset. We never noticed because on statically compiled
executables StaticBase is always zero and on PIE and plugins the
fallback code took care of the problem anyway.
A change in Go 1.17 broke the fallback code, making the issue apparent.
This commit fixes the setup of runtimeTypeToDIE and disables the
fallback code for Go 1.17 and later.
This change also fixes a rare failure in TestPluginVariables when PIE
is enabled.
2021-05-19 10:42:10 -07:00
Alessandro Arzilli
f3d7b25fdf
*: remove unused code, variables and constants (#2426) 2021-04-12 14:57:39 -07:00
Alessandro Arzilli
618f366998
proc: be more lenient when parsing debug_info (#2394)
- allow a concrete subprogram to be treated as the abstract origin for an inlined call
- allow nameless concrete and abstract subprograms

Fixes #2393
2021-04-05 11:50:59 -07:00
Alessandro Arzilli
a3c7ba8808
proc: add workaround for debug_frame bug on macOS (#2374)
This adds a workaround for the bug described at:

https://github.com/golang/go/issues/25841

Because dsymutil running on PIE does not adjust the address of
debug_frame entries (but adjusts debug_info entries) we try to do the
adjustment ourselves.

Updates #2346
2021-03-09 11:35:24 +01:00
Alessandro Arzilli
314ae669a3
dwarf/frame,proc: use eh_frame section (#2344)
The eh_frame section is similar to debug_frame but uses a slightly
different format. Gcc and clang by default only emit eh_frame.
2021-03-04 20:17:00 -08:00
Alessandro Arzilli
a6685247e0
proc/native: correctly read g address on linux/arm64 (#2343)
When cgo is used the address of the g struct is saved on the special
register TPIDR_EL0. Because executing C code could overwrite the
contents of R28 that normally contains the address of g we should read
it from TPIDR_EL0 instead when runtime.iscgo is set.
2021-02-23 12:38:52 -08:00
Alessandro Arzilli
c068861f95
locspec,proc: improve documentation (#2338)
* Reformat pkg/locspec documentation so that it is formatted correctly
  by godoc/pkgsite
* Unexport some types and variables in proc that don't need to be
  exported.
2021-02-10 09:31:37 -08:00
Than McIntosh
dceffacb89
pkg/proc: fix for file reference handling with DWARF 5 compilation units (#2327)
Add a helper method for collecting line table file references that
does the correct thing for DWARF 5 vs DWARF 4 (in the latter case you
have an implicit 0 entry which is the comp dir, whereas in the former
case you do not). This is to avoid out-of-bounds errors when examining
the file table section of a DWARF 5 compilation unit's line table.

Included is a new linux/amd-only test that includes a precompiled C
object file with a DWARF-5 section that triggers the bug in question.

Fixes #2319
2021-01-29 09:23:52 -08:00
Alessandro Arzilli
f5d5a681d0
proc: do not assume abstract origins precede their uses (#2293)
The DWARF standard does not say that a DW_ATTR_abstract_origin can only
reference entries that appear before it, this change fixes BinaryInfo
to comply. See #2284 for an example of this happening.
2021-01-27 06:58:48 -08:00
Christian Banse
57f033e4bc
proc/gdbserial: Added support for darwin/arm64 using gdbserver (#2285)
* Added support for reading darwin/arm64 using gdbserver

* Trying to fix test failures

* Addressing review comments
2021-01-04 08:52:04 -08:00
Alessandro Arzilli
85952c0826
proc: resolve symlinks when searching for split debug_info if path is /proc/pid/exe (#2170)
* Revert "proc: Find executable should follow symbol links."

This reverts commit 3e04ad0fada0c3ab57caf58bc024e4c0f9a3e01a.

* proc: resolve symlinks when searching for split debug_info if path is /proc/pid/exe

Fixes #2168
2020-09-15 14:49:30 -07:00
Alessandro Arzilli
12009e9833
proc/*,service: replace uses of uintptr with uint64 (#2163)
Since proc is supposed to work independently from the target
architecture it shouldn't use architecture-dependent types, like
uintptr. For example when reading a 64bit core file on a 32bit
architecture, uintptr will be 32bit but the addresses proc needs to
represent will be 64bit.
2020-09-09 10:36:15 -07:00
Aurken
3660f28397
proc: correct minor typos (#2148) 2020-08-24 10:19:50 -07:00
Alessandro Arzilli
328cf87808
dwarf/loclist,godwarf,proc: support DWARF version 5 loclists and debug_addr (#2097)
Parses and uses the new debug_loclists section added to DWARFv5.
2020-08-17 17:19:46 -07:00
aarzilli
136f4de4b8 proc: keep track of nesting depth while reading compile units
Fully read compile units that contain nested entries we don't
understand (such as DW_TAG_namespace) by keeping track of the depth
we're at.
2020-07-16 15:34:00 +02:00
Alessandro Arzilli
708eadd553
proc: do not wipe sources list when a plugin is detected (#2075)
The list of source files must include all files from all images, not
just the files from the last discovered image.

Fixes #2074
2020-06-05 11:23:48 -07:00
aarzilli
8f5df19948 proc: fix findCompileUnitForOffset when plugins are used
Splits the compileUnits slice between images so that we can search for
an offset inside the debug info of a specific image file.
2020-05-01 11:51:34 -07:00
chainhelen
ad9d13c671
proc: Don't set fileFound if there's a compileUnit without line section (#2006)
We should not return error directly which set `fileFound` to be true
if there's a compileUnit without line section.
2020-04-13 14:24:04 -07:00
aarzilli
a61b6c0d7c proc: avoid constructing unnecessary strings when evaluating variables
Avoids constructing:

1. name of runtime.curg fields while executing parseG
2. the location expression while evaluating any variable.

Benchmark before:

BenchmarkConditionalBreakpoints-4   	       1	4953889884 ns/op

Benchmark after:

BenchmarkConditionalBreakpoints-4   	       1	4419775128 ns/op

Updates #1549
2020-03-31 10:29:26 -07:00
aarzilli
431dea7ee6 proc: skip autogenerated wrappers when stepping in and out
Under some circumstances (methods with non-pointer receivers or from
embedded fields called through an interface) the compiler will
autogenerate wrapper functions.

This commit changes next, step and stepout to skip all autogenerated
wrappers.

Fixes #1908
2020-03-31 10:04:36 -07:00
Alessandro Arzilli
223e0a57ca
proc: convert Arch into a struct (#1972)
Replace the interface type Arch with a struct with the same
functionality.
2020-03-30 11:03:29 -07:00
Derek Parker
c4fd80fcd0 pkg/proc: Clean up proc.go
This patch moves out unrelated types, variables and functions from
proc.go into a place where they make more sense.
2020-03-24 09:45:29 +01:00
Alessandro Arzilli
7cd12c34fd
proc,dwarf: cache debug.Entry objects (#1931)
Instead of rescanning debug_info every time we want to read a function
(either to find inlined calls or its variables) cache the tree of
dwarf.Entry that we would generate and use that.

Benchmark before:

BenchmarkConditionalBreakpoints-4   	       1	5164689165 ns/op

Benchmark after:

BenchmarkConditionalBreakpoints-4   	       1	4817425836 ns/op

Updates #1549
2020-03-20 10:23:10 -07:00
chainhelen
f3a191cd73
pkg/proc,service: support linux/386 (#1884)
Implement debugging function for 386 on linux with reference to AMD64.
There are a few remaining problems that need to be solved in another time.

1. The stacktrace of cgo are not exactly as expected.
2. Not implement `core` for now.
3. Not implement `call` for now. Can't not find `runtime·debugCallV1` or
   similar function in $GOROOT/src/runtime/asm_386.s.

Update #20
2020-03-10 09:34:40 -07:00
Alessandro Arzilli
0741d3e57f
*: Go 1.14 support branch (#1727)
* tests: misc test fixes for go1.14

- math.go is now ambiguous due to changes to the go runtime so specify
  that we mean our own math.go in _fixtures
- go list -m requires vendor-mode to be disabled so pass '-mod=' to it
  in case user has GOFLAGS=-mod=vendor
- update version of go/packages, required to work with go 1.14 (and
  executed go mod vendor)
- Increased goroutine migration in one development version of Go 1.14
  revealed a problem with TestCheckpoints in command_test.go and
  rr_test.go. The tests were always wrong because Restart(checkpoint)
  doesn't change the current thread but we can't assume that when the
  checkpoint was taken the current goroutine was running on the same
  thread.

* goversion: update maximum supported version

* Makefile: disable testing lldb-server backend on linux with Go 1.14

There seems to be some incompatibility with lldb-server version 6.0.0
on linux and Go 1.14.

* proc/gdbserial: better handling of signals

- if multiple signals are received simultaneously propagate all of them to the
  target threads instead of only one.
- debugserver will drop an interrupt request if a target thread simultaneously
  receives a signal, handle this situation.

* dwarf/line: normalize backslashes for windows executables

Starting with Go 1.14 the compiler sometimes emits backslashes as well
as forward slashes in debug_line, normalize everything to / for
conformity with the behavior of previous versions.

* proc/native: partial support for Windows async preempt mechanism

See https://github.com/golang/go/issues/36494 for a description of why
full support for 1.14 under windows is problematic.

* proc/native: disable Go 1.14 async preemption on Windows

See https://github.com/golang/go/issues/36494
2020-02-10 17:31:54 -08:00
aarzilli
adb1746c60 proc: fix inlined stack reading for midstack inlined calls
Due to a bug in the Go compiler midstack inlined calls do not report
their ranges correctly. We can't check if an address is in the range of
a DIE by simply looking at that DIE's range, we should also recursively
check the DIE's children's ranges.

Also fixes the way stacktraces of midstack inlined calls are reported
(they used to be inverted, with the deepest inlined stack frame
reported last).

Fixes #1795
2020-01-10 09:04:48 +01:00
aarzilli
a8606afb0b proc,service: return build informations for each package
Adds an API call that returns a list of packages contained in the
program and the files that were used to build them, and also a best
guess at which filesystem directory contained the package when it was
built.

This can be used by IDEs to map file paths if the debugging environment
doesn't match the build environment exactly.
2020-01-09 20:19:02 +01:00
aarzilli
059c51ea0c proc: fix loclist access for Position Independent Executables 2020-01-02 09:30:55 -08:00
hengwu0
2a68058b4a delve: support linux-arm64 native debug(#118)
* delve now can be built to arm64-arch and running on linux-arm64 OS.
* arm64 general-purpose registers have completed.
* arm64 disasm has completed.

Co-authored-by: tykcd996 <tang.yuke@zte.com.cn>
Co-authored-by: hengwu0 <wu.heng@zte.com.cn>
2019-11-27 11:07:31 -08:00
Alessandro Arzilli
151de14d08 proc: support DW_AT_go_package_name (#1757)
Use the name specified by compile unit attribute DW_AT_go_package_name,
introduced in Go 1.13, to map package names to package paths, instead of
trying to deduce it from names of types.
Also use this mapping for resolving global variables and function
expressions.
2019-11-25 09:10:18 -08:00
Alessandro Arzilli
834591f4b6 proc: make ignorable errors reading debug_info look less scary (#1767)
We used to not do anything say anything at all about them anyway.
2019-11-25 09:06:30 -08:00
Derek Parker
c902522a8c pkg/proc,pkg/dwarf: Introduce loclist package
Move the loclist code out of proc and into its own package in
`pkg/dwarf`.
2019-11-13 18:30:21 +01:00
Alessandro Arzilli
222deeec36 proc,debugger: implement logical breakpoints (#1717)
Modifies FindFileLocation, FindFunctionLocation and LineToPC as well as
service/debugger to support inlining and introduces the concept of
logical breakpoints.

For inlined functions FindFileLocation, FindFunctionLocation and
LineToPC will now return one PC address for each inlining and one PC
for the concrete implementation of the function (if present).

A proc.Breakpoint will continue to represent a physical breakpoint, at
a single memory location.

Breakpoints returned by service/debugger, however, will represent
logical breakpoints and may be associated with multiple memory
locations and, therefore, multiple proc.Breakpoints.

The necessary logic is introduced in service/debugger so that a change
to a logical breakpoint will be mirrored to all its physical
breakpoints and physical breakpoints are aggregated into a single
logical breakpoint when returned.
2019-11-01 12:41:06 -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
Alessandro Arzilli
ccf57b9454 terminal: let 'list' work on file:line exprs that don't map to code (#1728)
Make the 'list' command succeed for file:line expressions that don't
map to any instruction.
Adds an argument to the FindLocations API call that makes FindLocations
return if the expression can be parsed, even if it doesn't end up
matching any instruction in debug_line.
2019-10-25 09:59:18 -07:00
Alessandro Arzilli
45fb477379 proc: better handling of bad DW_TAG_inlined_subroutine without debug_line (#1722)
Avoid crashing with nil pointer dereference, signal error instead.

Fixes #1720
2019-10-21 10:43:03 -07:00
Alessandro Arzilli
ca6c6301cd proc: refactor dwarf function information loading (#1685)
Splits the code that loads function information from debug_info into
multiple functions.
This makes the changes needed to implement logical breakpoints easier
to make.
2019-10-07 09:38:47 -07:00
Heschi Kreinick
8954858ee8 proc: round TLS segment size to its alignment (#1682)
The fix for #1428 was buggy, partly because I communicated poorly. Sorry
about that.

The size of the TLS segment should be padded such that TLS addresses
are congruent in the file to where they will end up memory, i.e.
(tlsoffset%align) == (vaddr%align). In most cases, vaddr will be aligned
and it won't matter, but if not then simply aligning the end of the
segment is incorrect. This should be right.

(For the record, the current rounding logic is working in bits, but
PtrSize is in bytes, so it wasn't working as originally intended
either.)
2019-09-04 09:01:53 -07:00
Alessandro Arzilli
a3e884e55c proc: discard variables with address 0 in disassembly sym lookup (#1668)
They are irrelevant and confusing.
2019-08-14 08:58:27 -07:00
David Chase
440aa31bc6 proc: add *Function.PrologueEndPC to support optargorder tool (#1663)
Intent here is to bring optargorder up to date with delve
and keep it in sync (and to use optargorder to help monitor
compiler output for debugging quality regressions).
2019-08-13 11:13:28 -07:00
Derek Parker
094915e4aa pkg/proc: Drop state from BinaryInfo
Remove `initialized` member in favor of just deriving the information it
represented.
2019-08-10 14:03:12 +02:00
Derek Parker
b87813e177 pkg/proc: Remove extra struct members in BinaryInfo 2019-08-10 14:03:12 +02:00
Derek Parker
1b9ae4188d pkg/proc: Consolidate BinaryInfo/Image methods
The methods for the BinaryInfo and Image structs were spread around in
multiple files. This patch just brings them all under one file.
2019-08-10 14:03:12 +02:00
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