- Visual Studio Gdb
- Visual Studio Gdb Debugger
- Visual Studio Remote Gdb
- Visual Studio Gdb Debugger Extension
- Visual Studio Gdb Support
- Gdb For Windows 10 Download
- Visualgdb
In this tutorial, you will configure Visual Studio Code to use the GCC C compiler (g) and GDB debugger on Ubuntu in the Windows Subsystem for Linux (WSL). GCC stands for GNU Compiler Collection; GDB is the GNU debugger. WSL is a Linux environment within Windows that runs directly on the machine hardware, not in a virtual machine. VisualGDB allows debugging code without creating Visual Studio projects. Simply open the Quick Debug window, point to a binary built with GNU tools and VisualGDB will start a debugging session. Your settings will be saved in a preset, so next time you could just select them from a list and start debugging with one mouse click.
Visual Studio Gdb
-->Linux support is available in Visual Studio 2017 and later. To see the documentation for these versions, set the Version drop-down located above the table of contents to Visual Studio 2017 or Visual Studio 2019.
Once you've created a MSBuild-based Linux C++ project in Visual Studio and you've connected to the project using the Linux Connection Manager, you can run and debug the project. You compile, execute, and debug the code on the remote target.
Visual Studio 2019 version 16.1 You can target different Linux systems for debugging and building. For example, you can cross-compile on x64 and deploy to an ARM device when targeting IoT scenarios. For more information, see Specify different machines for building and debugging later in this article.
There are several ways to interact with and debug your Linux project.
Debug using traditional Visual Studio features, such as breakpoints, watch windows, and hovering over a variable. Using these methods, you may debug as you normally would for other project types.
View output from the target computer in the Linux Console window. You can also use the console to send input to the target computer.
Debug your Linux project
Select debugging mode in the Debugging property page.
GDB is used to debug applications running on Linux. When debugging on a remote system (not WSL) GDB can run in two different modes, which can be selected from the Debugging Mode option in the project's Debugging property page:
GDB is used to debug applications running on Linux. GDB can run in two different modes, which can be selected from the Debugging Mode option in the project's Debugging property page:
In gdbserver mode, GDB is run locally, which connects to gdbserver on the remote system.
In gdb mode, the Visual Studio debugger drives GDB on the remote system. This is a better option if the local version of GDB isn't compatible with the version installed on the target computer. This is the only mode that the Linux Console window supports.
Note
If you are unable to hit breakpoints in gdbserver debugging mode, try gdb mode. gdb must first be installed on the remote target.
Select the remote target using the standard Debug toolbar in Visual Studio.
When the remote target is available, you'll see it listed by either name or IP address.
If you haven't connected to the remote target yet, you'll see an instruction to use Linux Connection Manager to connect to the remote target.
Set a breakpoint by clicking in the left gutter of some code that you know will execute.
A red dot appears on the line of code where you set the breakpoint.
Press F5 (or Debug > Start Debugging) to start debugging.
When you start debugging, the application is compiled on the remote target before it starts. Any compilation errors will appear in the Error List window.
If there are no errors, the app will start and the debugger will pause at the breakpoint.
Now, you can interact with the application in its current state, view variables, and step through code by pressing command keys such as F10 or F11.
If you want to use the Linux Console to interact with your app, select Debug > Linux Console.
This console will display any console output from the target computer and take input and send it to the target computer.
Configure other debugging options (MSBuild projects)
Command-line arguments can be passed to the executable using the Program Arguments item in the project's Debugging property page.
You can export the
DISPLAY
environment variable by using the Pre-Launch Command in the project's Debugging property pages. For example:export DISPLAY=:0.0
Specific debugger options can be passed to GDB using the Additional Debugger Commands entry. For example, you might want to ignore SIGILL (illegal instruction) signals. You could use the handle command to achieve this by adding the following to the Additional Debugger Commands entry as shown above:
handle SIGILL nostop noprint
You can specify the path to the GDB used by Visual Studio using the GDB Path item in the project's Debugging property page. This property is available in Visual Studio 2019 version 16.9 and later.
Debug with Attach to Process
The Debugging property page for Visual Studio projects, and the Launch.vs.json settings for CMake projects, have settings that enable you to attach to a running process. If you require additional control beyond what is provided in those settings, you can place a file named Microsoft.MIEngine.Options.xml
in the root of your solution or workspace. Here is a simple example:
The AttachOptionsForConnection has most of the attributes you might need. The example above shows how to specify a location to search for additional .so libraries. The child element ServerOptions enables attaching to the remote process with gdbserver instead. To do that, you need to specify a local gdb client (the one shipped in Visual Studio 2017 is shown above) and a local copy of the binary with symbols. The SetupCommands element enables you to pass commands directly to gdb. You can find all the options available in the LaunchOptions.xsd schema on GitHub.
Visual Studio Gdb Debugger
Specify different machines for building and debugging in MSBuild-based Linux projects
Visual Studio Remote Gdb
In Visual Studio 2019 version 16.1, you can separate your remote build machine from your remote debug machine for both MSBuild-based Linux projects and CMake projects that target a remote Linux machine. For example, you can now cross-compile on x64 and deploy to an ARM device when targeting IoT scenarios.
By default, the remote debug machine is the same as the remote build machine (Configuration Properties > General > Remote Build Machine). To specify a new remote debug machine, right-click on the project in Solution Explorer and go to Configuration Properties > Debugging > Remote Debug Machine.
The drop-down menu for Remote Debug Machine is populated with all established remote connections. To add a new remote connection, navigate to Tools > Options > Cross Platform > Connection Manager or search for 'Connection Manager' in Quick Launch. You can also specify a new remote deploy directory in the project's Property Pages (Configuration Properties > General > Remote Deploy Directory).
By default, only the files necessary for the process to debug will be deployed to the remote debug machine. You can use Solution Explorer to configure which source files will be deployed to the remote debug machine. When you click on a source file, you'll see a preview of its File Properties directly below the Solution Explorer.
The Content property specifies whether the file will be deployed to the remote debug machine. You can disable deployment entirely by navigating to Property Pages > Configuration Manager and unchecking Deploy for the desired configuration.
In some cases, you may require more control over your project's deployment. For example, some files that you want to deploy might be outside of your solution or you want to customize your remote deploy directory per file or directory. In these cases, append the following code block(s) to your .vcxproj file and replace 'example.cpp' with the actual file names:
CMake projects
For CMake projects that target a remote Linux machine, you can specify a new remote debug machine in launch.vs.json. By default, the value of 'remoteMachineName' is synchronized with the 'remoteMachineName' property in CMakeSettings.json, which corresponds to your remote build machine. These properties no longer need to match, and the value of 'remoteMachineName' in launch.vs.json will dictate which remote machine is used for deploy and debug.
IntelliSense will suggest all a list of all established remote connections. You can add a new remote connection by navigating to Tools > Options > Cross Platform > Connection Manager or searching for 'Connection Manager' in Quick Launch.
If you want complete control over your deployment, you can append the following code block(s) to the launch.vs.json file. Remember to replace the placeholder values with real values:
Next steps
- To debug ARM devices on Linux, see this blog post: Debugging an embedded ARM device in Visual Studio.
See also
Native VSCode debugger. Supports both GDB and LLDB.
Installation
Press ctrl-p (cmd+p on OS X) and run ext install webfreak.debug
in visual studio code and install GDB/LLDB. See Usage
for details on how to set it up.
Usage
Or if you already have an existing debugger in your project setup you can click 'Create Configuration' or use the auto completion instead:
Open your project and click the debug button in your sidebar. At the top right pressthe little gear icon and select GDB or LLDB. It will automatically generate the configurationyou need.
Note: for LLDB you need to have lldb-mi
in your PATH
If you are on OS X you can add lldb-mi
to your path usingln -s /Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi /usr/local/bin/lldb-mi
if you have Xcode.
Now you need to change target
to the application you want to debug relativeto the cwd. (Which is the workspace root by default)
Additionally you can set terminal
if you want to run the program in a separate terminal withsupport for input. On Windows set it to an empty string ('
) to enable this feature. On linuxset it to an empty string ('
) to use the default terminal emulator specified with x-terminal-emulator
or specify a custom one. Note that it must support the -e
argument.
Before debugging you need to compile your application first, then you can run it usingthe green start button in the debug sidebar. For this you could use the preLaunchTask
argument vscode allows you to do. Debugging multithreaded applications is currently notimplemented. Adding breakpoints while the program runs will not interrupt it immediately.For that you need to pause & resume the program once first. However adding breakpointswhile its paused works as expected.
Extending variables is very limited as it does not support child values of variables.Watching expressions works partially but the result does not get properly parsed andit shows the raw output of the command. It will run data-evaluate-expression
to check for variables.
While running you will get a console where you can manually type GDB/LLDB commands or MIcommands prepended with a hyphen -
. The console shows all output separatedin stdout
for the application, stderr
for errors and log
for log messages.
Some exceptions/signals like segmentation faults will be catched and displayed butit does not support for example most D exceptions.
Visual Studio Gdb Debugger Extension
Attaching to existing processes
Visual Studio Gdb Support
Attaching to existing processes currently only works by specifying the PID in thelaunch.json
and setting request
to 'attach'
. You also need to specify the executablepath for the debugger to find the debug symbols.
This will attach to PID 4285 which should already run. GDB will pause the program on entering and LLDB will keep it running.
Gdb For Windows 10 Download
Using gdbserver
for remote debugging (GDB only)
You can also connect to a gdbserver instance and debug using that. For that modify thelaunch.json
by setting request
to 'attach'
and remote
to true
and specifing theport and optionally hostname in target
.
This will attach to the running process managed by gdbserver on localhost:2345. You mightneed to hit the start button in the debug bar at the top first to start the program.
Using ssh for remote debugging
Debugging using ssh automatically converts all paths between client & server and also optionallyredirects X11 output from the server to the client. Simply add a ssh
object in your launch
request.
cwd
will be used to trim off local paths and ssh.cwd
will map them to the server. This isrequired for basically everything except watched variables or user commands to work.
For X11 forwarding to work you first need to enable it in your Display Manager and allow theconnections. To allow connections you can either add an entry for applications or run xhost +
in the console while you are debugging and turn it off again when you are done using xhost -
.
Visualgdb
Because some builds requires one or more environment files to be sourced before running anycommand, you can use the ssh.bootstrap
option to add some extra commands which will be prependedto the debugger call (using &&
to join both).