debug project with custom structure #63

Closed
opened 2023-12-12 10:43:18 +03:00 by amirphl · 4 comments
amirphl commented 2023-12-12 10:43:18 +03:00 (Migrated from github.com)

I have a project with such a structure:
project/
|-- cmd/
| |-- main.go
|-- service/
| |-- company/
| |-- service.go
|-- repo/

I normally run the project using this command:
go run ./cmd serve
Here. serve is just an argument.

Problematic Scenarios
When placing a breakpoint in a function in service.go, the debugging process fails because the build command is incorrect:
go build -o <path-to-executable> -gcflags all=-N -l <path-to>/service/company/service.go
This command is invalid as it attempts to compile a file that does not contain the main function.

Conversely, when navigating to main.go and attempting to debug, the generated build command is also incorrect:
go build -o <path-to-executable> -gcflags all=-N -l <path-to>/cmd/main.go
It should instead execute:
go build -o <path-to-executable> -gcflags all=-N -l <path-to>/cmd serve

I appreciate any help to fix the problem.

I have a project with such a structure: project/ |-- cmd/ | |-- main.go |-- service/ | |-- company/ | |-- service.go |-- repo/ I normally run the project using this command: go run ./cmd serve Here. `serve` is just an argument. Problematic Scenarios When placing a breakpoint in a function in `service.go`, the debugging process fails because the build command is incorrect: `go build -o <path-to-executable> -gcflags all=-N -l <path-to>/service/company/service.go` This command is invalid as it attempts to compile a file that does not contain the main function. Conversely, when navigating to `main.go` and attempting to debug, the generated build command is also incorrect: `go build -o <path-to-executable> -gcflags all=-N -l <path-to>/cmd/main.go` It should instead execute: `go build -o <path-to-executable> -gcflags all=-N -l <path-to>/cmd serve` I appreciate any help to fix the problem.
amirphl commented 2023-12-12 13:16:47 +03:00 (Migrated from github.com)

Current Solution
I have successfully resolved my debugging issue by temporarily injecting the serve keyword into os.Args. Subsequently, I run "Debug Package" from the main.go file, which works as a temporary workaround.

Desired Enhancement
I am seeking a more flexible solution that allows me to run "Debug Package" from any source file, not just restricted to main.go. For instance, I am unable to initiate "Debug Package" from my service.go.

Current Solution I have successfully resolved my debugging issue by temporarily injecting the serve keyword into os.Args. Subsequently, I run "Debug Package" from the main.go file, which works as a temporary workaround. Desired Enhancement I am seeking a more flexible solution that allows me to run "Debug Package" from any source file, not just restricted to main.go. For instance, I am unable to initiate "Debug Package" from my service.go.
stale[bot] commented 2024-06-10 01:02:08 +03:00 (Migrated from github.com)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
leoluz commented 2024-07-04 23:06:38 +03:00 (Migrated from github.com)

@amirphl please check if delve.build_flags configuration addresses your use-case.
If it doesn't, I currently don't have the time to implement it but feel free to push a PR in the repo.

@amirphl please check if `delve.build_flags` configuration addresses your use-case. If it doesn't, I currently don't have the time to implement it but feel free to push a PR in the repo.
stale[bot] commented 2025-01-01 04:14:54 +03:00 (Migrated from github.com)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
NeonXP/nvim-dap-go#63
No description provided.