|
| 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/) |
0 commit comments