Here's a practical, minimal guide for using GDB in Ubuntu terminal — from launching to setting breakpoints and navigating your code. 🧰 Step 1: Compile with Debug Symbols Use -g and disable optimizations ( -O0 preferred for debugging): bash Copy Edit g++ -g -O0 -o myprog myprog.cpp 🚀 Step 2: Launch GDB bash Copy Edit gdb ./myprog You'll see a (gdb) prompt. 🎯 Step 3: Set Breakpoints You can set breakpoints in three main ways : ✅ a. At a function gdb Copy Edit (gdb) break main ✅ b. At a specific file and line gdb Copy Edit (gdb) break myprog.cpp:42 ✅ c. At a method in a class gdb Copy Edit (gdb) break MyClass::doSomething If the symbol is mangled (C++), GDB usually demangles automatically, especially if compiled with -g . ▶️ Step 4: Run the Program gdb Copy Edit (gdb) run 🧠Step 5: Navigate Command Meaning next or n Step over current line step or s Step into function call finish Run until current function returns continue or c Continue until...
✅ Step-by-step: Build and Install GCC 15.1 on Ubuntu
⚠️ Estimated time: ~30–60 mins
✅ Works on Ubuntu 20.04 / 22.04 / 24.04
1. Install dependencies
bashsudo apt update
sudo apt install -y build-essential wget curl git \
libgmp-dev libmpfr-dev libmpc-dev libisl-dev \
flex bison libzstd-dev
2. Download GCC 15.1 source
bashcd ~/Downloads
wget https://ftp.gnu.org/gnu/gcc/gcc-15.1.0/gcc-15.1.0.tar.xz
tar -xf gcc-15.1.0.tar.xz
cd gcc-15.1.0
./contrib/download_prerequisites
This will fetch GMP, MPFR, MPC, and ISL into the source tree.
3. Create build directory
bashmkdir ../gcc-15.1-build
cd ../gcc-15.1-build
4. Configure build
bash../gcc-15.1.0/configure \
--prefix=/opt/gcc-15.1 \
--disable-multilib \
--enable-languages=c,c++,fortran \
--enable-bootstrap \
--enable-checking=release
5. Build (takes time)
bashmake -j$(nproc)
6. Install
bashsudo make install
7. Use GCC 15.1
Add it to your shell:
bashecho 'export PATH=/opt/gcc-15.1/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/gcc-15.1/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
8. Check version
bashgcc --version
Should show:
scssgcc (GCC) 15.1.0
✅ Optional: Set it system-wide (alternative)
Update update-alternatives
if you want it globally:
bashsudo update-alternatives --install /usr/bin/gcc gcc /opt/gcc-15.1/bin/gcc 1501
sudo update-alternatives --install /usr/bin/g++ g++ /opt/gcc-15.1/bin/g++ 1501
Then run:
bashsudo update-alternatives --config gcc
sudo update-alternatives --config g++
- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Comments
Post a Comment
If you have any doubts, please let me know.