trying to use lldb to debug c++ on vsCode on macbook - c++

I am using the Microsoft's C/C++ extension in VS Code and I created a launch.json for debugging.
{
"version": "0.2.0",
"configurations": [
{
"name": "c++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/main",
"args": ["world/moveleft.w"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
It does run successfully, but it doesn't stop on my breakpoints.
I am using a macbook, I tried using gdb instead of lldb and it didn't work.

Related

How to watch the content of a container (eq: std::vector) with the debugger of Microsoft's C++ extension in vscode?

I'm on MacOS, and I'm using the C/C++ extension for vscode from Microsoft. When debugging, I can't watch the content of the STL containers, (for example, the elements of a std::vector). Here is a picture of how the debugger looks.
This is my launch.json file.
{
"version": "0.2.0",
"configurations": [
{
"name": "g++-9 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: g++-9 build active file"
}
]
}
Thanks in advance.

How to set gdb as debugger for the C/C++ extension pf VSCode on MacOS?

the C/C++ Extension of Microsoft for VSCode allows to set a launch.json file with which you can set how to debug and run your C++ code. By default it has lldb as debugger for MacOS.
I wonder how to set gdb as debugger instead of lldb.
I tried and it shows me:
Unable to start debugging. GDB exited unexpectedly with exit code 134 (0x86).
This is how my launch.json file looks like:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++-9 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"osx": {
"miDebuggerPath": "/usr/local/bin/gdb",
"MIMode": "gdb"
},
"preLaunchTask": "C/C++: g++-9 build active file"
}
]
}
Make sure you have gdb installed.
For that you can use:
brew install gdb
Then make the gdb binary is certified. Because:
... modern Darwin kernels restrict the capability to assume
control over another process (here, for the purpose of debugging it),
since that capability is a boon to malware. In order for said
taskgated to grant access to gdb, the latter must be fitted with
entitlements, which consist of digitally-signed metadata inside the
gdb binary.
From: https://sourceware.org/gdb/wiki/PermissionsDarwin
To create a certification follow these instructions:
https://sourceware.org/gdb/wiki/PermissionsDarwin
After doing so, certify the binary as instructed here.
Then try this for launch.json:
{
// 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": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "C/C++: g++ build active file"
}
]
}

Can't receive input (cin) in c++ program in Windows vscode

I have been trying to figure out how to receive input in Windows vscode c++ program for example using cin. I have already tried running with MingW and cl and both have the same result.
Terminal output is being sent to vscode debugconsole and I can't interact with the program.
The same program runs fine if it is run directly via terminal or cmd command prompt.
Here is my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "cl.exe build active file",
"type": "shell",
"command": "c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
And here is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "cl.exe build active file"
}
]
}
I've seen other suggestions like using "code-runner.runInTerminal": true and "terminal": "integrated" but this has not worked for me. I have already seen this other post: Visual Studio Code: Take Input From User
But so far no joy.
Here's a screen of vscode that shows the issue with a small c++ program:
You will see from above that the output is directed to the debugconsole pane and no interaction is possible from there.
Whereas, the advice from https://code.visualstudio.com/docs/cpp/config-mingw indicates the IO should go to the terminal pane.

How to make VS Code not open a terminal when debugging?

I've installed VS Code on Ubuntu 17.04.
When I debug my C++ application, the output is displayed in a dedicated terminal and not within VS Code itself (like Eclipse does).
How do I make VS Code display output within the editor itself, i.e., not open another terminal?
My launch configuration is as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out",
"args": ["foo", "bar", "baz"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++"
}
]
}
I'd hoped that setting externalConsole to false would solve the problem. However, it didn't change anything.
For a C++ project, use "externalConsole": false, as follows:
This will open integrated terminal instead of external terminal. You can use "internalConsoleOptions": "openOnSessionStart" if you want to open the debug console instead of the integrated/external console:
For a Java project, use , "console": "integratedTerminal" in the configurations file:
Use "console": "internalConsole" if you do not want to see any debug console.
Set "console":"none" like such:
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}"
"cwd": "${workspaceFolder}"
"console": "none"

how to debug tensorflow internal c++ code efficiently with IDE(intelJ or Xcode) on mac?

I want to debug the c++ source code of tensorflow, e.g tensorflow/c/c_api.cc . I've found some answers about how to debug the c++ code with gdb,but I want to know if it's possible to debug it with ide like Xcode, which can be very comfortable for editing and debug.Thanks .
After much search and dig, I finally succeed to debug the tensorflow c++ source code in an acceptable way.I used bazel+vscode+lldb on mac.
bazel: build the target(Also can be done by vscode).
visual studio code: debug and read code
lldb : debug backend
my vscode lanch.json is :
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/bazel-out/darwin_x86_64-dbg/bin/tensorflow/cc/example/example",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb"
}
]
}