Gdb Visual Studio Code



  1. Gdb Visual Studio Code Linux
  2. Gdb Attach Visual Studio Code
  • Visual Studio 2008 - 2019; If you don't have Visual Studio, try the free VS Community Edition or a trial of VS Enterprise; Download older releases of VisualGDB. Installation Instructions If you are updating from an older version of VisualGDB, simply run the new MSI file. It will perform the update automatically and will use your old license key.
  • This video explains how to setup Visual Studio Code for building and debugging C programs on Windows 10. G and gdb from MinGW-w64 are used for that purpo.

Pick any port you like - here 1234. Test the connection to gdbserver from your local machine by typing. Gdb (gdb) target remote myremotehostname:1234. Trigger any gdb command to check whether it works - e.g. C (or continue) to continue running mybinary. Put the following into your.vscode/launch.json. Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers - paked/cortex-debug. Support J-Link, OpenOCD GDB Server; Initial support for STMicroelectronic's ST-LINK GDB server (no SWO support yet) Partial support for PyOCD and textane/stlink (st-util) GDB Servers (SWO can only be captured via a serial port). VisualGDB includes a powerful Clang-based IntelliSense engine that fully supports GCC-specific code and is integrated with Make, QMake and CMake. Advanced features include: Easy navigation around your code with CodeJumps; Create implementations for newly added methods; Create-from-use for methods and constructors.

This tutorial shows how to build and debug a simple Android App with a native library with Visual Studio.

Before you begin, please install VisualGDB (ensure that “Android Edition” is checked in the installer).

Gdb Visual Studio Code

You will also need to install Java JDK, Android SDK, NDK and Apache ANT.

Step-by-step tutorial

  1. Start Visual Studio. Select File->New project->VisualGDB->Android App Wizard.
  2. Specify your project name and location (please avoid spaces in file path). Press OK to start the wizard.
  3. If you are running VisualGDB Android wizard for the first time, please press the “Configure NDK/SDK locations” button to tell VisualGDB the locations of your Android-related tools. If you don’t have any of the tools installed, simply press the “install” button.WARNING! After installing Android SDK please run the SDK manager as Administrator and install the Tools (SDK tools/Platform tools) and all required Android APIs (at least Android 1.5 and 2.3.3).
  4. In this tutorial we’ll go the easiest way and simply create a new application from scratch. To do it, please select the first option in the wizard:
  5. On the next page you can customize the project name or leave the default names.
  6. Finally you can select the Android platform. If you see not platforms in the list, please press the “Manage installed platforms” button and install the required platforms. Please select “Android 1.5” as the app platform.
  7. When you press “Finish”, VisualGDB will create a new Android App project for you. If you have an Android phone or a tablet, you can enable USB debugging on it and connect it to your PC. If not, please start the Android simulator (AVD Manager) by selecting “Android->AVD Manager” in Visual Studio:
  8. If you have no virtual devices defined by now, please create one. It is recommended to specify at least Android 2.3.3 as the simulator platform:
  9. Start the virtual device. While it is booting, go to Visual Studio, set a breakpoint on the sprintf() line inside the main C file and and select Build->Build Solution.
  10. Once the solution has been built, please ensure that the virtual Android device has been started.
  11. Once the device is ready, press F5 to start debugging. VisualGDB will deploy the APK file automatically and will start a debugging session.
  12. Please go to the simulator and click on the huge full-screen button.
  13. Clicking the button will trigger the sprintf() breakpoint in Visual Studio:
  14. Hover the mouse over s_ButtonPressCounter, click on “0”, change the value to “123” and press ENTER.
  15. Press F5 to continue running the app. Go back to the simulator and ensure that the label indicates 123 hits.
  16. Have a look through the main debugging windows provided by VisualGDB using the Debug->Windows command:
    • The GDB Session window allows sending arbitrary commands to the GDB debugger
    • The Android LogCat window shows additional logging information provided by Android
    • The GDBServer Console window shows various NDK debugging information.
  17. Press Shift+F5 to stop debugging.
  18. As VisualGDB uses the Android NDK build system in the background, you can modify various build flags and settings by editing the Android.mk file. Note that VisualGDB will automatically update the LOCAL_SRC_FILES for you when you add/remove source files in the solution:

Now that you have managed to debug a basic project, you can follow the tutorials below for more advanced examples:

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.

