Commit Graph

143 Commits

Author SHA1 Message Date
Oleksandr Redko
938cb6e9d8
pkg,service: remove unnecessary convertions (#3564) 2023-11-14 16:36:55 +01:00
Alessandro Arzilli
db7e60aef3
proc: move StepInstruction method to TargetGroup (#3488)
Move StepInstruction method to TargetGroup since it will need access to
the process group on Windows to call WaitForDebugEvent.
2023-09-20 09:17:45 +02:00
Alessandro Arzilli
7f094c81e9
proc: refactorings to implement follow-exec mode on Windows (#3441)
Miscellaneous non-functional changes to prepare for adding support for
follow-exec mode on Windows:

- removed (*nativeProcess).wait function from Windows backend (unused).
- move close of ptraceDoneChan from release to handlePtraceFuncs, this
  makes postExit callable by a function executed by execPtraceFunc.
- change addTarget to detach before creating the target object if we
  don't actually want to attach to the child process, also moved the
  detach call to (*processGroup).add instead of having one in addTarget
  and one in the code that calls (*processGroup).add.
- changed Detach to be a method of TargetGroup/ProcessGroup, the
  Windows backend will need access to the process group to call
  WaitForDebugEvent.
- moved resume method to processGroup. First all threads stopped at a
  breakpoint need to be stepped, then all other threads can be resumed.
  This is true also for linux even though it didn't cause the current
  tests to fail.
2023-08-28 12:46:19 -07:00
Oleksandr Redko
8aa0050158
pkg,service: make receiver names consistent (#3473) 2023-08-17 14:24:43 -07:00
Alessandro Arzilli
ec07c27fc7
proc: fix PIE support on macOS (#3467)
Go1.22 switched to emitting PIE by default and also changed some
details of the PIE implementation. This breaks delve entirely on macOS.

Fix how relocations are handled on macOS.
2023-08-14 15:31:05 -07:00
Alessandro Arzilli
dc5d8de320
proc: add waitfor option to attach (#3445)
Adds a waitfor option to 'dlv attach' that waits for a process with a
name starting with a given prefix to appear before attaching to it.

Debugserver on macOS does not support follow-fork mode, but has this
feature instead which is not the same thing but still helps with
multiprocess debugging somewhat.
2023-08-09 10:30:22 -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
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
Aviram Hassan
4050a62c0a
pkg/proc: fix stripping DYLD_INSERT_LIBRARIES on macOS (#3245) 2023-01-04 14:14:23 -08:00
Oleksandr Redko
a6e3d14455
proc: Fix typos in the comments (#3231) 2022-12-28 12:41:13 +01:00
Alessandro Arzilli
a35b902ecf
gdbserial: continue if tcsetpgrp fails (#3211)
Do not stop if tcsetpgrp errors, also only do it if the target process
got its own process group.

Fixes #3210
2022-12-12 08:36:48 -08:00
Alessandro Arzilli
56eed898ec
proc/gdbserver: set child process pgrp as foreground group (#3205)
Newer versions of debugserver (which contain [1]) will spawn the target
process on a new process group, when we detect that this happen, and we
are a headless instance and stdin is a tty, make the child process'
process group the controlling group for the terminal.

 [1] https://reviews.llvm.org/rG33ac4fddc7906ba712c50cd3a9b02ae041d751ab
2022-12-05 09:38:00 -08:00
Aviram Hassan
350dd6afe3
proc/gdbserial/gdbserver: Don't pass DYLD_INSERT_LIBRARIES to debugserver (#3181)
Filter out DYLD_INSERT_LIBRARIES on Darwin when launching debugserver.
This is needed since macOS Ventura, loading custom dylib into debugserver
using DYLD_INSERT_LIBRARIES leads to a crash.
This is unlike other protected processes, where they just strip it out.
2022-11-07 15:26:10 -08: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
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
Alessandro Arzilli
2827145f1e
proc/gdbserver: ignore spurious stop packet from debugserver (#3021)
When we send an interrupt request to debugserver we, sometimes, get one
extra spurious stop packet back.
This stop packet gets interpreted as a response to a qThreadStopInfo request
we make causing the protocol to become desynchronized for a while, until
eventually some kind of error appears.

Here's an example of this problem, distilled from issue #3013:

     1 <- $vCont;c#a8
     2 <- interrupt
     3 -> $T05thread:12efb47;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...
     4 <- $qThreadStopInfo12efb8e#28
     5 -> $T05thread:12efb47;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...
     6 <- $qThreadStopInfo12efb8f#29
     7 -> $T00thread:12efb8e;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...
     8 <- $qThreadStopInfo12efb90#f4
     9 -> $T00thread:12efb8f;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...
    10 <- $qThreadStopInfo12efb91#f5
    11 -> $T00thread:12efb90;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...
    12 <- $qThreadStopInfo12efb47#f6
    13 -> $T00thread:12efb91;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...
    14 <- $qThreadStopInfo12efb8d#27
    15 -> $T05thread:12efb47;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...
    16 <- $p0;thread:12efb8e;#f5
    17 -> $T00thread:12efb8d;threads:12efb47,12efb8d,12efb8e,12efb8f,12efb90,12efb91;thread-pcs:10abe83,7ff81b20e2be,7ff81b20e3ea,...

response (3) is interpreted as the response to the vCont request at (1). We
then make a qThreadStopInfo request (4) and receive a stop packet in
response (5). Packet (5) is interpreted as the response to (4) but it
actually isn't, note how the thread ID is different, packet (5) is actually
a spurious stop packet sent by debug server. From response (5) onward the
protocol is desynchronized, none of the response we process are actually the
response to the preceding request.
This eventually causes a failure at packet (17) which debugserver sent as
the response to request (14) but we interpret as the response to (16).

Fixes #3013
2022-06-08 10:56:50 -07:00
Alessandro Arzilli
32bdd19f8f
proc/gdbserver: fix function call injection on rr (#3007)
Issue https://github.com/rr-debugger/rr/issues/3208 was fixed so finish
fixing call injection on rr and remove the test exception.
2022-05-17 09:19:34 -07:00
Alessandro Arzilli
c9d800edb9
proc: support function call injection on arm64 (#2996)
* _scripts/test_linux.sh,_scripts/test_windows.ps1: always return exit code 0 when testing on tip

Same as what we do for test_mac.sh

* proc: support function call injection on arm64

Support function call injection on arm64 with go1.19
2022-05-03 10:46:24 -07:00
polinasok
0b71eeca40
proc/gdbserial: shut down debuggee when failing to debug (#2953)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2022-04-01 10:31:23 -07:00
Alessandro Arzilli
e1e4b09a5e
proc: move resume notify and manual stop handling to Target (#2921)
Moves handling of ResumeNotify and manualStopRequested to Target instead of the backends

Updates #2551
2022-03-21 12:42:37 -07:00
Alessandro Arzilli
1418cfd385
proc: better handling of hardcoded breakpoints (#2852)
This commit improves the handling of hardcoded breakpoints in Delve.
A hardcoded breakpoint is a breakpoint instruction hardcoded in the
text of the program, for example through runtime.Breakpoint.

1. hardcoded breakpoints are now indicated by setting the breakpoint
   field on any thread stopped by a hardcoded breakpoint
2. if multiple hardcoded breakpoints are hit during a single stop all
   will be notified to the user.
3. a debugger breakpoint with an unmet condition can't hide a hardcoded
   breakpoint anymore.
2022-02-22 09:57:37 -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
b8a9ae26f6
proc: fix signal handling during stepping (#2803)
Fix signal handling during thread single stepping so that signals that
are generated by executing the current instruction are immediately
propagated to the inferior, while signals other signals sent to the
thread are delayed until the full resume happens.

Fixes a bug where a breakpoint set on an instruction that causes a
SIGSEGV would make Delve hang and a bug where signals received during
single step would make it look like an instruction is executed twice.

Fixes #2801
Fixes #2792
2021-12-07 09:21:53 -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
884ef4f338
proc/gdbserial: workaround for debugserver register set bug (#2770)
Debugserver has a bug where writing to a AVX-2 or AVX-512 register does
not work unless it is followed by at least a write to a AVX (not 2 or
512) register.

See also: https://bugs.llvm.org/show_bug.cgi?id=52362

Fixes #2767
2021-10-30 11:51:02 -07:00
Alessandro Arzilli
9a5d5bc996
proc/gdbserial: support call injection with rr backend (#2740)
Normally calls can't be performed on recorded processes, becuase the
future instructions executed by the target are predetermined. The rr
debugger however has a mechanism that allows this by taking the current
state of the recording and allowing it to diverge from the recording,
temporarily.
This commit adds support for starting and ending such diversions around
function calls.

Note: this requires rr version 5.5 of later to work, see:
	https://github.com/rr-debugger/rr/pull/2748
2021-10-14 11:06:14 -07:00
Alessandro Arzilli
348c722981
proc/gdbserver: support watchpoints (#2659)
Adds watchpoint support to gdbserver backend for rr debugger and
debugserver on macOS/amd64 and macOS/arm64.

Also changes stack watchpoints to support reverse execution.
2021-10-04 14:45:05 -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
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
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
Augusto Yao
686989e1b3
debugserver: fix typo in checking whether debugserver support unmask_… (#2581)
* debugserver: fix typo in checking whether debugserver support unmask_signals

* gdbserver.go: fix issues in deepsource:go
2021-07-13 08:37:26 -07:00
polinasok
569b772b82
proc/gdbserial: ContinueOnce returns StopUnknown, not StopExited on non-exited error (#2577)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-12 09:49:02 -07:00
Alessandro Arzilli
c617ed8189
proc/core/minidump,proc/gdbserial: update broken ext links (#2570)
The LLVM project archived their repository and moved it elsewhere,
Microsoft broke their minidump documentation URLs.
2021-07-06 09:28:53 -07:00
Alessandro Arzilli
b9fcb03ff4
proc/native,proc/gdbserial: detect and complain about Rosetta (#2569)
Delve does not run under Rosetta. Detect this condition and point
confused users towards the solution.
2021-07-06 08:53:39 -07:00
Alessandro Arzilli
7f527d26a8
gdbserial: actually fix ZMM register support (#2516)
PR #2498 / commit d552b338 left out some code due to a clerical error.
2021-06-28 08:42:06 -07:00
Suzy Mueller
b2afb7cd20
pkg/proc: add support for hit count condition breakpoints (#2490)
* pkg/proc: implement support for hit count breakpoints

* update comment

* udpate hitcount comment

* update HitCond description

* add test for hit condition error

* respond to review

* service/dap: add support for hit count breakpoints

* use amendbps to preserve hit counts

* update test health doc

* fix failing test

* simplify hit conditions

* REmove RequestString, use name instead

* update backend_test_health.md

* document hit count cond

* fix tests
2021-05-28 11:21:53 -07:00
Alessandro Arzilli
d552b33822
gdbserial,regnum: support ZMM registers, disable 'g' on debugserver (#2498)
Adds DWARF register number and support for AVX-512 registers.
Changes proc/gdbserial so that the 'g' and 'G' commands are never used
with debugserver since they seem to corrupt the thread state when used
on AVX-512 capable hardware.
Also changes TestClientServer_FpRegisters to be simpler and more
resilient to changes to the Go runtime.

Fixes #2479
2021-05-26 08:21:03 -07:00
Alessandro Arzilli
db291698e0
gdbserial: for the 'g' command on debugserver treat E74 as unsupported (#2487)
The maintainer of debugserver says he wants to fix the problem with the
'g' command but doesn't know when it will happen. Treat the error 'E74'
for the 'g' command on debugserver as if the server had returned an
unsupported error so that, for this specific problem, the error doesn't
resurface in the future.
2021-05-17 10:27:33 -07:00
Alessandro Arzilli
58762685e3
proc/native: low level support for watchpoints in linux/amd64 (#2301)
Adds the low-level support for watchpoints (aka data breakpoints) to
the native linux/amd64 backend.

Does not add user interface or functioning support for watchpoints
on stack variables.

Updates #279
2021-05-06 10:33:56 -07:00
Christian Banse
4bd16ad756
Slightly better version check for gdb server on newer macOS (arm64) (#2461)
* proc: Slightly better version check for gdb server on newer macOS

* Adjusted version to be >= 1200 and <= 1205
2021-05-04 12:33:10 -07:00
Alessandro Arzilli
35d4f05c4e
proc: remove duplicate Registers.Get implementations (#2415)
Moves the implementation of Registers.Get out of the backends and into
proc where it can be implemented only once per architecture.
2021-04-28 10:00:26 -07:00
Alessandro Arzilli
3c69f7435e
*: Never use pointer to proc.ErrProcessExited (#2431)
We have some places where we use proc.ErrProcessExited and some places
that use &proc.ErrProcessExited, resulting in checks for process exited
errors occasionally failing on some architectures.
Uniform use of ErrProcessExited to the non-pointer version.

Fixes intermittent failure of TestStepOutPreservesGoroutine.
2021-04-13 08:52:29 +02:00
Alessandro Arzilli
7ace7a8e76
proc/gdbserial: remove unnecessary conditional compilation (#2389)
Remove unnecessary conditionally compiled files introduced with the
darwin/arm64 port.
2021-04-05 11:23:32 -07:00
Alessandro Arzilli
6a70d531bb
proc/*: implement proc.(*compositeMemory).WriteMemory (#2271)
Delve represents registerized variables (fully or partially) using
compositeMemory, implementing proc.(*compositeMemory).WriteMemory is
necessary to make SetVariable and function calls work when Go will
switch to using the register calling convention in 1.17.

This commit also makes some refactoring by moving the code that
converts between register numbers and register names out of pkg/proc
into a different package.
2021-03-04 10:28:28 -08:00
Alessandro Arzilli
2c1a822632
terminal,service,proc/*: adds dump command (gcore equivalent) (#2173)
* proc/core: off-by-one error reading ELF core files

core.(*splicedMemory).ReadMemory checked the entry interval
erroneously when dealing with contiguous entries.

* terminal,service,proc/*: adds dump command (gcore equivalent)

Adds the `dump` command that creates a core file from the target process.

Backends will need to implement a new, optional, method `MemoryMap` that
returns a list of mapped memory regions.
Additionally the method `DumpProcessNotes` can be implemented to write out
to the core file notes describing the target process and its threads. If
DumpProcessNotes is not implemented `proc.Dump` will write a description of
the process and its threads in a OS/arch-independent format (that only Delve
understands).

Currently only linux/amd64 implements `DumpProcessNotes`.

Core files are only written in ELF, there is no minidump or macho-o writers.

# Conflicts:
#	pkg/proc/proc_test.go
2021-01-29 13:39:33 -08:00
Alessandro Arzilli
c40774d3d4
proc: refactor common code in WriteBreakpoint (#2300)
Moves common backend code in WriteBreakpoint to
proc.(*Target).SetBreakpoint.
2021-01-27 07:27:54 -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
fbfad81968
proc/gdbserial: use --unmask-signal debugserver option (#2255)
Fixes #852

Co-authored-by: a <a@kra>
2020-12-10 09:04:35 -08:00
Aaron Sky
579b17ce27
proc/gdbserial: Use the active xcode-select path instead of a hardcoded Xcode path (#2229)
* Use the active xcode-select path instead of a hardcoded Xcode path

* Refactored exec.Command to invoke Output instead of running with a custom buffer for stdout

Addresses review comment by @derekparker
2020-11-17 08:49:15 -08:00