Commit Graph

108 Commits

Author SHA1 Message Date
Alessandro Arzilli
1f0b39eab5
proc: fix crash trying to open separate debug info (#2901)
If debugInfoDirectories is set, the executable does not have debug info
and build-id is not set we should not crash.
2022-02-08 10:53:45 -08:00
Morten Linderud
8c392d2fdf
Implement source listing from debuginfo (#2885)
* service: Implement BuildID

Parse the BuildID of executables and provides it over the RPC
service.

Signed-off-by: Morten Linderud <morten@linderud.pw>

* command: Support debuinfod for file listing

Signed-off-by: Morten Linderud <morten@linderud.pw>

* debuginfod: create debuginfod package for common code

We remove the duplicated code and provide our a new debuginfod package.

Signed-off-by: Morten Linderud <morten@linderud.pw>

* starlark: Workaround for 'build_i_d'

Signed-off-by: Morten Linderud <morten@linderud.pw>

* command: Ensure we only overwrite path when one has been found

Signed-off-by: Morten Linderud <morten@linderud.pw>

* bininfo: Inline parseBuildID

Signed-off-by: Morten Linderud <morten@linderud.pw>
2022-01-30 13:39:30 -08:00
Derek Parker
8ddb64c808
pkg/proc: handle double inlined calls (#2880)
It's possible that an inlined function call also contains an inlined
sunroutine. In this case we should also parse the children of
inlined calls to ensure we don't lose this information.
2022-01-24 08:56:37 +01:00
Alessandro Arzilli
df8c2b37ce
proc: always load eh_frame section from executable (#2875)
Always load eh_frame section from the executable file instead of the
split debug info file. The eh_frame section is meant to be loaded in
memory along with the executable file so it will usually not be present
in a split debug info file (or, if it is present, it will be the wrong
one).
2022-01-19 10:40:23 -08:00
Morten Linderud
3b6099cace
bininfo: Strip whitespace from debuginfod-find output (#2876)
Signed-off-by: Morten Linderud <morten@linderud.pw>
2022-01-19 10:25:48 -08:00
Alessandro Arzilli
d95f26c4bd
proc: interpret value of DW_AT_inline correctly (#2859)
All values greater than or equal to 1 indicate that the function has
been inlined.
2022-01-06 09:07:53 -08:00
Alessandro Arzilli
75bbbbb60c
proc: support DWARF5 on Windows/macOS (#2791)
* proc: log errors reading debug_info

Because of an incorrect use of debug/dwarf.Reader errors encountered
while reading debug_info were not reported.

Updates #2786

* proc: use debug_line_str section for PE and Macho-O files

Updates #2786
2021-11-26 08:11:29 -08:00
Alessandro Arzilli
c207db792a
proc,locspec: support setting breakpoints by func name on generic funcs (#2745)
* proc,locspec: support setting breakpoints by func name on generic funcs

Changes proc.Function to parse function names correctly when they
contain instantiation lists and locspec to match generic functions.

* vendor: update golang.org/x/tools

The old version of golang.org/x/tools is incompatible with the new
iexport format.
2021-10-30 11:52:26 -07:00
aarzilli
4e7b689e1a proc: rewrite FindFileLocation to support generics
With generics a single function can have multiple concrete
instantiations, the old version of FindFileLocation supported at most
one concrete instantiation per function and any number of inlined
calls, this supports any number of inlined calls and concrete
functions.
2021-10-02 15:44:30 +02:00
aarzilli
878a52539e proc: use trampoline attribute to detect autogenerated wrappers
Go 1.18 abandoned the 'dwrap' tag introduced by Go 1.17
2021-10-02 15:44:30 +02:00
aarzilli
ee1719f6eb proc: only apply regabiMallocgcWorkaround to first image
The workaround for runtime.mallocgc with regabi should only be applied
to the first image.
2021-10-02 15:44:30 +02:00
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