Commit Graph

128 Commits

Author SHA1 Message Date
Ville Skyttä
d7f104bf9c
cmd/dlv: fix panic on connect fail (#3698) 2024-04-11 07:12:42 +02:00
Ville Skyttä
2c946bcbd0
cmd/dlv: add shell (non-)completions to flags taking args (#3696)
Mostly to avoid the default filename completions to flags that don't
operate on filenames. Then again, mark ones that do explicitly as
such, and add more specific completions for a number of other cases,
too.
2024-04-09 11:04:55 -07:00
Alessandro Arzilli
f32818c9e3
cmd/dlv: fix --continue with unix domain sockets (#3658)
Fixes #3657
2024-02-13 10:14:38 -08:00
Alessandro Arzilli
4f5b74a651
cmd/dlv: support unix domain sockets (#3655)
Add support for listening on a unix domain socket in headless mode and
in the 'connect' command.

Fixes #3654
2024-02-07 11:04:45 -08:00
Derek Parker
ff7a9f9f9a
cmd: fix a bunch of linter warnings from GoLand (#3550) 2023-11-03 17:22:02 +01:00
Derek Parker
5f01e72bb8
cmd/dlv: handle ctrl-c during tracing (#3477)
Ensure we send a Halt command to stop the process being traced so that
the deferred Detach can run ensuring proper cleanup upon exit.

Fixes #3228
2023-08-23 07:45:44 +02:00
Alessandro Arzilli
caf6df0eb9
Documentation,cmd/dlv: clean up command line usage help (#3395)
Due to some very old mistakes too many of Delve's flags are declared as
persistent on cobra's root command. For example the headless flag is a
global flag but does not apply to connect, dap or trace; the backend
flag does not apply to replay, core and dap; etc.

Almost all global flags should have been declared as local flags on
individual subcommands. Unfortunately we can not change this without
breaking backwards compatibility, for example:

   dlv --headless debug

would not parse if headless was a flag of debug instead of a global
flag.

Instead we alter usage function and the markdown generation script to
strategically hide the flags that don't apply.

Fixes #2361
2023-08-09 10:37:55 -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
ttoad
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
Alessandro Arzilli
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
nozzy123nozzy
8b9c3a93f5
cmd/commands: Fix to read debug info file from the correct directory when using trace command with -e option. (#3405) 2023-06-06 16:12:11 -07:00
Alessandro Arzilli
84b757ad57
cmd/dlv,service/dap: use randomized name as default output binary (#3366)
Using a fixed path as the default output binary means that executing
Delve twice in the same directory will cause the second invocation to
overwrite the output binary of the first instance of Delve, making the
restart command not work correctly.

Fixes #3345
2023-05-16 09:36:15 -07:00
Oleksandr Redko
1c9792bce4
cmd/dlv: logger is not closed in connect command (#3367) 2023-05-15 10:22:33 -07:00
罗泽轩
801a9109c7
trace: add timestamp to the output (#3358)
Fix #3356
2023-05-08 10:41:47 -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
Oleksandr Redko
372552bf1f
Documentation: fix typo and grammar issues (#3291) 2023-02-28 14:52:52 +01:00
Derek Parker
98f6d0b619
cmd/dlv: fix exit status for trace subcommand (#3263)
We currently return an error when the command exits because a process
exited error is always returned. Detect this like we do in other code
paths to return a 0 exit code instead of nonzero which indicates the
command itself failed and can confuse other tools.
2023-02-02 11:11:31 +01:00
Alessandro Arzilli
4aaa184b31
cmd/dlv: match go test behavior when dlv test gets a list of .go files (#3232)
When 'dlv test' is called with a list of files it should match the
behavior of 'go test' and chdir to the directory where the go files are
(if they are all in the same directory).

Fixes #3230
2023-01-04 10:47:27 -08:00
Alessandro Arzilli
3a91d56823
Documentation: add -test.run to test example (#3212)
Add -test.run to the example of how 'dlv test' can be used.
2022-12-12 09:59:39 -08:00
Morten Linderud
2391601038
cmd/dlv: Include hidden flag -c for coredumpctl support (#3195)
`coredumpctl` attempts to pass the core file to the debugger through the `-c`
flag. However delve does not support such a flag.

This patch makes it a bool flag so we can receive the coredump file from
`coredumpctl`

    $ GOTRACEBACK=crash ./main
    panic:
    goroutine 1 [running]:
    [....]
    zsh: IOT instruction (core dumped)  GOTRACEBACK=crash ./main
    $ coredumpctl list main
    TIME                            PID  UID  GID SIG     COREFILE EXE                             SIZE
    Tue 2022-11-15 23:29:07 CET 2047401 1000 1000 SIGABRT present  /tmp/go-test/main 60.2K
    $ coredumpctl gdb --debugger=dlv -A core main
               PID: 2047401 (main)
            Signal: 6 (ABRT)
         Timestamp: Tue 2022-11-15 23:29:07 CET (1min 27s ago)
      Command Line: ./main
        Executable: /tmp/go-test/main
         Owner UID: 1000 (fox)
      Size on Disk: 60.2K
           Message: Process 2047401 (main) of user 1000 dumped core.

                    Module /tmp/go-test/main without build-id.
                    Stack trace of thread 2047401:
                    #0  0x000000000045fa01 n/a (/tmp/go-test/main + 0x5fa01)
                    #1  0x0000000000446d3e n/a (/tmp/go-test/main + 0x46d3e)
                    #2  0x0000000000445487 n/a (/tmp/go-test/main + 0x45487)
                    #3  0x000000000045fce6 n/a (/tmp/go-test/main + 0x5fce6)
                    #4  0x000000000045fde0 n/a (/tmp/go-test/main + 0x5fde0)
                    #5  0x0000000000432a49 n/a (/tmp/go-test/main + 0x32a49)
                    #6  0x000000000043211a n/a (/tmp/go-test/main + 0x3211a)
                    #7  0x000000000048d405 n/a (/tmp/go-test/main + 0x8d405)
                    #8  0x0000000000434db2 n/a (/tmp/go-test/main + 0x34db2)
                    #9  0x000000000045e0e1 n/a (/tmp/go-test/main + 0x5e0e1)
                    ELF object binary architecture: AMD x86-64

    [dlv core /tmp/go-test/main -c /var/tmp/coredump-JizL2g]
    Type 'help' for list of commands.
    (dlv) list main.main
    Showing /tmp/go-test/main.go:3 (PC: 0x457c26)
         1:	package main
         2:
         3:	func main() {
         4:		panic()
         5:	}
    (dlv)

Signed-off-by: Morten Linderud <morten@linderud.pw>
2022-11-17 09:13:25 +01:00
Derek Parker
be08778975
:* Improve trace subcommand output (#3091)
This patch improves the output of the trace subcommand by
adding better line breaks, adding goroutine info to the
return statement, and removing unnecessary output.
2022-08-04 10:10:54 +02: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
6ef5284505
cmd/dlv,proc: misc improvements to trace subcommand (#3069)
1. return an error when SetUProbe fails, while creating ebpf tracepoints
2. if no tracepoint can be set for 'dlv trace' exit early
3. never leave the traced program running
4. fix typo in description of --ebpf flag

Fixes #3006
2022-07-22 08:57:57 -07:00
polinasok
a5532eb985
dlv dap: pass disable-aslr to backend (#2965)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2022-04-12 14:20:22 -07:00
Derek Parker
5b6f8ec03a
cmd/dlv: require arg for trace subcommand (#2848)
Fixes #2845
2022-01-29 13:18:24 +01:00
Alessandro Arzilli
5b925d4f5d
terminal: add transcript command (#2814)
Adds a transcript command that appends all command output to a file.
This command is equivalent to gdb's 'set logging'.

As part of this refactor the pkg/terminal commands to always write to a
io.Writer instead of using os.Stdout directly (through
fmt.Printf/fmt.Println).

Fixes #2237
2022-01-27 13:18:25 -08:00
polinasok
4c1f8b4b25
commmands: update DAP overview in help (#2850)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2022-01-06 08:57:40 -08: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
6cf7a7149d
cmd/dlv,config: obey logflags config for LoadConfig warnings (#2701)
LoadConfig warnings should obey the logflags configuration and should
also be delayed until after the "listening at" message, which should
always be the first thing output.

Co-authored-by: Suzy Mueller <suzmue@golang.org>
2021-10-13 18:46:20 -07:00
Hyang-Ah Hana Kim
98a0bcf772
cmd/dlv: add --client-addr flag to run dap with a predefined client (#2568)
This adds a new `--client-addr=host:port` flag to `dlv dap`.
If it is supplied, the dap process will dial into the tcp port where
a DAP client is waiting, and work with only the DAP client.
The DAP client is supposed to start the normal DAP message
exchange starting with the 'initialize' request after the dlv dap
process dials in and the connection is set up. 

VS Code Go extension plans to use this mode for

* reliably detecting `dlv dap` readiness. Currently it depends on
watching the log stream. After this PR, it can listen on a network port.
* running `dlv dap` from any terminal (part of RunInTerminal workflow
implementation).
2021-10-13 11:43:47 -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
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
polinasok
7cdf48605b
service/dap: clarify handling of relative program path (#2653)
* service/dap: add test verifying handling of relative program path

* Add exec test, log build dir and document in --help

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-08-23 11:27:49 -07:00
hitzhangjie
4e5bddee9b
cmd/dlv: use simple chan read instead of select-case (#2649) 2021-08-09 10:08:12 -07:00
polinasok
229fcf1559
cmd: refactor building logic into a helper (#2629)
* cmd: refactor building logic into a helper

* Address review comments

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-08-03 09:48:01 -07:00
Derek Parker
10406f96d5
*: Initial eBPF tracing support (#2625) 2021-07-31 17:16:26 +02:00
Hyang-Ah Hana Kim
26e7f67cc4
cmd/dlv: dlv version --verbose (#2615)
* cmd/dlv: dlv version --verbose

That prints out runtime/debug.BuildInfo read from the dlv binary.
Users can retrieve the same info using `go version -m <path_to_dlv>`
but I think it is convenient to have.

If dlv was built from cloned delve repo:

```
$ ./dlv version -v
Delve Debugger
Version: 1.7.0
Build: $Id: e353a65161e6ed74952b96bbb62ebfc56090832b $
Build Details: go1.16.5
 mod    github.com/go-delve/delve       (devel)
 dep    github.com/cosiner/argv v0.1.0  h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
...
```

If dlv was built with `go install github.com/go-delve/delve@latest`
with go1.16+, or
`GO111MODULE=on go get github.com/go-delve/delve@latest`
from a clean main module:

```
$ ./dlv version -v
Delve Debugger
Version: 1.7.0
Build: $Id: e353a65161e6ed74952b96bbb62ebfc56090832b $
Build Details: go1.16.5
 mod    github.com/go-delve/delve       v1.7.0
 dep    github.com/cosiner/argv v0.1.0  h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
...
```

* remove an accidentally added bogus test
2021-07-27 09:38:48 -07:00
polinasok
c5e533b131
Treat SIGTERM as a server disconnect signal (#2580)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-21 07:43:06 -07:00
Luis Gabriel Gomez
69615b3604
service/dap: Support for replay and core modes (#2367)
This PR aims to add support for rr replay and core actions from the DAP layer. This basically encloses the following:
New launch modes: replay and core

The following modes are added:

    replay: Replays an rr trace, allowing backwards flows (reverse continue and stepback). Requires a traceDirPath property on launch.json pointing to a valid rr trace directory.
    Equivalent to dlv replay <tracedir> command.
    core: Replays a core dump file, showing its callstack and the file matching the callsite. Requires a coreFilePath property on launch.json pointing to a valid coredump file.
    Equivalent to dlv core <exe> <corefile> command.

Dependencies

To achieve this the following additional changes were made:

    Implement the onStepBackRequest and onReverseContinueRequest methods on service/dap
    Adapt onLaunchRequest with the requried validations and logic for these new modes
    Use CapabilitiesEvent responses to enable the StepBack controls on the supported scenarios (see dicussion here)
    Add the corresponding launch.json support on vs code: 

Support for replay and core modes golang/vscode-go#1268
2021-07-21 07:38:04 -07:00
polinasok
af378d396f
service/dap: add backend launch/attach attribute (#2567)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-18 11:37:41 +02:00
polinasok
5459034a98
cmd/dap: server - always headless, target - always foregrounded (#2589)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-07-16 09:49:16 -07:00
polinasok
4fd6c483e1
dap: update dlv dap --help (#2558)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-06-29 15:15:47 +02:00
Hyang-Ah Hana Kim
669fc2d8d3
dap: add sameuser check (#2494)
On linux, delve RPC server allows only connections from the same user
if --only-same-user is set (true, by default). Do the same for DAP
server.

Moved the sameuser check logic to service/internal/sameuser.
Considered importing service/rpccommon from the dap server,
but when we eventually migrate to multiplex rpc and dap from one
port, I am afraid that can cause cyclic imports.
2021-05-19 10:29:05 -07:00
Alessandro Arzilli
0da1c9a9d7
Documentation: document passing arguments to the test program (#2459)
Add documentation on how to pass arguments to the program generated by
`dlv test`.

Fixes #2458
2021-05-04 12:37:09 -07:00
Suzy Mueller
1c9a10529e
service/dap: use specified working directory for launch requests (#2360)
* service/dap: use specified working directory for launch requests

If a user specifies a working directory in the launch request,
then the process should use that working directory. This may
affect how the program runs and the user should be able to have
control over this.

* service/dap: add tests for launch with working dir

Added tests to make sure the working directory is set correctly.

* service/dap: fix TestWorkingDir on windows

* service/dap: use %q to print quoted string

* cmd/dlv: update dap warning about working dir

* service/dap: change the launch argument to be wd`

* update warning to specify only launch request
2021-03-22 20:06:09 -07: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
polinasok
1b2357092c
cmd: update dlv dap --help (#2299)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
2021-01-13 13:10:15 +01:00
Alex Zamai
433eafb280
*: Expand --build-flags= description in the document (#2273)
add example for multiple  --build-flags

add example description to --build-flags
2021-01-05 10:57:30 -08:00
Alessandro Arzilli
9a3c9ebad1
proc/*: add launch option to disable ASLR (#2202)
Fixes #1847
2020-10-21 12:50:52 -07:00
aarzilli
7555d1c063 cmd,proc,terminal,debugger: Support default file descriptor redirects
Adds features to support default file descriptor redirects for the
target process:

1. A new command line flag '--redirect' and '-r' are added to specify
   file redirects for the target process
2. New syntax is added to the 'restart' command to specify file
   redirects.
3. Interactive instances will check if stdin/stdout and stderr are
   terminals and print a helpful error message if they aren't.
2020-09-01 21:50:27 +02:00