Skip to content

Commit

Permalink
modification for testing go-delve/delve#3781
Browse files Browse the repository at this point in the history
  • Loading branch information
hyangah committed Sep 6, 2024
1 parent 3b1f6ff commit 9bd5daf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"debugAdapter": "dlv-dap",
"port": 40000,
"host": "127.0.0.1",
"showLog": true,
"logOutput": "dap",

"ClientMod2Dir": {
// Add the info from `substitute-path-guess-helper` output. Example:
"main": "/usr/local/google/home/hakim/projects/go-docker-alpine-remote-debug",
"github.com/ccampo133/go-docker-alpine-remote-debug":"/usr/local/google/home/hakim/projects/go-docker-alpine-remote-debug"
}

/* manual config :-(
"substitutePath": [
{
"from": "${workspaceFolder}",
"to": "/app",
}],
*/
}
]
}
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ WORKDIR /app
# Turning off Cgo is required to install Delve on Alpine.
ENV CGO_ENABLED=0

# Download and install the Delve debugger.
RUN go install github.com/go-delve/delve/cmd/dlv@latest
# Build and install patched delve (checked out in the delve directory)
COPY delve /tmp/delve
RUN go install -C /tmp/delve ./cmd/dlv

COPY go.mod .
COPY go.sum .
Expand All @@ -17,7 +18,8 @@ RUN go mod download
COPY main.go .

# Disable inlining and optimizations that can interfere with debugging.
RUN go build -gcflags "all=-N -l" -o /main main.go
#RUN go build -gcflags "all=-N -l" -o /main main.go
RUN go build -gcflags "all=-N -l" -o /main .

FROM alpine:3.17

Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
This is forked from github.com/ccampo133/go-docker-alpine-remote-debug for
testing delve DAP testing. It assumes there is a checked out copy of delve
under the `delve` directory. Let's assume you checked out this repo in
$WORKDIR.

```
git clone https://github.com/hyangah/go-docker-alpine-remote-debug $WORKDIR
cd $WORKDIR
git clone https://github.com/go-delve/delve
cd delve
git fetch upstream pull/3781/head
go build ./cmd/dlv
```

From the $WORKDIR, running the `dlv substitue-path-guess-helper` gave me:

```
./delve/dlv substitute-path-guess-helper
{"ModuleDirectories":{"github.com/ccampo133/go-docker-alpine-remote-debug":"/usr/local/google/home/hakim/projects/go-docker-alpine-remote-debug"}}
```

Update `ClientMod2Dir` attribute in `$WORKDIR/.vscode/launch.json`.

Read the "Dockerfile" to see how the container is built.

Then, follow the remaining instruction below.


# go-docker-alpine-remote-debug

A simple example on how to enable remote debugging using [Delve](https://github.com/go-delve/delve)
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cmd="/bin/app"
if [ "$REMOTE_DEBUG_PORT" ]; then
echo "Starting application with remote debugging on port $REMOTE_DEBUG_PORT"
dlvFlags="--listen=:$REMOTE_DEBUG_PORT --headless=true --log --api-version=2 --accept-multiclient"
dlvFlags="--listen=:$REMOTE_DEBUG_PORT --headless=true --log --api-version=2 --accept-multiclient --log-output=dap,debugger"
execFlags=""
# Simply setting this environment variable is enough to force the debugger to
# pause on start --- we don't care about the value.
Expand Down

0 comments on commit 9bd5daf

Please sign in to comment.