Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmds/command: Include hidden flag -c for coredumpctl support #3195

Merged
merged 1 commit into from
Nov 17, 2022

Conversation

Foxboron
Copy link
Contributor

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

@Foxboron
Copy link
Contributor Author

The reason why this is neat is because we could run Go binaries from distributions in services with GOTRACEBACK=crash and leverage debuginfod to fetch symbols from crashing systems. It would probably be a good idea to document this as well, but testing the waters with an implicit flag first :)

Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestGeneratedDoc in dlv_test.go fails because the documentation hasn't been regenerated. To actually make the flag hidden you have to call coreCommand.Flags().MarkHidden("core"), I think.

cmd/dlv/cmds/commands.go Show resolved Hide resolved
@derekparker
Copy link
Member

It should also be noted that Delve supports debuginfod already: https://github.com/go-delve/delve/blob/master/pkg/proc/debuginfod/debuginfod.go.

@Foxboron
Copy link
Contributor Author

@derekparker Yes, I implemented some of that and see coredumpctl as a natural extension to this :)

This feature set should maybe be documented a bit better because it's quite neat.

A quick recording of be crashing the Arch packaged delve and using this patch to debug the stack trace with stuff fetched from debuginfod.

https://paste.xinu.at/wp7pZBzekQQERwvN2/

`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)
                    go-delve#1  0x0000000000446d3e n/a (/tmp/go-test/main + 0x46d3e)
                    go-delve#2  0x0000000000445487 n/a (/tmp/go-test/main + 0x45487)
                    go-delve#3  0x000000000045fce6 n/a (/tmp/go-test/main + 0x5fce6)
                    go-delve#4  0x000000000045fde0 n/a (/tmp/go-test/main + 0x5fde0)
                    go-delve#5  0x0000000000432a49 n/a (/tmp/go-test/main + 0x32a49)
                    go-delve#6  0x000000000043211a n/a (/tmp/go-test/main + 0x3211a)
                    go-delve#7  0x000000000048d405 n/a (/tmp/go-test/main + 0x8d405)
                    go-delve#8  0x0000000000434db2 n/a (/tmp/go-test/main + 0x34db2)
                    go-delve#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>
@Foxboron Foxboron force-pushed the morten/coredumpctl-support branch from 6e1d5f6 to a75a8b5 Compare November 16, 2022 22:25
Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aarzilli aarzilli merged commit 2391601 into go-delve:master Nov 17, 2022
@aarzilli
Copy link
Member

This feature set should maybe be documented a bit better because it's quite neat.

I'm not sure where the right place for this would be. Could be inside Gettting started but it would probably have to be in the context of a broader discussion on generating and debugging core files.

derekparker pushed a commit to derekparker/delve that referenced this pull request Nov 22, 2022
`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)
                    go-delve#7  0x000000000048d405 n/a (/tmp/go-test/main + 0x8d405)
                    go-delve#8  0x0000000000434db2 n/a (/tmp/go-test/main + 0x34db2)
                    go-delve#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants