docs: Fix vscode debugging section in HACKING.md

Let's account for the recent changes in mkosi in the debugging
with vscode section.
This commit is contained in:
Daan De Meyer 2023-03-21 16:06:15 +01:00 committed by Luca Boccassi
parent c5ba7a2a4d
commit c84d14c525

View file

@ -215,24 +215,25 @@ vscode documentation [here](https://code.visualstudio.com/docs/cpp/launch-json-r
## Debugging systemd with mkosi + vscode
To simplify debugging systemd when testing changes using mkosi, we're going to show how to attach
[VSCode](https://code.visualstudio.com/)'s debugger to an instance of systemd running in a mkosi image
(either using QEMU or systemd-nspawn).
[VSCode](https://code.visualstudio.com/)'s debugger to an instance of systemd running in a mkosi image using
QEMU.
To allow VSCode's debugger to attach to systemd running in a mkosi image, we have to make sure it can access
the container/virtual machine spawned by mkosi where systemd is running. mkosi makes this possible via a
handy SSH option that makes the generated image accessible via SSH when booted. Thus you must build
the image with `mkosi --ssh`. The easiest way to set the
option is to create a file 20-local.conf in mkosi.default.d/ (in the directory you ran mkosi in) and add
the following contents:
the virtual machine spawned by mkosi where systemd is running. mkosi makes this possible via a handy SSH
option that makes the generated image accessible via SSH when booted. Thus you must build the image with
`mkosi --ssh`. The easiest way to set the option is to create a file 20-local.conf in mkosi.conf.d/ (in the
directory you ran mkosi in) and add the following contents:
```
[Host]
Ssh=yes
```
Next, make sure systemd-networkd is running on the host system so that it can configure the network interface
connecting the host system to the container/VM spawned by mkosi. Once systemd-networkd is running, you should
be able to connect to a running mkosi image by executing `mkosi ssh` in the systemd repo directory.
Also make sure that the SSH agent is running on your system and that you've added your SSH key to it with
`ssh-add`.
After rebuilding the image and booting it with `mkosi qemu`, you should now be able to connect to it by
running `mkosi ssh` from the same directory in another terminal window.
Now we need to configure VSCode. First, make sure the C/C++ extension is installed. If you're already using
a different extension for code completion and other IDE features for C in VSCode, make sure to disable the
@ -270,11 +271,11 @@ the directory, and add the following contents:
},
"MIMode": "gdb",
"sourceFileMap": {
"/root/build/../src": {
"/work/build/../src": {
"editorPath": "${workspaceFolder}",
"useForBreakpoints": false
},
"/root/build/*": {
"/work/build/*": {
"editorPath": "${workspaceFolder}/mkosi.builddir",
"useForBreakpoints": false
}