How to use gdb in Ubuntu Terminal

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
g++ -g -O0 -o myprog myprog.cpp

🚀 Step 2: Launch GDB

bash
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
(gdb) break main

✅ b. At a specific file and line

gdb
(gdb) break myprog.cpp:42

✅ c. At a method in a class

gdb
(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
(gdb) run

🧭 Step 5: Navigate

CommandMeaning
next or nStep over current line
step or sStep into function call
finishRun until current function returns
continue or cContinue until next breakpoint
listShow source code around current line
info localsShow all local variables
print xPrint variable x

⛏️ Step 6: Manage Breakpoints

List breakpoints:

gdb
(gdb) info breakpoints

Delete a breakpoint:

gdb
(gdb) delete <number>

Disable/Enable breakpoint temporarily:

gdb
(gdb) disable <number> (gdb) enable <number>

🧪 Example Session

bash
g++ -g -O0 -o test test.cpp gdb ./test
gdb
(gdb) break main (gdb) break test.cpp:18 (gdb) run (gdb) next (gdb) print myVar (gdb) continue

🧠 Pro Tips

  • Press <TAB> for autocompletion.

  • Use layout src in GDB to get a TUI (text UI).

  • quit to exit.


🪟 Bonus: GDB Text UI Mode

In GDB:

gdb
(gdb) layout src

→ Shows source code window with current line highlighted. Use arrow keys or n, s, etc.


Let me know if you'd like:

  • Watchpoints (for memory change)

  • Debugging core dumps

  • Pretty printing with gdbinit

  • Automating GDB session with scripts

Install gcc 15.1 using spack in Ubuntu (chatGpt Reply)

git clone https://github.com/spack/spack.git ~/spack
. ~/spack/share/spack/setup-env.sh
spack install [email protected]

Install gcc-15.1 form source in Ubuntu (chatGpt reply)

✅ 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

bash
sudo 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

bash
cd ~/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

bash
mkdir ../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)

bash
make -j$(nproc)

6. Install

bash
sudo make install

7. Use GCC 15.1

Add it to your shell:

bash
echo '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

bash
gcc --version

Should show:

scss
gcc (GCC) 15.1.0

✅ Optional: Set it system-wide (alternative)

Update update-alternatives if you want it globally:

bash
sudo 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:

bash
sudo update-alternatives --config gcc sudo update-alternatives --config g++

Regarding site Free Browser Tool (https://free-browser-tools.mohitkrgupta.dev) (discussion with google search AI)

Various discussions with Google Search AI regarding site  Free Browser Tool are as below: site free-browser-tools.mohitkrgupta.dev what doe...