Commit Graph

131 Commits

Author SHA1 Message Date
Alessandro Arzilli
674bd63996
proc: fix runtime type handling for Go 1.21 (#3370)
Go 1.21 renamed runtime._type to internal/abi.Type and changed the name
of its fields. Update Delve so that it uses the new names for loading
interfaces and generic type parameters.
2023-05-15 10:21:52 -07:00
Alessandro Arzilli
13ad7dc1d5
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.

- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more

Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.

The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible

Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 12:23:59 -07:00
Alessandro Arzilli
3507ff977a
proc: support multiple functions with the same name (#3297)
The compiler produces ABI compatibility wrappers for some functions.
We have changed the support for breakpoints to allow a single logical
breakpoint to correspond to multiple physical breakpoints, take
advantage of that to set breakpoints on both the ABI wrapper and the
real function.

Fixes #3296
2023-03-22 11:38:09 -07:00
Gregor Noczinski
260229b979
terminal/logflags: Added SetLoggerFactory(LoggerFactory) (#3257)
* terminal/logflags: Added `SetLoggerFactory(LoggerFactory)`

This change will enable people who want to embed Delve into their applications to adjust the logging better to their needs.

* terminal/logflags: Added `SetLoggerFactory(LoggerFactory)`

Added changes from code review.

* terminal/logflags: Added `SetLoggerFactory(LoggerFactory)`

Reworked requested changes.

* terminal/logflags: Added `SetLoggerFactory(LoggerFactory)`

Reworked requested changes.
2023-02-14 09:46:35 -08:00
Oleksandr Redko
f6e6eadd22
pkg/proc,service/test: refactor to strings.ReplaceAll (#3269)
Use strings.ReplaceAll instead of strings.Replace with -1 as the last argument.
2023-02-14 09:36:24 -08:00
Oleksandr Redko
58fc3931e8
proc/dwarf: Move util functions to dwarf package (#3252) 2023-01-16 09:20:20 -08:00
Hyang-Ah Hana Kim
bbc22707d0
pkg/proc: apply simplifycompositelit analysis fixes (#3236)
https://pkg.go.dev/golang.org/x/tools/internal/lsp/analysis/simplifycompositelit
2023-01-03 08:13:28 -08:00
Oleksandr Redko
a6e3d14455
proc: Fix typos in the comments (#3231) 2022-12-28 12:41:13 +01:00
Alessandro Arzilli
5ca60a81e8
proc: extend macOS workaround to amd64 (#3204)
Go change 064f34f (which exists in Go 1.19.2 and following) removed the
pagezero_size option from linker calls (because it is deprecated). This
expanded the problem that exists on darwin/arm64 as well as PIE builds
on darwin/amd64 to all darwin/amd64 builds.

This problem is described on: https://github.com/golang/go/issues/25841.

This commit extends the darwin/arm64 workaround to darwin/amd64.

Fixes #3194
2022-12-05 09:46:24 -08:00
Alessandro Arzilli
b9a8bd7f41
*: early fixes for go1.20 (#3180)
- updated go/packages to support new export format
- rewrite testinline.go fixture because the compiler got too smart with
  constant folding
- temporarily disable staticcheck on go1.20 because it doesn't support
  the new export format.
- workaround for go.dev/cl/429601
2022-12-05 09:02:22 -08:00
Quim Muntal
f439987f14
G struct offset is a pointer to an offset since go1.20 (#3196) 2022-11-16 09:44:27 -08:00
Daniel Lipovetsky
c7fa713c34
bininfo: Log when the file listed in .gnu_debuglink is not found (#3188) 2022-11-10 09:41:42 -08:00
Alessandro Arzilli
6e7e1d8830
proc,terminal: allow setting suspended breakpoints (#3154)
Allows setting suspended breakpoints and try to enable them
automatically after every time a plugin is loaded.

Fixes #1653
Updates #2551
2022-10-04 08:07:05 -07:00
Alessandro Arzilli
02d46b059e
proc: remove old method to resolve the type of an interface to a DIE (#3150)
Before 1.11 we used to read a bunch of runtime structures to determine
the runtime type of an interface variable. This had significant
dependencies on private structs of the Go runtime and the code is
broken for versions of Go after 1.17.
Remove all this code, since it is no longer used and doesn't work with
newer versions of Go anyway.
2022-09-29 10:06:15 -07:00
Alessandro Arzilli
1effee3576
proc: fix openSeparateDebugInfo backwards compatibility path (#3145)
Fix openSeparateDebugInfo backwards compatibility path to actually be
backwards compatible.
2022-09-26 10:09:06 -07:00
Alessandro Arzilli
b0ac6db339
proc: fix cast to empty interface type (#3146)
Fix cast to empty interface type. This is a workaround for a
discrepancy between how type names are serialized by the compiler vs
how type expressions are formatted by go/printer.
2022-09-26 10:08:01 -07:00
Quim Muntal
4455d6a9ef
Add support for windows/arm64 (#3063)
* Add support for windows/arm64

* split sentinel files and add winarm64 experiment

* update loadBinaryInfoPE to support PIE binaries

* skip TestDump on windows/arm64

* run windows/arm64 compilation on windows/amd64

* add entry point check for pie binaries

* delete unusded code

* document windows/arm64 breakpoint

* implement changing windows/arm64 fp registers

* update crosscall offset names

* fix G load when using CGO

* fix testvariablescgo

* remove DerefGStructOffset

* derefrence gstructoffset in GStructOffset() if necessary
2022-09-21 13:39:44 -07:00
Alessandro Arzilli
0c09fc9bdd
proc: use stdlib to compute CRC for gnu_debuglink section (#3105)
The standard library package has a the CRC algorithm used for
gnu_debuglink, use that instead of our own implementation.
2022-08-16 11:08:53 +02:00
Alessandro Arzilli
2900418e78
proc: support gnu_debuglink section (#3073)
Load separate debug info using gnu_debuglink.

Fixes #2150
2022-07-25 10:01:41 -07:00
Alessandro Arzilli
5660f9a415
dwarf/op,proc: output register name when printing location exprs (#3052)
Output the architecture specific register name when printing location
expression after DW_OP_regN and DW_OP_bregN operators.
2022-07-15 14:56:00 +02:00
Alessandro Arzilli
c412dcdc4f
*: run go1.19 'go fmt' on everything and fix problems (#3031)
Go 1.19 also formats doc comments according to the new godoc syntax.
Some of our comments, especially unexported symbols did not conform to
the godoc syntax and therefore are mangled by 'go fmt'.

This PR runs 'go fmt' from go1.19 on everything and manually fixes the
problems.

See also:
	https://github.com/golang/proposal/blob/master/design/51082-godocfmt.md
2022-06-17 10:08:11 -07:00
cui fliter
9a9c1a9f33
*: fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-23 16:10:00 +01:00
Alessandro Arzilli
a646d06544
proc: downgrade loadBuildID errors to warnings (#2893)
Most binaries do not have build-ids and it's fine, there's no reason to
report it as an error.
2022-02-08 10:54:05 -08:00
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