Commit Graph

244 Commits

Author SHA1 Message Date
Andrei Matei
6d412c65da
rpc2, debugger: Fix comments around goroutine grouping (#3374) 2023-06-06 20:44:51 -07:00
Alessandro Arzilli
407ace96c8
debugger: inline clearBreakpoint, createLogicalBreakpoint (#3389) 2023-05-31 10:21:12 -07:00
Alessandro Arzilli
e95ae9c21b
proc,terminal: read command line of new processes (#3346)
Read the command line of the main target process as well as any other
process Delve attaches to in follow exec mode.
The command line can be viewed using the 'target list' command.

In follow exec mode this command line is used to match the follow exec
regex to decide whether or not to attach to a child process.

On macOS or when using rr the list of arguments is not available for
attached processes since there is no way to use the gdb serial protocol
to read it.

Fixes #2242
2023-05-09 11:40:00 -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
Oleksandr Redko
5f588d8927 service/dap,service/debugger: refactor regexp funcs
Use regex.MatchString and regex.MustCompile.
2023-04-28 17:23:35 +02:00
Alessandro Arzilli
a61ccea65a
service/debugger,terminal: API and user interface for follow exec mode (#3286)
Updates #2551
2023-04-24 14:37:31 -07:00
Alessandro Arzilli
83a2555497
debugger: do not panic if defer location can not be found (#3329)
convertDefers should not try to dereference nil if the deferred
location does not belong to a function.
2023-04-24 13:38:19 -07:00
Joseph Callen
c0b0148525
cmd/dlv: Add flag to replay for rr onprocess pid (#3281)
Add `-p` or `rr-onprocess-pid` to replay
command to pass `-p` or `--onprocess` pid
to `rr`.
2023-03-01 11:28:32 -08:00
Alessandro Arzilli
37e44bf603
proc,proc/native: adds ability to automatically debug child processes (#3165)
Adds the ability to automatically debug child processes executed by the
target to the linux native backend.
This commit does not contain user interface or API to access this
functionality.

Updates #2551
2023-02-22 09:26:28 -08: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
Derek Parker
3847b7a199
debugger,terminal: Allow setting and clearing breakpoints after process exit (#3246)
This patch allows users to set a breakpoint even when the process has
exited. It will be left in a pending state until the process is
restarted.

Fixes #3242
2023-01-06 18:37:35 +01:00
Andrei Matei
983624c484
service/debugger: fix comment on EvalVariableInScope (#3225) 2022-12-20 10:06:54 -08:00
Alessandro Arzilli
2c10bb3e25
service/debugger: allow setting a breakpoint with a specific ID (#3185)
Before 4c5b111a it was possible for a client to create a breakpoint
with a specific logical ID, restore this ability for backwards
compatibility.
2022-11-08 10:33:25 -08:00
Derek Parker
b072f61bf8
service/debugger: Assume current dir for exec (#3167)
This patch modifies the behavior of the exec subcommand such that
you don't necessarily have to write the "./" prefix when trying
to debug a precompiled binary in your working directory.

For example (given foo.test in working dir), before this change:

dlv exec foo.test

Would result in an error, forcing the user to type:

dlv exec ./foo.test

This just makes things a bit more convenient.
2022-10-28 14:59:09 +02: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
ec5fcc07fe
proc,service/debugger: track how breakpoints were originally set (#3148)
Adds field to breakpoint struct to track how a breakpoint was
originally set, moves the logic for disabling and enabling a breakpoint
to proc.
This will allow creating suspended breakpoints that are automatically
enabled when a plugin is loaded. When follow exec mode is implemented
it will also be possible to automatically enable breakpoints (whether
or not they were suspended) on new child processes, as they are
spawned.

It also improves breakpoint restore after a restart, before this after
a restart breakpoints would be re-enabled using their file:line
position, for breakpoints set using a function name or a location
expression this could be the wrong location after a recompile.

Updates #1653
Updates #2551
2022-09-28 11:35:07 -07:00
Alessandro Arzilli
a73eaeffd2
proc,service: change FindLocation to work with multiple targets (#3103)
Changes FindLocation to support multiple targets and adds an AddrPid
member to api.Breakpoint so that clients can set breakpoints by address
when multiple targets are connected (but at them moment this field is
ignored).

Updates #1653
Updates #2551
2022-09-26 10:12:34 -07:00
Alessandro Arzilli
8337b5a8a9
service/debugger: merge attachErrorMessage, verifyBinaryFormat (#3142)
These functions don't need to be conditionally compiled and they share
substanatial amounts of code in all their OS-specific versions.
2022-09-21 09:48:35 -07:00
Alessandro Arzilli
5b9f65dac2
*: switch to int64 for goroutine IDs (#3110)
Go 1.20 switched to uint64 to represent goroutine IDs, we can't
actually follow suit because we have allowed clients to use -1 to refer
to the currently selected goroutine, however we should at least switch
to int64 and also update the rtype check to accept the 1.20 type.
2022-08-16 09:31:11 -07:00
Alessandro Arzilli
65cfd25787
service/debugger: refactor state/collectBreakpointInfo for TargetGroup (#3064)
Change service/debugger.(*Debugger).state and collectBreakpointInfo
methods so that they work with TargetGroup.

Updates #2551

when running custom builds
abstraction
on '5660f9a4'.
2022-08-09 10:03:45 -07:00
Derek Parker
5c5fca4849
pkg/proc/internal/ebpf: Fix handling of entry / return (#3081)
This patch removes the old error-prone way of tracking
whether the tracepoint is for a function entry or
return. Instead of trying to guess, let the data structure
simply tell us directly.
2022-07-29 12:00:32 +02:00
Alessandro Arzilli
6f34add5db
proc,service/debugger: introduce TargetGroup abstraction (#3030)
Introduces a new TargetGroup abstraction that can be used to manage
multiple related targets.
No actual management of child processes is implemented here, this is
just a refactoring to make it possible to do that in the future.

Updates #2551
2022-07-14 14:14:45 -07:00
roketyyang
278e4d10c8
terminal/command: add -per-g-hitcount option to condition command (#3055)
Support use per goroutine hitcount as hintcond operand.

Fixes #3050

Co-authored-by: roketyyang <roketyyang@tencent.com>
2022-07-12 10:31:34 +02:00
Alessandro Arzilli
78471b3a5a
proc,service: represent logical breakpoints explicitly (#2946)
Adds a LogicalBreakpoint type to represent logical breakpoints
explicitly. Until now logical breakpoints were constructed implicitly
by grouping physical breakpoints together by their LogicalID.

Having logical breakpoints represented explicitly allows for a simpler
implementation of disabled breakpoints, as well as allowing a simple
implementation of delayed breakpoints (#1653, #2551) and in general of
breakpoints spanning multiple processes if we implement debugging
process trees (#2551).

Updates #1653
Updates #2551
2022-05-25 13:58:26 -07:00
polinasok
705ab206cd
dap: remote attach must not use terminateDebuggee in single-client launch mode (#2995) 2022-05-18 12:23:47 +02:00
polinasok
6c368b78a9
debugger: clarify no debug info errors (#2954)
* debugger: clarify no debug info errors

* Fix typo

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2022-04-01 10:31:03 -07:00
Alessandro Arzilli
4c5b111abb
proc,debugger: move breakpoint ID counter to service/debugger (#2913)
Moves breakpoindIDCounter out of BreakpointsMap and into
service/debugger.Debuggger to simplify proc.Target's API and aid with
implementing fork follow mode, where we'll have to debug multiple
processes simultaneously.
2022-02-25 10:09:53 +01: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
Fabio Falzoi
79d5db24a5
Automatically disable breakpoints with hitcount conditions that will never be satisfied again (#2833)
* service/debugger: disable breakpoints with hitcond not satisfiable

To avoid slowing down the debugged process unnecessarily, we disable
breakpoints with a hit condition that can no longer be hit again.

* test: add integration tests for hit conditions no more satisfiable

* proc/test: fix typo in breakpoints related tests

* test: use the new API for hitcond integration tests
2022-01-06 09:00:46 -08:00
Alessandro Arzilli
b192d84670
service: use name w/o parameters for breakpoints on generic funcs (#2774)
When printing breakpoints on generic functions use the function name
without parameters instead of using the name of the first instantiation
that appears on the list.
2021-12-13 11:41:28 -08:00
Alessandro Arzilli
617d934d3e
proc/gdbserial: allow rewind to work after process exit with rr (#2815)
* service/debugger: fix bug internal err with Restart on recorded target

If Restart is called after a Continue and Rewind on a recorded target
that has already terminated it will return an internal error.

* proc/gdbserial: allow rewind to work after process exit with rr

It is sometimes useful to set breakpoints and rewind a terminated
process when using rr, for example if interested in the last execution
of some function.
RR will not allow a backward continue after the process exit packet has
been  sent, however rr will also generate a synthetic SIGKILL right
before process exit.
Treat this packet as a process exit and change some things so both
continuing backwards and setting breakpoints can be done, on recorded
targets, after process exit has been reported.
2021-12-13 11:39:20 -08:00
Alessandro Arzilli
01b01423ae
proc/*: minor miscellaneous code cleanups (#2790)
* made Pid a method of Target instead of a method of Process
* changed argument of NewTarget to ProcessInternal, since that's the
  interface that backends have to implement
* removed warnings about ProcessInternal since there is no way for
  users of pkg/proc to access those methods anyway
* made RecordingManipulation an optional interface for backends, Target
  supplies its own dummy implementation when the backend doesn't
* inlined small interfaces that only existed to be inlined in
  proc.Process anyway
* removed unused function findExecutable in the Windows and no-native
  darwin backends
* removed (*EvalScope).EvalVariable, an old synonym for EvalExpression
2021-11-26 08:06:23 -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
Derek Parker
689e08260b
eBPF tracing backend return value parsing (#2704)
Add return value parsing for eBPF tracing backend.
2021-10-25 12:37:36 -07:00
Alessandro Arzilli
a97da22762
proc: do not assign temporary breakpoint IDs (#2650)
Internal breakpoints do not need IDs and assigning them from a counter
separate from the user ID counter can be a cause of confusion.
If a user breakpoint is overlayed on top of a pre-existing internal
breakpoint the temporary ID will be surfaced as if it was a user ID,
possibly conflicting with another user ID.
If a temporary breakpoint is overlayed on top of a pre-existing user
breakpoint and the user breakpoint is first deleted and then
re-created, the user ID will be resurrected along with the breakpoint,
instead of allocating a fresh one.

This change removes internal breakpoint IDs entirely, only user
breakpoints receive an ID.
2021-09-29 12:01:37 +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
polinasok
efc4483175
pkg/goversion: visibly warn the user with --check-go-version=false (#2684)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-09-25 17:41:00 +02:00
Suzy Mueller
4b30ba4228
service/dap: add basic log points (#2634)
Log points are special kinds of breakpoints that do not 'break' but instead log a message and then continue. This change implements basic log points that simply log the provided message, without any interpolation.

In order to resume execution after hitting a breakpoint, I added a new lock resumeMu and tracked the running state within the DAP server. resumeMu must be held in order to issue a debugger request that would start execution. This means it can be used to make sure that another goroutine does not resume execution while you are holding the lock.

Most of the synchronization logic is taken from PR #2530

Updates golang/vscode-go#123
2021-09-24 15:22:32 -07:00
Suzy Mueller
e00670b901
service/debugger: return correct exit status on manual halt (#2674)
* service/dap: add test for nonzero exit status
2021-09-24 15:18:28 -07:00
Derek Parker
1b2f7f0051
pkg/proc: Parse Goroutine ID in eBPF tracer (#2654)
This patch enables the eBPF tracer backend to parse the ID of the
Goroutine which hit the uprobe. This implementation is specific to AMD64
and will have to be generalized further in order to be used on other
architectures.
2021-08-24 14:53:27 +02:00
Alessandro Arzilli
4264bf00f2
proc,terminal,service: support stack watchpoints (#2521)
* terminal,service: add way to see internal breakpoints

Now that Delve has internal breakpoints that survive for long periods
of time it will be useful to have an option to display them.

* proc,terminal,service: support stack watchpoints

Adds support for watchpoints on stack allocated variables.

When a stack variable is watched, in addition to the normal watchpoint
some support breakpoints are created:

- one breakpoint inside runtime.copystack, used to adjust the address
  of the watchpoint when the stack is resized
- one or more breakpoints used to detect when the stack variable goes
  out of scope, those are similar to the breakpoints set by StepOut.

Implements #279
2021-08-09 10:41:25 -07:00
Alessandro Arzilli
f3e76238e3
proc: move breakpoint condition evaluation out of backends (#2628)
* proc: move breakpoint condition evaluation out of backends

Moves breakpoint condition evaluation from the point where breakpoints
are set, inside ContinueOnce, to (*Target).Continue.

This accomplishes three things:

1. the breakpoint evaluation method needs not be exported anymore
2. breakpoint condition evaluation can be done with a full scope,
   containing a Target object, something that wasn't possible before
   because ContinueOnce doesn't have access to the Target object.
3. moves breakpoint condition evaluation out of the critical section
   where some of the threads of the target process might be still
   running.

* proc/native: handle process death during stop() on Windows

It is possible that the thread dies while we are inside the stop()
function. This results in an Access is denied error being returned by
SuspendThread being called on threads that no longer exist.

Delay the reporting the error from SuspendThread until the end of
stop() and only report it if the thread still exists at that point.

Fixes flakyness with TestIssue1101 that was exacerbated by moving
breakpoint condition evaluation outside of the backends.
2021-08-09 10:16:24 -07:00
Derek Parker
7caa534d76
service/debugger: Remove target lock on GetBufferedTracepoints (#2645)
There is already a lock on the actual buffered tracepoints collection
within proc, and this method call doesn't do anything to mutate Target
otherwise so we shouldn't be opening ourselves up for a race condition
error or any other kind of parallelism problem.

Additionally, with this lock we essentially can never get the data until
the process has exited becuase `continue` will lock the target. This
change allows us to get the buffered tracepoint information immediately
and display it as the program is running.
2021-08-05 13:53:09 +02:00
Derek Parker
10406f96d5
*: Initial eBPF tracing support (#2625) 2021-07-31 17:16:26 +02:00
Alessandro Arzilli
658d36cb19
proc: allow multiple overlapping internal breakpoints (#2519)
Changes Breakpoint to allow multiple overlapping internal breakpoints
on the same instruction address.
This is done by changing the Breakpoint structure to contain a list of
"breaklets", each breaklet has a BreakpointKind and a condition
expression, independent of the other.
A breakpoint is considered active if any of its breaklets are active.
A breakpoint is removed when all its breaklets are removed.
We also change the terminology "internal breakpoint" to "stepping
breakpoint":

HasInternalBreakpoints -> HasSteppingBreakpoints
IsInternal -> IsStepping
etc...

The motivation for this change is implementing watchpoints on stack
variables.
Watching a stack variable requires also setting a special breakpoint to
find out when the variable goes out of scope. These breakpoints can not
be UserBreakpoints because only one user breakpoint is allowed on the
same instruction and they can not be internal breakpoints because they
should not be cleared when a next operation is completed (they should
be cleared when the variable watch is cleared).

Updates #279
2021-07-21 08:24:19 -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
Alessandro Arzilli
1b0c4310c4
proc: give unique addresses to registerized variables (#2527)
We told clients that further loading of variables can be done by
specifying a type cast using the address of a variable that we
returned.
This does not work for registerized variables (or, in general,
variables that have a complex location expression) because we don't
give them unique addresses and we throw away the compositeMemory object
we made to read them.

This commit changes proc so that:

1. variables with location expression divided in pieces do get a unique
   memory address
2. the compositeMemory object is saved somewhere
3. when an integer is cast back into a pointer type we look through our
   saved compositeMemory objects to see if there is one that covers the
   specified address and use it.

The unique memory addresses we generate have the MSB set to 1, as
specified by the Intel 86x64 manual addresses in this form are reserved
for kernel memory (which we can not read anyway) so we are guaranteed
to never generate a fake memory address that overlaps a real memory
address of the application.

The unfortunate side effect of this is that it will break clients that
do not deserialize the address to a 64bit integer. This practice is
contrary to how we defined our types and contrary to the specification
of the JSON format, as of json.org, however it is also fairly common,
due to javascript itself having only 53bit integers.

We could come up with a new mechanism but then even more old clients
would have to be changed.
2021-07-02 18:37:55 +02:00
Alessandro Arzilli
7c82164264
terminal,service: Add filtering and grouping to goroutines command (#2504)
Adds filtering and grouping to the goroutines command.

The current implementation of the goroutines command is modeled after
the threads command of gdb. It works well for programs that have up to
a couple dozen goroutines but becomes unusable quickly after that.

This commit adds the ability to filter and group goroutines by several
different properties, allowing a better debugging experience on
programs that have hundreds or thousands of goroutines.
2021-07-01 11:25:33 -07:00
Derek Parker
96b379b5a2
service/debugger: improve CreateBreakpoint docs (#2553)
The existing documentation was a little light on details. This patch
gives more insight into how the argument to this function is used and
interpreted.

* service/rpc2,service/debugger: more doc updates

Combine debugger.CreateBreakpoint documentation with the documentation
that already existed for the rpc2 server CreateBreakpoint method.

Also adds more contextual information for both the server and client
with links to debugger.CreateBreakpoint documentation.
2021-06-29 15:14:24 +02:00
Suzy Mueller
1ebfc5c37b
service/dap: add throw reason to exception info (#2524)
We can get the throw reason by looking at the argument "s" in runtime.throw. This is not currently working in Go 1.16 or Go 1.17 (see golang/go#46425), but does work in Go 1.15 and Go 1.14
2021-06-28 08:39:34 -07:00