Jezewski's Nest

Debugging C programs with VS Code

I have been exploring my knowledge of the C language for some time. When I tried to use the debugger built into Visual Studio Code, I encountered some configuration problems.

After a tremendous amount of googling I found, more or less, the steps needed to debug C programs in VSC, on Mac Air with M1 CPU.

  1. Install C/C++ extension

  2. Install Apple Xcode console tools:

xcode-select --install

  1. In the case of errors with finding debugger like:

Unable to determine path to debugger.  Please specify the "MIDebuggerPath" option.

or Unable to start debugging. Unable to establish a connection to LLDB. The following message was writter lldb: unrecognized option '--interpreter=mi'error: unknown or ambiguous option

use directly build-in LLDB-MI shipped with VSCode. Example launch.json file:

{

// Use IntelliSense to learn about possible attributes.

// Hover to view descriptions of existing attributes.

// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [

{

"name": "Launch (lldb)",

"type": "cppdbg",

"request": "launch",

"program": "${workspaceFolder}/a.out",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"environment": [],

"externalConsole": false,

"MIMode": "lldb",

"miDebuggerPath": "/Users/your_user_name/.vscode/extensions/ms-vscode.cpptools-1.13.8-darwin-arm64/debugAdapters/lldb-mi/bin/lldb-mi",

}

]

}