Visual Studio Code supports the following debuggers for C/C++ depending on the operating system you are using:

  • Linux: GDB
  • macOS: LLDB or GDB
  • Windows: the Visual Studio Windows Debugger or GDB (using Cygwin or MinGW)

Windows debugging with GDB

You 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 (launch.json). To debug your Cygwin or MinGW application, add the miDebuggerPath property and set its value to the location of the corresponding gdb.exe for your Cygwin or MinGW environment.

For example:

Cygwin/MinGW debugging on Windows supports both attach and launch debugging scenarios.

To learn more, see Configuring C/C++ debugging.

If you are debugging with GDB on Windows, see Windows Debugging with MinGW64.

Conditional breakpoints

Conditional 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 breakpoints

Function 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 evaluation

VS Code supports expression evaluation in several contexts:

  • You can type an expression into the Watch section of the Run view and it will be evaluated each time a breakpoint is hit.
  • You can type an expression into the Debug Console and it will be evaluated only once.
  • You can evaluate any expression that appears in your code while you're stopped at a breakpoint.

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 debugging

The 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 debugging

The C/C++ extension for VS Code also has the ability to debug memory dumps. To debug a memory dump, open your launch.json file and add the coreDumpPath (for GDB or LLDB) or dumpPath (for the Visual Studio Windows Debugger) property to the C++ Launch configuration, set its value to be a string containing the path to the memory dump. This will even work for x86 programs being debugged on an x64 machine.

Additional symbols

If there are additional directories where the debugger can find symbol files (for example, .pdb files for the Visual Studio Windows Debugger), they can be specified by adding the additionalSOLibSearchPath (for GDB or LLDB) or symbolSearchPath (for the Visual Studio Windows Debugger).

For example:

or

Locate source files

The 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 sourceFileMap section. The first match in this list will be used.

For example:

GDB, LLDB, and LLDB-MI Commands (GDB/LLDB)

For the C++ (GDB/LLDB) debugging environment, you can execute GDB, LLDB and LLDB-MI commands directly through the debug console with the -exec command, but be careful, executing commands directly in the debug console is untested and might crash VS Code in some cases.

Other debugging features

  • Unconditional breakpoints
  • Watch window
  • Call stack
  • Stepping

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 Configuring C/C++ debugging.

Natvis framework

You 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 remotely

For information about attaching to a remote process, such as debugging a process in a Docker container, see Pipe transport.

Debug the debugger

If 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 limitations

Symbols and code navigation

All platforms:

  • Because the extension doesn't parse function bodies, Peek Definition and Go to Definition don't work for symbols defined inside the body of a function.

Debugging

Windows:

  • GDB on Cygwin and MinGW cannot break a running process. To set a breakpoint when the application is running (not stopped under the debugger), or to pause the application being debugged, press Ctrl-C in the application's terminal.
  • GDB on Cygwin cannot open core dumps.

Linux:

  • You may see an error saying: ptrace: Operation not permitted. This is due to GDB needing elevated permissions in order to attach to a process. This can be solved using the solutions below:
    1. When using attach to process, you need to provide your password before the debugging session can begin.

    2. To disable this error temporarily, use the following command:

      echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

    3. To remove the error permanently, add a file called 10-ptrace.conf to /etc/sysctl.d/ and add the following kernel.yama.ptrace_scope = 0.

Visual

Gdb Visual Studio Code Linux

macOS:

  • LLDB:
    • When debugging with LLDB, if the Terminal window is closed while in break mode, debugging does not stop. Debugging can be stopped by pressing the Stop button.
    • When debugging is stopped the Terminal window is not closed.
  • GDB:
    • Additional manual install steps are required to use GDB on macOS. See Manual Installation of GDB for OS X in the README.
    • When attaching to a process with GDB, the application being debugged cannot be interrupted. GDB will only bind breakpoints set while the application is not running (either before attaching to the application, or while the application is in a stopped state). This is due to a bug in GDB.
    • Core dumps cannot be loaded when debugging with GDB because GDB does not support the core dump format used in macOS.
    • When attached to a process with GDB, break-all will end the process.

Next steps

Read on to find out about:

  • Configure C/C++ debugging - Learn about additional debugger configuration options.
  • Basic Editing - Learn about the powerful Visual Studio Code editor.
  • Code Navigation - Move quickly through your source code.
  • Tasks - use tasks to build your project and more.
  • Debugging - find out about the Visual Studio Code debugger.

Gdb Attach Visual Studio Code

If you have any other questions or run into any issues, please file an issue on GitHub.