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

Support for debugging go with gdb #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ezaquarii
Copy link

This PR introduces configuration to debug
Go applications with GDB, since Delve is not
supported on OpenBSD.

#94

At this moment, this PR has been tested on Fedora 40 with GDB 15.2.

For reasons unknown, the debugger fails to hit the breakpoint unless
:stopAtBeginningOfMainSubprogram is set to t.

It used to work with older version of dape, so could it be some sort of regression perhaps?

Debugging test using go-gdb-test target doesn't work because it can't stop at beginning of main.

go-gdb target works.

@svaante I'll probably need some assistance as I'm not familiar enough with DAP to land this.

This PR introduces configuration to debug
Go applications with GDB, since Delve is not
supported on OpenBSD.
@svaante
Copy link
Owner

svaante commented Jan 5, 2025

Hey and thank you for your contribution!

For reasons unknown, the debugger fails to hit the breakpoint unless
:stopAtBeginningOfMainSubprogram is set to t.

This is due to an GDB bug which dape has an workaround for but it has been fixed upstream in gdb so depending on the gdb defer-launch-attach needs to be set.
From dape-configs docs:

- defer-launch-attach: If launch/attach request should be sent
  after initialize or configurationDone.  If nil launch/attach are
  sent after initialize request else it's sent after
  configurationDone.  This key exist to accommodate the two different
  interpretations of the DAP specification.
  See: GDB bug 32090.

How is your FSF status? This amount of code needs to be FSF assigned to be merged.

Copy link
Owner

@svaante svaante left a comment

Choose a reason for hiding this comment

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

Good start, just a couple of small things!

@@ -219,6 +220,26 @@
:type "debug"
:cwd "."
:program ".")
(go-gdb-test
modes (go-mode go-ts-mode)
Copy link
Owner

Choose a reason for hiding this comment

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

Missing ensure symbol. This should be grouped with the other gdb configuration and ensure implemented once (see js-debug configuration)

modes (go-mode go-ts-mode)
command "gdb"
command-args ("--interpreter=dap")
command-cwd (lambda () (file-name-directory (buffer-file-name)))
Copy link
Owner

Choose a reason for hiding this comment

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

Dape supports short cutting these functions as just (file-name-directory (buffer-file-name))

command "gdb"
command-args ("--interpreter=dap")
command-cwd (lambda () (file-name-directory (buffer-file-name)))
compile (lambda () (format "go test -c -o %s -gcflags '-N -l'" (dape--go-test-binary-name))) ;; compile without optimizations
Copy link
Owner

Choose a reason for hiding this comment

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

See comment above

Copy link
Author

Choose a reason for hiding this comment

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

This doesn't work for me:

compilation-start: Wrong type argument: stringp, (format "go build -o %s -gcflags '-N -l'" (dape--go-binary-name))
Error running timer: (wrong-type-argument stringp nil)

Same for command-cwd. I can pass a function name only or string.

command-cwd (lambda () (file-name-directory (buffer-file-name)))
compile (lambda () (format "go test -c -o %s -gcflags '-N -l'" (dape--go-test-binary-name))) ;; compile without optimizations
:request "launch"
:program dape--go-test-binary-name
Copy link
Owner

Choose a reason for hiding this comment

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

I am not a big fan of language specific functions, this could be defined inline

@@ -822,6 +843,22 @@ Non interactive global minor mode."

;;; Utils

(defun dape--go-test-name ()
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe I am missing something but where is this used? (also as stated above I don't want to define language specific functions)

Copy link
Author

Choose a reason for hiding this comment

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

Oh, it's not used atm.

This is a leftover from my prototype to debug test under cursor. However, the logic to construct the test runner invocation is somewhat convoluted and breaking it into pieces would help.

I'll remove it for now.

@ezaquarii
Copy link
Author

defer-launch-attach needs to be set.

I missed that. I'll check that out and report back.

How is your FSF status?

I sent a message to assign@ today. You should be in CC just FYI.

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.

2 participants