Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Installation and setup (C++)

This chapter discusses how to add v5gdb to a C++ project using PROS.

Important

v5gdb is compatible with PROS v4.2.3 or later.

(At the time of writing, this is a very recent release, so actually check that you are using it!)

To check, run pros c info-project in your project folder and look for the version of kernel. If it is older than 4.2.3, run pros c upgrade to update it.

Installing v5gdb

v5gdb has two parts: a library that runs on the brain as part of your program, and a v5gdb command that runs on your computer.

The library

Open the PROS Integrated Terminal (or any terminal in your project folder) and run these commands:

pros c add-depot v5gdb https://raw.githubusercontent.com/vexide/v5gdb/depot/preview.json
pros c apply v5gdb

The first command tells PROS where to download v5gdb from. You only need to run it once per computer. The second command adds the v5gdb library to the current project, so run it once in each project you want to debug.

The v5gdb command

Next, install the v5gdb command on your computer using one of the commands below. This is a support program that helps GDB running on your computer connect to your VEX V5 brain.

Shell script (macOS/Linux)

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/vexide/v5gdb/releases/download/v0.1.0-beta.2/v5gdb-cli-installer.sh | sh

PowerShell script (Windows)

powershell -ExecutionPolicy Bypass -c "irm https://github.com/vexide/v5gdb/releases/download/v0.1.0-beta.2/v5gdb-cli-installer.ps1 | iex"
Other installation methods
  • Cargo: cargo install v5gdb-cli@0.1.0-beta.2
  • Cargo Binstall: cargo binstall v5gdb-cli@0.1.0-beta.2
  • View the Releases page for detailed install instructions and manual downloads.

After installing, close and reopen your terminal (or restart VS Code) so it can find the new command. Then check that it works:

v5gdb --help

If you installed PROS through the VS Code extension, you already have GDB and don’t need to install it separately.

Project setup

To enable debugging support, add the following line to your initialize function, preferably near the beginning.

#include "v5gdb/v5gdb.h"

void initialize() {
    v5gdb::install({.stop_motors_on_break = true});
    // ...rest...
}

stop_motors_on_break makes every motor stop whenever your program pauses in the debugger. Without it, motors keep running at whatever speed they were last set to while you look around. You can also toggle this while debugging with monitor autostop true or monitor autostop false.

Debugger setup

Build and upload your program, then start it:

pros mu

At this point, you can now view the debug console by running the v5gdb command in the PROS Integrated Terminal.

$ v5gdb
GNU gdb (GDB) 16.3
Copyright (C) 2024 Free Software Foundation, Inc.
Reading symbols from ./bin/hot.package.elf...
add symbol table from file "./bin/cold.package.elf"
Reading symbols from ./bin/cold.package.elf...
Remote debugging using :35537
initialize () at src/main.cpp:19
19              printf("Hello world\n");
(gdb)

You may now use GDB to debug your program: for instance, type continue to resume execution, or press Ctrl-C to pause the program.

Tip

Make sure to quit other commands like pros, cargo v5, or vexcom before starting v5gdb. Only one program can use the brain’s USB connection at a time.

Considerations

PROS compiles your program with optimizations turned on. This makes the debugger a little less predictable: some variables may show as <optimized out>, and stepping line by line may jump around or skip lines. This is normal. If it gets in the way, set a breakpoint on a later line instead of stepping, or print the value you care about at a point where it’s still in use.

Next steps