Deploy, run, and debug your Linux project

Once you have created a Linux C++ project in Visual Studio and you have 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.

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 a special Linux Console window. You can also use the console to send input to the target computer.

Debug your Linux project

  1. Select debugging mode in the 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:

    GDB options

    • In gdbserver mode, GDB is run locally, which connects to gdbserver on the remote system. Note that this is the only mode that the Linux Console window supports.

    • In gdb mode, the Visual Studio debugger drives GDB on the remote system. This is a better option if the local version of GDB is not compatible with the version installed on the target computer. |

    Note

    If you are unable to hit breakpoints in gdbserver debugging mode, try gdb mode. gdb must first be installed on the remote target.

  2. Select the remote target using the standard Debug toolbar in Visual Studio.

    When the remote target is available, you will see it listed by either name or IP address.

    Remote target

    If you have not yet connected to the remote target, you will see an instruction to use Linux Connection Manager to connect to the remote target.

    Remote Architecture

  3. 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.

  4. 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.

    Hit a 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.

  5. If you want to use the Linux Console to interact with your app, select Debug > Linux Console.

    Linux Console menu

    This console will display any console output from the target computer as well as take input and send it to the target computer.

    Linux Console window

Configure other debugging options

  • Command-line arguments can be passed to the executable using the Program Arguments item in the project's Debugging property page.

    Program Arguments

  • 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

Next steps

See also

C++ Debugging Properties (Linux C++)