Skip to content

Commit 065109c

Browse files
committed
docs: add docs related to dap
Adds some entry-level and developer-friendly docs for the debug adapter. The one in `docs/dap.md` is meant for someone trying to use the debugger while the one in `docs/reference/buildx_dap_build.md` is more focused on documenting the command to be integrated in a debugger extension. Signed-off-by: Jonathan A. Sternberg <[email protected]>
1 parent e3eb64e commit 065109c

File tree

3 files changed

+140
-4
lines changed

3 files changed

+140
-4
lines changed

commands/dap.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func dapCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
2323

2424
dapBuildCmd := buildCmd(dockerCli, rootOpts, &options)
2525
dapBuildCmd.Args = cobra.RangeArgs(0, 1)
26+
27+
// Remove aliases and annotations for documentation.
28+
dapBuildCmd.Aliases = nil
29+
dapBuildCmd.Annotations = nil
2630
cmd.AddCommand(dapBuildCmd)
2731
return cmd
2832
}

docs/dap.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Debug Adapter Protocol
2+
3+
## What is the debug adapter protocol?
4+
5+
The debug adapter protocol [DAP](https://microsoft.github.io/debug-adapter-protocol/overview) is a protocol created by Microsoft to standardize an abstract protocol for how a development tool (such as VS Code) communicates with concrete debuggers.
6+
7+
Many [popular editors](https://microsoft.github.io/debug-adapter-protocol/implementors/tools/) now support DAP as the primary method of launching debuggers. This includes **VS Code** and **Neovim**. There are also other editors, such as **Jetbrains IDEs** where DAP is not the primary method of launching debuggers, but is available with plugins.
8+
9+
## Features
10+
11+
- Pause on exception.
12+
- Set breakpoints on instructions.
13+
- Step next and continue.
14+
15+
## Limitations
16+
17+
- **Step In** is the same as **Next**.
18+
- **Step Out** is the same as **Continue**.
19+
- **FROM** directives may have unintuitive breakpoint lines.
20+
- Stack traces may not show the full sequence of events.
21+
- Invalid `args` in launch request may not produce an error in the UI.
22+
- Does not support arbitrary pausing.
23+
- Output is always the plain text printer.
24+
25+
## Future Improvements
26+
27+
- Support for Bake.
28+
- Exec into a container.
29+
- Backwards stepping.
30+
- Better UI for errors with invalid arguments.
31+
32+
## We would like feedback on
33+
34+
- Stack traces.
35+
- Step/pause locations.
36+
- Variable inspections.
37+
- Additional information that would be helpful while debugging.
38+
39+
### Stack Traces
40+
41+
We would like feedback on whether the stack traces are easy to read and useful for debugging.
42+
43+
The goal was to include the parent commands inside of a stack trace to make it easier to understand the previous commands used to reach the current step. Stack traces in normal programming languages will only have one parent (the calling function).
44+
45+
In a Dockerfile, there are no functions which makes displaying a call stack not useful. Instead, we decided to show the input to the step as the "calling function" to make it easier to see the preceding steps.
46+
47+
This method of showing a stack trace is not always clear. When a step has multiple parents, such as a `COPY --from` or a `RUN` with a bind mount, there are multiple parents. Only one can be the official "parent" in the stack trace. At the moment, we do not try to choose one and will break the stack trace into two separate call stacks. This is also the case when one step is used as the parent for multiple steps.
48+
49+
### Step/pause Locations
50+
51+
Execution is paused **after** the step has been executed rather than before.
52+
53+
For example:
54+
55+
```dockerfile
56+
FROM busybox
57+
RUN echo hello > /hello
58+
```
59+
60+
If you set a breakpoint on line 2, then execution will pause **after** the `RUN` has executed rather than before.
61+
62+
We thought this method would be more useful because we figured it was more common to want to inspect the state after a step rather than before the step.
63+
64+
There are also Dockerfiles where some instructions are aliases for another instruction and don't have their own representation in the Dockerfile.
65+
66+
```dockerfile
67+
FROM golang:1.24 AS golang-base
68+
69+
# Does not show up as a breakpoint since it refers to the instruction
70+
# from earlier.
71+
FROM golang-base
72+
RUN go build ...
73+
```
74+
75+
### Step into/out
76+
77+
It is required to implement these for a debug adapter but we haven't determined a way that these map to Dockerfile execution. Feedback about how you would expect these to work would be helpful for future development.
78+
79+
For now, step into is implemented the same as next while step out is implemented the same as continue. The logic here is that next step is always going into the next call and stepping out would be returning from the current function which is the same as building the final step.
80+
81+
### Variable Inspections
82+
83+
We plan to include more variable inspections but we would like feedback on the current ones. At the moment, only the `RUN` step has additional arguments shown.
84+
85+
For other steps, would it be useful to see the arguments for other operations like the copy source or destination?
86+
87+
If an argument is using the default value or is empty, would it still be helpful to show?
88+
89+
Are there any additional things that would be useful to be able to see in the inspection window?
90+
91+
## Official Implementations
92+
93+
The following are officially supported plugins for invoking the debug adapter.
94+
Please refer to the documentation in each of these repositories for installation instructions.
95+
96+
- [Visual Studio Code](https://github.com/docker/vscode-extension/)
97+
- [Neovim](https://github.com/docker/nvim-dap-docker/)

docs/reference/buildx_dap_build.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
<!---MARKER_GEN_START-->
44
Start a build
55

6-
### Aliases
7-
8-
`docker build`, `docker builder build`, `docker image build`, `docker buildx b`
9-
106
### Options
117

128
| Name | Type | Default | Description |
@@ -50,3 +46,42 @@ Start a build
5046

5147
<!---MARKER_GEN_END-->
5248

49+
## Description
50+
51+
Start a debug session using the [debug adapter protocol](https://microsoft.github.io/debug-adapter-protocol/overview) to communicate with the debugger UI.
52+
53+
Arguments are the same as the `build`
54+
55+
> [!NOTE]
56+
> `buildx dap build` command may receive backwards incompatible features in the future
57+
> if needed. We are looking for feedback on improving the command and extending
58+
> the functionality further.
59+
60+
## Examples
61+
62+
### <a name="launch-config"></a> Launch request arguments
63+
64+
The following [launch request arguments](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Launch) are supported. These are sent as a JSON body as part of the launch request.
65+
66+
| Name | Type | Default | Description |
67+
|:--------------------|:--------------|:-------------|:-----------------------------------------------------------------------------|
68+
| `dockerfile` | `string` | `Dockerfile` | Name of the Dockerfile |
69+
| `contextPath` | `string` | `.` | Set the context path for the build (normally the first positional argument) |
70+
| `target` | `string` | | Set the target build stage to build |
71+
| `stopOnEntry` | `boolean` | `false` | Stop on the first instruction |
72+
73+
### <a name="additional-args"></a>
74+
75+
Command line arguments may be passed to the debug adapter the same way they would be passed to the normal build command and they will set the value.
76+
Launch request arguments that are set will override command line arguments if they are present.
77+
78+
A debug extension should include an `args` entry in the launch configuration and should append these arguments to the end of the tool invocation.
79+
For example, a launch configuration in Visual Studio Code with the following:
80+
81+
```json
82+
{
83+
"args": ["--build-arg", "FOO=AAA"]
84+
}
85+
```
86+
87+
This should cause the debug adapter to be invoked as `docker buildx dap build --build-arg FOO=AAA`.

0 commit comments

Comments
 (0)