After you have set up the basics of your debugging environment as specified in the configuration tutorials for each target compiler/platform, you can learn more details about debugging C/C++ in this section. Show
Visual Studio Code supports the following debuggers for C/C++ depending on the operating system you are using:
Windows debugging with GDBYou can debug Windows applications created using Cygwin or MinGW by using VS Code. To use Cygwin or MinGW debugging features, the debugger path must be set manually in the launch configuration ( For example:
Cygwin/MinGW debugging on Windows supports both attach and launch debugging scenarios. To learn more, see Configure C/C++ debugging. If you are debugging with GDB on Windows, see Windows Debugging with MinGW64. Conditional breakpointsConditional breakpoints enable you to break execution on a particular line of code only when the value of the condition is true. To set a conditional breakpoint, right-click on an existing breakpoint and select Edit Breakpoint. This opens a small peek window where you can enter the condition that must evaluate to true in order for the breakpoint to be hit during debugging. In the editor, conditional breakpoints are indicated by a breakpoint symbol that has a black equals sign inside of it. You can place the cursor over a conditional breakpoint to show its condition. Function breakpointsFunction breakpoints enable you to break execution at the beginning of a function instead of on a particular line of code. To set a function breakpoint, on the Run view right-click inside the Breakpoints section, then choose Add Function Breakpoint and enter the name of the function on which you want to break execution. Expression evaluationVS Code supports expression evaluation in several contexts:
Expressions in the Watch section take effect in the application being debugged; an expression that modifies the value of a variable will modify that variable for the duration of the program. Multi-threaded debuggingThe C/C++ extension for VS Code has the ability to debug multi-threaded programs. All threads and their call stacks appear in the Call Stack section: Memory dump debuggingThe C/C++ extension for VS Code also has the ability to debug memory dumps. To debug a memory dump, open your Additional symbolsIf there are additional directories where the debugger can find symbol files (for example, For example:
or
Locate source filesThe
source file location can be changed if the source files are not located in the compilation location. This is done by simple replacement pairs added in the For example:
GDB, LLDB, and LLDB-MI Commands (GDB/LLDB)For the Other debugging features
For more information on debugging with VS Code, see this introduction to debugging in VS Code. For additional ways to configure the launch.json file so that you can debug your C/C++ app, see Configure C/C++ debugging. Natvis frameworkYou create custom views of C++ object in the debugger with the Natvis framework. You can read the Custom views for native objects topic for details on using Natvis with the C/C++ extension. Debug remotelyFor information about attaching to a remote process, such as debugging a process in a Docker container, see Pipe transport. Debug the debuggerIf you are experiencing a debugging problem with the extension that we can't diagnose based on information in your issue report, we might ask you to enable logging and send us your logs. See Enable logging for the debug adapter to learn how to get C/C++ extension logs. Known limitationsSymbols and code navigationAll platforms:
DebuggingWindows:
Linux:
macOS:
Next stepsRead on to find out about:
If you have any other questions or run into any issues, please file an issue on GitHub. 5/21/2020 How to debug C code?8 Steps for Debugging in C. Start TotalView and debug the fib application.. Set a breakpoint at line 12 by clicking on the line number.. Start debugging by pressing the Green GO button. ... . Use the Next button to step through the loop and watch the values of the variables in the Local Variables window change as you do so.. Can we debug C program?The compiler takes care of checking the syntax errors in the code. To debug the code via GDB, we need to tell the compiler to collect the debugging information in the executable. This is important to view code while debugging.
|