VSCode Debug FreeRTOS-Plus MPS2 TCP demo on QEMU

I’m trying to debug the FreeRTOS_Plus_TCP_Echo_Qemu_MPS2 demo.
I compile it with the DEBUG=1 option that enables all debug related CFLAGS.
My host is a Kubuntu 22.04.
My IDE is VSCode.
I am using a Qemu, version 8.2.0 stable release, to run the demo.
(-machine mps2-an385 -cpu cortex-m3 -m 16M)

My issue is the following:

  1. I use a launch.json in VSCode to start debugging the freertos_tcp_mps2_demo.axf firmware binary
  2. A prelaunch task launches Qemu with root privileges (else it cannot modify /dev/tun/tuntap on my host Linux machine to create a bridge interface)
  3. That Qemu instance opens a GDB server (-s -S) and waits for VSCode to attach
  4. VSCode attaches a GDB instance for ARM to Qemu
  5. At this point the code should execute until it hits a breakpoint I’ve defined in the firmware’s code. However, Qemu just keeps executing it.

Any ideas on what could be wrong?

This is the launch.json

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Terminate All Tasks",
        "command": "echo ${input:terminate}",
        "type": "shell",
        "problemMatcher": []
      },
      {
        "label": "Run_QEMU",
        "command": "sudo /home/xgandiaga/Desktop/qemu-8.2.0/build/qemu-system-arm -machine mps2-an385 -cpu cortex-m3 -m 16M -kernel /home/xgandiaga/Desktop/FreeRTOS/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/build/freertos_tcp_mps2_demo.axf -nic tap,id=mynet0,mac=52:54:00:12:34:AD,ifname=virbr0-nic,script=no -nographic -serial stdio -monitor null -semihosting-config enable=on,target=native -s -S",
        "type": "shell",
        "problemMatcher": []
      }
    ],
    "inputs": [
      {
        "id": "terminate",
        "type": "command",
        "command": "workbench.action.tasks.terminate",
        "args": "terminateAll"
      }
    ]
  }

This is the tasks.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug MPS2 FreeRTOS on QEMU",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/xgandiaga/Desktop/FreeRTOS/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2/build/freertos_tcp_mps2_demo.axf",
            "cwd": "/home/xgandiaga/Desktop/FreeRTOS",
            "MIMode": "gdb",
            "setupCommands": [
               {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/gdb-multiarch",
            "miDebuggerServerAddress": "localhost:1234",
            "stopAtEntry": true,
            "preLaunchTask": "Run_QEMU",
            "postDebugTask": "Terminate All Tasks",
        }       
    ]
}

Fixed it.

Just launch qemu by itself instead of using the tasks.
I don’t know why, but that works.

I’ll leave the post open just in case anybody finds how to make it work through tasks.json

Thanks for sharing your solution!