In this post, we will be examining gdbgui, an extension of gdb, with visual debugging abilities, which will help us debug compiled languages.

Introduction

Developers spend a lot of time debugging and maintaining current codebases. Understanding different methods of debugging is critical. Some developers still feel comfortable with more manual ways of debugging. There are also a lot of snapshot tools that give you a detailed report of the issues and errors after a certain part of the code runs. Both of these approaches can be beneficial but they are often focused on when the error happens. With the help of debugger tools, we can see how an error has happened.

In this post, we will be examining gdbgui, an extension of gdb, with visual debugging abilities, which will help us debug compiled languages.

What is gdb?

gdb is a very handy tool for debugging compiled languages such as [C](https://en.wikipedia.org/wiki/C_(programming_language), C++, [Go](https://en.wikipedia.org/wiki/Go_(programming_language), Rust, etc. It is available for common operating systems such as Mac, Windows, and Linux. This debugger can help us in several ways such as:

  • Getting an overview of program variables and context when the error occurs
  • If a core dump, which is the state of memory at a specific time, happens because of a crash or abnormal termination, we can understand what statement of expression caused it
  • Stopping on parts of the program that are causing issues while the program is running
  • Testing and experimenting with the program while debugging to narrow down or fix the problems

While these are very helpful in our debugging effort, you still need to run the debugging commands in the terminal and might not get a good overview of the context of the program.

What is gdbgui?

gdbgui is another debugging tool that is built on top of gdb. The main difference is that gdbgui exposes a browser-based frontend to developers, so they can add breakpoints, view stack traces, and change the context and parameter values while the debugger is running.

gdb debugger browser based frontendSource: https://www.gdbgui.com/screenshots/

gdbgui architecture

The library takes advantage of WebSockets. Whenever the frontend debugging tool starts, a WebSocket connection is established which is the communication channel between the browser and the backend. After each established WebSocket, the backend starts a new managed gdb subprocess for parsing the output while spawning a separate subprocess for constantly checking for the output from the other subprocess. Finally, it transports the output to the client using the same WebSocket.

Installation

Let us install gdbgui on our machine. As mentioned before, gdbgui can be installed on various operating systems, but it can also run remotely.

There are several ways to install gdbgui on your machine depending on your operating system, but I am going to follow the simplest and most straightforward one. Since this library is reliant on Python 3, you need to be careful in following any of the installation guides as it might interfere with your machine’s global settings.

The best way to install gdbgui is via [pipx](https://github.com/pipxproject/pipx). This tool lets you install libraries and applications written in Python in an isolated environment while allowing you to run them via shell as globals via shell. This removes a lot of headaches that might happen because of version incompatibility.

Start by running these commands:

// Step 1: Install pipx
python3 -m pip install --user pipx

// Step 2: Add new path in user path
python3 -m userpath append ~/.local/bin

// Step 3: Install gdbgui
pipx install gdbgui

// Or you can run gdbgui without installing
pipx run gdbgui

Debugging using gdbgui

Let us debug a simple C++ program using gdbgui to get familiar with its features.

First, download this repository to your machine, using the dropdown on the right side of the page.

gdbuigithub

Source: https://github.com/cs01/gdbgui

#rust #go #developer

Visual Debugging using gdbgui
2.25 GEEK