Skip to content

Instantly share code, notes, and snippets.

@levihuayuzhang
Last active January 8, 2024 03:35
Show Gist options
  • Save levihuayuzhang/0f078ce482c3cf6bc079e1d3b8a6c6dd to your computer and use it in GitHub Desktop.
Save levihuayuzhang/0f078ce482c3cf6bc079e1d3b8a6c6dd to your computer and use it in GitHub Desktop.
Fix debug C/C++ with lldb-mi in VSCode on MacOS stdin issue

Problem: when debugging the programs with lldb-mi on MacOS with VSCode-cpptools, the buildin terminal of VSCode not used as the stdin&out interface.

Fix:

  1. enable external terminal
  2. use stdin file while debugging and pass the file path using debugger setup command.

Notes:

  1. the "args": ["<", "${fileDirname}/data/${fileBasenameNoExtension}"]will not work (at least for now) on MacOS because it treats the redirect operator as program argument.
  2. the 1. does work with gdb-mi (on Linux) though.
  3. if not want to use stdin, just enable the external terminal and in put the data manually during debugging at external terminal window.

Ref: microsoft/vscode-cpptools#1219 (comment)

{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
// "args": ["<", "${fileDirname}/data/${fileBasenameNoExtension}"], // not work, will take as argv to the programe
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
// "externalConsole": true,
"MIMode": "lldb",
"setupCommands": [ // nether setup command will read data from a file on disk as stdin to the target program
{
"text": "settings set target.input-path ${fileDirname}/data/${fileBasenameNoExtension}"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment