How do I stop vs code to stop debugging internal cpp modules? - c++

VScode screenshot
Vscode cpp debugger is taking me in to internal c++ modules like you can see in this picture
I just want it to debug my files

You will need to create new file launch.json first.
Now add
{
"name": "C++ Launch (Windows)",
"type": "cppvsdbg",
"justMyCode": true,
"request": "launch",
"program": "C:\\app1\\Debug\\app1.exe",
"symbolSearchPath": "C:\\Symbols;C:\\SymbolDir2",
"externalConsole": true,
"logging": {
"moduleLoad": false,
"trace": true
},
"visualizerFile": "${workspaceFolder}/my.natvis",
"showDisplayString": true
}
Check this first: https://code.visualstudio.com/docs/cpp/launch-json-reference
If above thing doesn't work, try using "Step Over" option when you hit internal C++ functions.
Check this: https://code.visualstudio.com/docs/editor/debugging#_debug-actions

Related

Unable to start debugging. Not implemented. Error on VS code

Hi i recently started using VS code for my C++ course. I am trying to get the debugger to work but even with hours of trying to figure out what's wrong i still get the following error "Unable to start debugging. Not implemented." I am a bit unsure on what that means let alone how to solve it. My launch.json file looks like this. Thank you in advance for the help.
{
// 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": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "Assigment_1.C++",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal"
}
]
}
I don't have enough Karma to post in the comment thread but I wanted to say that I don't think it matters that you're using vs code instead of visual studio. It says in the debug console that the C/C++ extionsion is compatible with both, and this is the .json that is automatically generated by vs code. I'm having the same issue trying to run C. I've reached out to microsoft support. Let me know if you've figured it out, thanks.
Alternatively, it seems to work if you just download the code runner extension and then right click and choose run code instead. At least it did for me using C. Still trying to figure out how to use it with the debugger however.
I had the same problem and I have solved this problem using these steps.
First create your C++ folder (mine is cpp test) and create the main.cpp file.
Then after making the main method just click f5 and the vs code will pop up a box asking whether C++(GDB) or C++(Windows).
refer the photo
Now click on C++(GDB/LLDB).
Now click on g++.exe (Build and Debug active file).
Now the vs code will generate the lanch.json file.
Then go to the main.cpp file, Just click f5 and it will run without any problem. It worked for me.
(Please make sure that you have installed cygwin64 on your computer, mingw is also possible)
The json file below worked for me
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/mingw/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]

How to use integratedTerminal in launch.json for C++ in Visual Studio Code?

I am trying Visual Studio Code for debugging C++ code. I would like the debugger to use the integrated terminal for showing the STDOUT and reading from the STDIN. Currently it opens an external terminal.
I tried putting "console": "integratedTerminal" in launch.json but I get the parsing error: Property console is not allowed.
How can I achieve the behaviour I described?
EDIT: this is my 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": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/path_to_my_executable",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
],
"console": "integratedTerminal",
}
the default setting for STDOUT and STDIN of c++ is just the "integratedTerminal" or "integratedConsole".
you can change it by enabling "externalConsole":true in the launch.json then you will get a pop up console window that you can type in.
also if you encounter the same problem as me that the integratedTerminal cannot read input from user as below hanging(env. windows 10)
my solution was to replace cygwin's gdb and g ++ with mingw64's.
then the input output are normal

Visual Studio Code use input text file on debug

I am trying to follow the direction from this post
Visual Studio Code redirect input on debug
but when I add the console config to the launch.json file
"console": "integratedTerminal"
it throws a "Property console is not allowed". and when I debug the program it still waits on input and never reach break point like I would if I start in shell like
"./a.out 1 test1.txt"
"./a.out 1 <test1.txt"
Full config
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
//"program": "${workspaceRoot}/a.out.dSYM/Contents/Resources/DWARF/a.out",
"program": "${workspaceRoot}/a.out",
"args": ["1", "<","test1.txt"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
//"miDebuggerPath": "C:\\mingw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"console": "integratedTerminal"
//"preLaunchTask": //"build test1"
}
]
}
I use GDB instead of lldb but still encountered the same issue. It waited for an input when I typed arguments in the "launch.json" file this way:
"args": ["<", "test1.txt"],
But it started working properly when I had rewritten it in the following manner:
"args": ["<", "${workspaceFolder}/test1.txt"],
I think that one should add a parent folder even though the input file is in the workspace folder or simply use the full path.
If you use the integrated console, the < doesn't get interpreted by a shell. Usually, using externalConsole: true fixes the problem since this uses a shell. But if the external console doesn't work on your system for whatever reason and you're forced to use externalConsole: false, the workaround is to let GDB create the shell: miDebuggerArgs: "'-ex' 'run < /path/to/test1.txt'"

Debugging c++ built with a makefile in Visual Studio Code

I have an existing code base that builds with a makefile and I'd like to use Visual Studio Code to run it.
I started by opening my project directory with Visual Studio Code.
Then, for building I created a task as per http://code.visualstudio.com/docs/languages/cpp :
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args":["-c", "cd build && make"]
}
which works fine. I then downloaded the C++ extension and created a launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${workspaceRoot}/build/myProgram",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
},
// attach here, which I don't care about
]
}
This launch file allows me to start my program using the built-in debugger. I know that it works because I see all the symbol files getting loaded and I can pause the program.
However, VS Code doesn't "see" my source files; when I pause it says
Source /Unknown Source is not available.
I also can't set breakpoints in the source. I see that some symbols get loaded though as I can see my function names on the call stack when I pause execution.
So what did I miss? Do I absolutely have to do as they say here ( http://code.visualstudio.com/docs/languages/cpp ) and make a g++ task where I'll have to manually input all my include paths and linker inputs? The point of using a makefile in the first place was to not have to do this tedious stuff...
Thanks a lot to anyone who knows how to wrangle VS code.
You should be able to debug by just using tasks.json and launch.json.
Are you sure you have the -g option set in your makefile?
Another thing - you can have your task be executed on launch by adding
"preLaunchTask": "bash" to your your launch.json.
Hope this helps!
At windows; Mingw, gdb and -g parameter at compilation of the executable are necessary with c/c++ extension. "preLaunchTask": "bash" is not necessary in launch.json.

VSCode: Debugger for C++ does not launch nor attach properly

I am using:
Ubuntu 16.04 (I know it is not supported officially)
Latest VSCode version
Latest "C/C++ for VSCode" version
My project is a C++ project and the structure looks like this:
/home/lvier/mainProject/fooProject (source code)
/home/lvier/mainProject/build/fooProject (binaries)
I am working in the sub-project "/home/lvier/mainProject/fooProject" and in "/home/lvier/mainProject/build/fooProject" there are many sub programs (lets say "foo", "foo_sub1", "foo_sub2" ...).
My goal:
I want to start the program "foo" (which starts all other foo_sub-programs) and then, I want to debug a certain sub program (let's say "foo_sub1") by attaching to it. I am also fine with starting and debugging in the same time as long as I can debug the sub-program "foo_sub1". The main project itself does not contain any executables.
Some months ago, debugging was working with "attach". For me it is not working anymore (because of VSCode updates and/or C/C++ extension updates). Here are my problems:
Assume that "foo" is running.
When using the "C++ Attach"-config and setting "request": "attach" (which is getting highlighted as "not an accepted value"), it will ask for the property "processId" if it is not set. If I set "processId", the error "Attach not supported" pops up.
If I use the "C++ Attach"-config with "request": "launch" (in the beginning this was autogenerated by the C/C++-extension), then the program finds the process id, tries to attach but then aborts with the message "Unable to start debugging. Commands are only accepted when the process is stopped." - what a surprise.
Assume that "foo" is not running yet.
When using the "C++ Launch"-config, the program starts but no UI elements appear. Instead, it starts with a new terminal popping up which says "warning gdb failed to set controlling terminal operation not permitted" for a brief moment and in the internal console of VSCode, it states that it stops at a certain line of code (a breakpoint not defined by me) and prints
"Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1"."
From there I can't continue further and I have to manually terminate the program.
When I use GDB without VSCode, i.e. just by native terminal, my program is starting properly but with VSCode, there seem to be some issues currently.
This is my current, autogenerated config where I only edited the "cwd" and "program" paths (assume that the environment variable "${env.build_foo}" is set to "/home/lvier/mainProject/build/fooProject"):
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${env.build_foo}/foo",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
},
{
"name": "C++ Attach",
"type": "cppdbg",
"targetArchitecture": "x64",
"request": "launch", // <-- "attach" is not allowed (anymore)! :(
"program": "${env.build_foo}/foo_sub1",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"processId": "${command.pickProcess}",
"externalConsole": false,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
}
]
}
So far I am really frustrated and still don't want to give up on VSCode (I don't want to switch to another IDE yet). I have searched a lot for other issues and also tried to set some other config-properties but none of it helped.
Does anyone else also have such issues with the debugger or is this a general problem with the extension (... and Ubuntu 16.04)?
I am happy for any help or convenient workaround. Thanks in advance!
Note:
I have also created a thread on the related github page (see https://github.com/Microsoft/vscppsamples/issues/115)
Update 07/26/2016:
It seems like there is a bug with the C/C++ extension (see comments in the github link above). It is still being investigated though.
Here solution:
...Debugging works for me now after I removed the GCC -s flag (strip symbol table and relocation information) from the linker settings...
Got it from last answer of the next link (thanks HorstBaerbel):
https://github.com/Microsoft/vscode-cpptools/issues/115#issuecomment-299334301