286 Commits

Author SHA1 Message Date
e61c678d6b pkg/terminal: allow custom starlark commands to be used in on prefix (#4170)
Fixes #4160
2025-10-16 13:56:19 +02:00
79cc19a7a4 service/debugger: use address in ClearBreakpoint only when ID is 0 (#4168)
We've always said that predefined breakpoints (like the
unrecovered-panic breakpoint) are just like any other breakpoint and
clients can remove them by using the ClearBreakpoint API.
However commit 78471b3a in 2022 made this not true by treating negative
IDs (which is what we assign to predefined breakpoints) specially.

That change was made as part of a series of changes to support
debugging child processes: prior to that change breakpoints were
cleared by address only (which worked fine for predefined breakpoints)
but this was not tenable for multiprocess debugging.
So ClearBreakpoint was changed to clear breakpoints by breakpoint ID
and only use address in a backward compatibility mode when no ID was
specified.

The current implementation of ClearBreakpoint works fine for user
breakpoints in all cases and for predefined breakpoints as long as
there is only one target process (clearing a predefined breakpoint will
be processed in backwards compatibility mode using its address).

However it should be possible to clear predefined breakpoints even when
Delve is attached to multiple processes. For this reason limit the
backwards compatibility mode of ClearBreakpoint to only ID == 0,
sparing negative IDs as valid.
2025-10-06 14:45:58 -04:00
e835184aff Add flag to retain trace directory after detach (#4091)
* Add flag to retain trace directory after detach
Fixes https://github.com/go-delve/delve/issues/4079

* Addressing review comments

* To fix test errors coming in issue 4051

* Skip TestIssue4051 for rr backend

* Address remaining review comments
2025-09-10 11:50:46 -04:00
8da93b0620 proc,service,terminal: allow cancelling of debuginfod downloads (#4123)
Adds an RPC call to cancel in-progress debuginfod-find downloads. Wires
this call to ^C in the terminal interface and to receiving a Pause
request while already pausing in DAP.
Adds a new terminal command to download the debug info for libraries
for which it hasn't been downloaded already.

Fixes #3906
2025-09-10 11:49:58 -04:00
b1fcbdbb25 debugger: check that breakpoint exists in ClearBreakpoint (#4141)
ClearBreakpoint should check that the breakpoint exists before trying
to manipulate it.

Fixes #4137
2025-09-10 11:24:06 -04:00
3bd31d1534 service: remember that we attached in WaitFor attach mode (#4120)
Save the attached to PID to the configuration when WaitFor is used so
that we later know that we attached and behave identically to when the
normal attach command is used, particularly with respect to killing the
process on exit.

Fixes #4119
2025-08-31 12:04:02 -04:00
61573cffb3 *: modernize codebase with newer syntax / helpers (#4110)
Changes came from running
https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
on the codebase.
2025-08-29 15:50:08 +02:00
17acdb87a7 proc,service,terminal: add events call use it for dld notifications (#3980)
Add a GetEvents method that can be used to retrieve debug events, adds
events for downloading debug info through debuginfod and shows those
events in the command line client as well as console messages in DAP.

In the future this events mechanism can be used to unify EBPF
tracepoints with old style tracepoints.

Update #3906
2025-08-04 08:12:48 -07:00
2e8df9d9b6 service/debugger,rpc2,dap: target locking review (#3997)
We had a few problems with missing targetMutex acquisitions in
service/debugger, this commit takes care of a few other methods (although I
don't think any of these are problems in practice).

- DwarfRegisterToString is removed, there is no need to call this method
  outside of the context of ScopeRegisters/ThreadRegisters which can
  directly return the function that DwarfRegisterToString would call
- add lock acquisition to BuildID
- remove Target, TargetGroup, TargetLock and TargetUnlock. Replace them with
  a single LockTargetGroup method that acquires the lock and returns the
  target group and the unlock function. Callers can still misuse
  LockTargetGroup by calling unlock immediately and continuing to use the
  target group but this is harder to do accidentally compared to the others.
2025-05-21 12:46:59 -07:00
193f21e49b proc: replace Thread.Location method with a function (#3972)
Replaces the Thread.Location method with a ThreadLocation function. All
backends implemented the Location method exactly the same way, this
change deduplicates it.
2025-04-07 11:45:17 -07:00
cc4343bff6 debugger: add missing targetMutex protection to CreateWatchpoint() (#3973)
as discussed in https://github.com/go-delve/delve/issues/3970#issuecomment-2779013352 ,
CreateWatchpoint() is missing mutex protection. This commit corrects
this oversight
2025-04-07 11:43:45 -07:00
b0adcfbde3 debugger: acquire missing lock to GuessSubstitutePath (#3963)
Acquire missing targetMutex lock in GuessSubstitutePath. This fixes
TestGuessSubstitutePath with the rr backend.
2025-04-02 09:35:06 -07:00
f6e0c3e59b service/debugger: fix FindLocation with child processes (#3937)
FindLocation should only return a "location not found" error if none of
the attached target processes can find the location.

Fixes #3933
2025-03-13 11:03:45 -07:00
b329489c6c goversion: add check for DWARFv5 compatibility (#3943)
Due to #3861 which was fixed in:

https://go-review.googlesource.com/c/go/+/656675
https://go-review.googlesource.com/c/go/+/655976

debugging DWARFv5 executables only works if Delve itself is built with
1.25 or later. Add this check to the version compatibility checks.

Fixes #3861
2025-03-13 10:59:21 -07:00
d97b471292 pkg/proc,service/debugger: do not disable unsatisfiable breakpoints (#3868)
Previously breakpoints with hitcount conditions that became
unsatisfiable
would become disabled, this was done as an optimization so that the
continue loop would no longer need to stop on them and evaluate their
conditions.
As a side effect this meant that on restart these breakpoints would
remain disabled, even though their hit condition returned satisfiable.

This commit changes Delve behavior so that breakpoints with
unsatisifiable hitcount conditions are no longer disabled but the
associated physical breakpoints are removed anyway, preserving the
optimization.

Some refactoring is done to the way conditions are represented and the
enable status is managed so that in the future it will be possible to
use hitcount conditions to implement "chained" breakpoints (also known
as dependet breakpoints), i.e. breakpoints that become active only
after a second breakpoint has been hit.
2024-12-04 19:07:56 -08:00
9af09688ea feat: print a message when the debuggee process exits (#3870)
Co-authored-by: Jake Ng <jakejx.ng@gmail.com>
2024-12-02 11:12:51 -08:00
091e5535ab all: remove redundant err declarations (#3855) 2024-11-12 08:04:22 -08:00
822014b8e8 service,terminal,cmd/dlv: automatically guessing substitute-path config (#3781)
Add command, API calls and launch.json option to automatically guess
substitute-path configuration.
2024-10-31 10:19:08 -07:00
a3d7712752 *: replace uses of uniq with slices.Compact (#3821) 2024-10-01 10:16:49 -07:00
7a801c440b *: remove redundant lines at the start/end of block (#3773) 2024-07-11 13:54:55 +02:00
979e487ac7 service/debugger: evaluate breakpoint vars on g-less threads (#3759)
Use a thread scope to evaluate breakpoint variables if the current
thread does not have an associated goroutine.

Fixes #3758
2024-07-01 11:23:39 -07:00
b9f50fe9b0 pkg/proc,service/debugger: fix debuginfod-find source (#3762)
Fixes bug where the incorrect Build ID could be used to try and download the source for a binary. This is because the Build ID was stored on the BinInfo object for a target and not the image itself.
2024-06-28 09:15:37 +02:00
0d0d2e1b16 *: replace fmt.Errorf with errors.New (#3752) 2024-06-20 21:50:18 +02:00
d673e04662 service: print better message for unattended stops (#3747)
Print a better message when an unattended stop happens for reasons
other than hitting a breakpoint.
2024-06-19 09:57:41 -07:00
89123a0000 pkg/terminal,service/debugger: Support to add a new suboption --follow-calls to trace subcommand (#3594)
* rebasing on master to implement --followcalls

* in progress changes to enable --followcalls

* rebase to master: modified function to add children to funcs array

* modify main traversal loop

* added tests to check different scenarios

* added tests to check different scenarios

* added tests to check different scenarios

* add test to check for overlapping regular expression

* modified type of strings array as a return only

* changed depth to a simple integer instead of a global map

* avoid calling traverse on recursive calls

* Added tests for various call graphs to test trace followfuncs

* Added tests for various call graphs to test trace followfuncs

* Added tests for various call graphs to test trace followfuncs

* made auxillary changes for build to go through for new option follow-calls

* Add support to print depth of the function calls as well

* Added two sample output files for checking

* Bypass morestack_noctxt in output for verification testing

* Corrected newline error by adding newlines only if the line does not match morestack_noctxt

* Added more tests

* Cleanup

* Updated documentation

* fixed error message in fmt.Errorf

* Fixed result of Errorf not used error

* Addressing review comments to fix depth reporting and other issues

* dont invoke stacktrace if tracefollowcalls is enabled, compute depth from main regex root symbol than main.main

* Addressing a part of review comments

* Added changes to allow deferred functions to be picked up for tracing

* Fix issue to avoid printing stack for a simple trace option

* Moving most tests to integration2_test.go and keeping only one in dlv_test.go

* Moving most tests to integration2_test.go and keeping only one in dlv_test.go

* Adding panic-defer test case

* Moved rest of the tests to integration2_test.go

* addressing review comments: folding Functions and FunctionsDeep, reducing branches by using depth prefix, wrap using %w and other comments

* Optimize traversal and parts of printing trace point function and modify trace output layout
and adjust tests accordingly

* Resolved error occurring due to staticcheck

* Implemented traversal algorithm using breadth first search

* Addressing review comments on the breadth first search implementation and
other comments

* Inline filterRuntimeFuncs and remove duplicate initialization
2024-06-12 12:35:48 -07:00
15a9f9d353 cmd/dlv: print out message with stack trace when breakpoint is hit but has no waiting client (#3632)
* Print out message and dump stack on pause

* Fix test

* Move the logic to debugger layer

* Remove unused fields

* Do not use defer to get state

* move channel to connection

* remove lock on isClosed

* Use mutex

* Remove unwanted changes
2024-06-12 12:31:46 -07:00
8347f97c00 *: remove redundant lines at the start/end of block (#3730) 2024-05-20 14:16:22 -07:00
bba7547156 pkg/proc: fix watchpoints on macos (#3703)
It seems newer MacOS kernels are sending mach exceptions for watchpoints
which contain the hardware register number as opposed to the address
which triggered the exception. Also, ARM64 seems to have switched to
sending _EXC_I386_SGL as medata[0] for this exception type.
2024-04-29 14:06:32 +02:00
29aa2ea8c9 pkg/terminal,pkg/proc: Implement next-instruction (#3671)
The next-instruction (nexti) command behaves like
step-instruction (stepi) however, similar to the
`next` command it will step over function calls.
2024-02-28 09:28:33 +01:00
4a72c523be pkg/proc: remove usage of gore dependency (#3664) 2024-02-21 12:10:41 +01:00
ef20fbbf12 proc/gdbserver: clean up rr directory on detach (#3570)
We used to autoremove the trace recorded by rr but as a result of
various refactorings done to implement follow exec mode this broke.
Restore the functionality.

Also remove the _fixtures/testfnpos.go file which is autogenerated
during testing.
2024-01-24 09:21:20 -08:00
c727ec52c5 service: fix a bunch of linter warnings from GoLand (#3551) 2023-11-05 17:36:37 +01:00
e404917db7 pkg,service: fix typos in comments, exceptions, tests (#3486) 2023-08-29 14:44:18 +02:00
0b35fe6d42 proc,service,terminal: add ways to list goroutines waiting on a channel (#3481)
Adds -chan option to the goroutines command to list only the goroutines
running on a specified channel.
Also when printing a variable if it is a channel also print the list of
goroutines that are waiting on it.
2023-08-23 13:02:34 -07:00
6a0423a1e9 proc: when stepping set condition on thread ID if there is no curg (#3475)
If there is no current goroutine when 'next', 'step' or 'stepout' are
used set a condition that the thread ID should stay the same instead.
This makes stepping work for multithreaded C programs or Go programs
that have threads started by cgo code.

Fixes #3262
2023-08-21 12:30:56 -07:00
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
ca611db449 terminal: restore breakpoints set with line offset on restart (#3425)
Change FindLocation so it can return a substitute location expression
and propagate it to pkg/terminal/command.
When breakpoints are set using the syntax :<lineno> or +<lineno>
produce a substitute location expression that doesn't depend on having
a valid scope and can be used to restore the breakpoint.

Fixes #3423
2023-07-20 12:29:59 +02:00
8023fa956e all: use "len == 0" rather than "len <= 0" when checking empty slice/string (#3439) 2023-07-13 11:30:32 -07:00
db0bc26949 terminal,service: better printing of suspended breakpoints (#3415)
Show the location expression that will be used to set a suspended
breakpoint in the breakpoints list.

Also change 'target' called without arguments to print a better error
message and 'target follow-exec' without the last argument to print the
state of follow-exec.
2023-07-07 10:33:40 -07:00
53998cbb18 pkg/proc,service/*: Supports sending output to clients when running programs remotely (#3253)
* wip: Support sending output when remote debug

* wip: Support local output and remote output

* wip: fix stderr and stdout assignment error

* wip: optimize code

* wip: Only if outputMode is "remote" is the redirected console output

* wip: Redirected debugMode output(Not tested on windows)

* wip: support remote debugging output redirection of windows

* wip: real-time write back output

* wip: support for windows

* wip: fix windows remote debug not output

* wip: fix truncated output redirection

* wip: delete printfln

* wip: use debugger.Config to pass redirect(macOS)

* wip: use debugger.Config to pass redirect(linux)

* wip: Change redirect to a concrete type

* wip: s.wg.wait before sending "terminated"

* wip: add proc/redirect test(darwin and linux)

* Merge branch 'master' of github.com:tttoad/delve into feat-console

* wip: Fix test failure on windows

* fix: undefined: proc.Redirects

* fix: compile failure

* wip: Remove useless code

* fix: filename error

* fix: os.file not close

* test: add server_test.redirect

* fix: Remove 'eol' from end of file

* fix: gdbserial: File not closed in file mode.
(in reality, gdbserial will never use file mode)

* feat: Remove "only-remote". Fix spelling mistakes.

* fix: spelling mistakes

* refactor: redirect

* fix: stdout and stderr are not set to default values

* fix: Restore code logic for rr.openRedirects()

* fix: Optimization Code

* fix: utiltest

* fix: execpt out

* fix: Resource release for redirects

* fix: build failure

* fix: clean->clear

* fix: build failure

* fix: test failure

* fix: Optimization Code

* style: remove useless code

* refactor: namedpipe

* refactor: namedpipe, launch ...

* fix: freebsd compile failure

* fix: proc_darwin compile failure

* style:  remove useless code

* feat: add d.config.Stdxx check on debug.Restart

* style: formatting and adding comments

* style: formatting and adding comments

* feat: add d.config.Stdxx check on debug.Restart

* style: namedpipe->redirector

* style: namedPipe->redirector

---------

Co-authored-by: 李翔 <qian.fu2@amh-group.com>
2023-07-05 08:39:01 -07:00
d963eb1057 proc: read context from sigtrampgo, fixes TestCgoStacktrace2 on 1.21 (#3401)
* logflags,proc: flag to log stacktrace execution

Add a log flag to write logs about what the stacktracer does.

* proc: read context from sigtrampgo, fixes TestCgoStacktrace2 on 1.21

Changes stacktrace code to read the signal context from the arguments
of sigtrampgo.
Also changes the automatic fatalthrow breakpoint for go 1.21.
In combination these two changes fix TestCgoStacktrace2 on Go 1.21 on
various platforms.
2023-06-27 09:33:07 -07:00
ccf17a6f42 pkg/proc: enable basic debug functionality for stripped ELF binaries (#3408)
We used to parse the .gopclntab section but removed support in favor of
simply using DWARF debug information, due to lack of C symbols among
other reasons. This makes it impossible to debug stripped binaries,
which some distrubutions ship by default.

Add back in basic support for .gopclntab which survives if the binary
is stripped, allowing for rudimentary debugging such as basic
program navigation, tracing, etc...
2023-06-14 13:23:46 +02:00
6d412c65da rpc2, debugger: Fix comments around goroutine grouping (#3374) 2023-06-06 20:44:51 -07:00
407ace96c8 debugger: inline clearBreakpoint, createLogicalBreakpoint (#3389) 2023-05-31 10:21:12 -07:00
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
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
5f588d8927 service/dap,service/debugger: refactor regexp funcs
Use regex.MatchString and regex.MustCompile.
2023-04-28 17:23:35 +02:00
a61ccea65a service/debugger,terminal: API and user interface for follow exec mode (#3286)
Updates #2551
2023-04-24 14:37:31 -07:00
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
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