microsoft / microsoft/vscode-cpptools

"Unable to start debugging. Failed to find thread 1 for break event" when debugging Zephyr app

Open
#10,195 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

debugger
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment
  • OS and version: Windows 11 build 22621, WSL2 Ubuntu 22.04.1 LTS
  • VS Code: 1.73.1
  • C/C++ extension: 1.12.4
  • OS and version of remote machine (if applicable): nRF5340 dev kit, Zephyr RTOS version 3.0
  • GDB / LLDB version: GNU gdb (Zephyr SDK 0.15.1) 12.1

The USB JLink debugger from the nRF5340 DK is passed through to WSL as described in https://learn.microsoft.com/en-us/windows/wsl/connect-usb

Bug Summary and Steps to Reproduce

Bug Summary:
I am trying to debug a Zephyr application on an nRF5340 DK using its built-in JLink. When the application is built with CONFIG_DEBUG_THREAD_INFO=y, the debug session fails immediately with

ERROR: Unable to start debugging. Failed to find thread 1 for break event

When I debug from the command line, it works properly. It appears that thread 1 is only used for system initialization in Zephyr, and it exits shortly after the program starts, which may be the source of the error.

Steps to reproduce:

  1. Build a Zephyr application with -b nrf5340dk_nrf5340_cpuapp. (I am using https://zmk.dev/ which doesn't have support for the nRF5340 DK in mainline code yet, but I expect this could be reproduced with one of the Zephyr sample apps, like https://docs.zephyrproject.org/latest/samples/basic/blinky/README.html)
  2. Add to prj.conf
    CONFIG_DEBUG=y
    CONFIG_DEBUG_INFO=y
    CONFIG_DEBUG_THREAD_INFO=y
    
  3. Run west debugserver to start the GDB server.
  4. Start the vscode debugger.
Debugger Configurations
// Launch configuration
      {
        "name": "GDB,
        "type": "cppdbg",
        "request": "launch",
        "cwd": "${workspaceFolder:zmk}/app",
        "program": "${workspaceFolder:zmk}/app/build/zmk_uno/zephyr/zmk.elf",
        "miDebuggerPath": "/home/joel/.local/zephyr-sdk-0.15.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb",
        "miDebuggerServerAddress": "localhost:2331",
        "preLaunchTask": "gdbserver",
        "launchCompleteCommand": "exec-continue",
        "logging": {
          "trace": true,
          "traceResponse": true,
          "engineLogging": true
        }
      },

// Tasks
{
        "label": "gdbserver",
        "type": "shell",
        "options": {
          "cwd": "${workspaceFolder:zmk}/app"
        },
        "command": "west debugserver -d build/zmk_uno",
        "isBackground": true,
        "problemMatcher": {
          "owner": "jlink",
          "fileLocation": "autoDetect",
          "pattern":[
            {
              "regexp": "$^",
              "file": 1,
              "location": 2,
              "message": 3
            }
          ],
          "background": {
            "activeOnStart": true,
            "beginsPattern": "west debugserver: rebuilding",
            "endsPattern": "J-Link GDB server running"
          }
        }
      }
Debugger Logs
See error.log in additional information.
Other Extensions

No response

Additional Information

The debug console log is too large to paste directly, so I've attached it here:
error.log

When debugging from the command line, where GDB works properly, I get the following output:
debug.log

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the attached error.log and debug.log, then reproduce with a Zephyr sample built for nrf5340dk_nrf5340_cpuapp and CONFIG_DEBUG_THREAD_INFO=y. Check the VS Code debugger launch configuration and the C/C++ extension's GDB thread and break-event handling. Done means the VS Code session starts successfully without the missing-thread error, matching command-line GDB behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.