Guide to Installing and Using CGDB for Debugging MySQL on CentOS
This article introduces CGDB, explains how to choose the appropriate GDB version, provides step‑by‑step installation commands for both CGDB and GDB, and demonstrates practical debugging scenarios with MySQL, including attaching to processes, inspecting threads, analyzing core dumps, and adjusting runtime variables.
CGDB (Curses‑based GDB) is a text‑mode front‑end for GDB that provides a richer interface using the curses library. It requires a compatible GDB version (≥7.12) and is often used on CentOS 7.5.
Version selection : The article recommends installing GDB 9.2 because the default CentOS 7.5 GDB (7.6.1) is too old for CGDB and because GDB ≥9.0 is needed to debug OBServer.
Installing CGDB :
yum -y install automake flex texinfo ncurses-devel readline-devel gcc-c++
git clone https://github.com/cgdb/cgdb.git
cd cgdb
./autogen.sh
./configure --prefix=/usr/local
make && make installIf error: ‘for’ loop initial declarations are only allowed in C99 mode occurs, re‑run configure with CFLAGS="-std=c99" .
Installing GDB (example for version 9.2):
yum -y install gcc gcc-c++ texinfo
wget ftp://ftp.gnu.org/gnu/gdb/gdb-9.2.tar.gz
tar zxf gdb-9.2.tar.gz -C /tmp
cd /tmp/gdb-9.2
mkdir build && cd build
/tmp/gdb-9.2/configure
make && make installAfter installation, verify the GDB version and launch cgdb to start debugging.
Help commands : In GDB type help ; in CGDB type ESC :help to list commands.
Debugging examples demonstrate attaching to a MySQL mysqld process, inspecting threads, stepping through code, analyzing core dumps, using cgdb -p , and modifying MySQL runtime variables such as max_connections . The article also warns against using CGDB in production environments.
Summary : CGDB offers a convenient way to visualize GDB debugging sessions, analyze core dumps, and adjust MySQL internals, making it valuable for learning, troubleshooting, and occasional emergency fixes.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.