Can't get debugging to work for a native project on mac os with vscode

Hi,

I tried the following:

  • in Home: import example project: “hello-world” from the native platform
  • set a break point in src/main.c and press F5

Nothing happens; code execution does not stop at the breakpoint. I tried adding build_type=debug and build_flags = -g and debug_build_flags = -g to the platformio.ini file, but none made a difference.

I noticed however that when I do the following:

  • delete the json files in the folder “.vscode”
  • press F5
  • Select the configuration: “C/C++: gcc build …” from the popup menu

Now only the “.vscode/tasks.json” file is recreated and the debugger works; I can step through the code. However, when I close and reopen the project the other json files are recreated too and debugging stops working again.

Is this a bug or am I missing something?

I’m running: macOS 10.15.7, vscode 1.73.1, pio core 6.1.5 and Home 3.4.3. I don’t have gcc and gdb installed.

Kind regards, Marcel

Delete the .vscode folder again and use Command+Shift+P → Rebuild Intellisense. The .vscode folder should be recreated. Now change click on the debugging symbol in the left sidebar. The debug configuration should be starting with “PIO Debug…”. Press the play button on that. Does it invoke PlatformIO?

Hi Max,

Thanks for your response. Yes, PlatformIO is invoked (see below), but debugging still does not work; code execution doesn’t stop at the breakpoint.

 *  Executing task: platformio debug 

Processing native (platform: native)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 2 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
=============================================================================== [SUCCESS] Took 0.51 seconds ===============================================================================
 *  Terminal will be reused by tasks, press any key to close it. 

What’s the output in the “Debug Console” tab?

Here it is. There’s an error:

Processing native (platform: native)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 2 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
========================= [SUCCESS] Took 0.52 seconds =========================
undefinedError: Traceback (most recent call last):
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/platformio/__main__.py", line 102, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/platformio/cli.py", line 71, in invoke
    return super().invoke(ctx)
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/platformio/debug/cli.py", line 84, in cli
    return _debug_in_project_dir(
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/platformio/debug/cli.py", line 193, in _debug_in_project_dir
    loop.run_until_complete(coro)
  File "/Users/marcello/.platformio/python3/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/platformio/debug/process/gdb.py", line 58, in run
    await self.spawn(*args, cwd=self.project_dir, wait_until_exit=True)
  File "/Users/marcello/.platformio/penv/lib/python3.9/site-packages/platformio/debug/process/base.py", line 77, in spawn
    await loop.subprocess_exec(
  File "/Users/marcello/.platformio/python3/lib/python3.9/asyncio/base_events.py", line 1661, in subprocess_exec
    transport = await self._make_subprocess_transport(
  File "/Users/marcello/.platformio/python3/lib/python3.9/asyncio/unix_events.py", line 197, in _make_subprocess_transport
    transp = _UnixSubprocessTransport(self, protocol, args, shell,
  File "/Users/marcello/.platformio/python3/lib/python3.9/asyncio/base_subprocess.py", line 36, in __init__
    self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
  File "/Users/marcello/.platformio/python3/lib/python3.9/asyncio/unix_events.py", line 789, in _start
    self._proc = subprocess.Popen(
  File "/Users/marcello/.platformio/python3/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/marcello/.platformio/python3/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'gdb'

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq/index.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

I see. Open a PlatformIO CLI and execute

gdb --version

Does it output something?

zsh: command not found: gdb

PlatformIO does expect gdb to be installed on the machine for debugging native programs. It will not accept lldb (Debugging using macOS lldb instead of gdb).

You could try and install gdb via homebrew.

I tried to get gdb going the whole afternoon. It’s a pain to install because you have to create a certificate and sign the gdb app. After I finally got that, the debugger started but I didn’t see any values, they were “<optimized out>” and I gave up. I had hoped it would be easier to use macOS’s debugger. That did work initially (without the .vscode folder)! Is there no setting somewhere where I can exchange gdb for lldb? I saw that mirosoft’s C/C++ extension uses a “$gcc” “problemMatcher” to communicate (I assume!) with lldb.??

I am not aware of such a thing, it seems to be hardcoded in the core. Nobody created a new issue for this like I wanted to in the original post (only workarounds posted in Issues · platformio/platformio-core · GitHub that do not involve PlatformIO debugging it), can you post one?

It’s done: link.

1 Like