- Setup: Debugging Setup
- Debugger: Why is debugging not working?
- Build: How to enable debug symbols
- Logging: How to enable logging
The debugger needs to be configured to know which executable and debugger to use:
Click menu item: Debug -> Add Configuration...
The file launch.json will now be open for editing with a new configuration. The default settings will probably work except that you need to specify the program setting.
See the Documentation/Debugger folder in this repository for more in-depth documentation on how to configure the debugger.
When you start debugging, if it is showing that your breakpoints aren't bound (solid red circle) or they are not being hit, you may need to enable debug symbols during compilation.
If your debugger is showing a grey stacktrace or won't stop at a breakpoint,or the symbols in the call stack are grey then your executable was compiled without debug symbols.
Enabling debug symbols are dependent on the type of compiler you are using. Below are some of the compilers and the compiler options necessary to enable debug symbols.
When in doubt, please check your compiler's documentation for the options necessary to include debug symbols in the output. This may be some variant of -g or --debug.
-
- If you invoke the compiler manually then add the
--debugoption. - If you're using a script then make sure the
CXXFLAGSenvironment variable is set; e.g.export CXXFLAGS="${CXXFLAGS} --debug" - If you're using CMake then set make sure the
CMAKE_CXX_FLAGSis set; e.g.export CMAKE_CXX_FLAGS=${CXXFLAGS}
- If you invoke the compiler manually then add the
-
See Clang C++ but use
CFLAGSinstead ofCXXFLAGS. -
If you invoke the compiler manually, add the
-goption. -
Symbols are located in the
*.pdbfile.
Enabling logging will show communication information between VS Code and our extension and between our extension and the debugger.
The logging block with its defaults is as follows:
"logging": {
"trace": false,
"traceResponse": false,
"engineLogging": false
}
The logging here is called trace logging and can be enabled by setting trace and traceResponse to true in the logging block inside launch.json. This will help diagnose issues related to VS Code's communication to our extension and our responses.
The logging between CppTools and the debugger is called engineLogging. When using an MI debugger such as gdb or lldb, this will show the request, response and events using the mi interpreter. This logging will help us determine whether the debugger is receiving the right commands and generating the correct responses.
The logging block with its defaults is as follows:
"logging": {
"engineLogging": false
}
The Visual C++ debugger logging will show only the communication to and from VS Code as all communication to the debugger is done internally to the process and is not visible through logging.