Skip to main content

Posts

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 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...

Usb reset in Ubuntu (chatGpt discussions)

Query: a usb not working in my ubuntu laptop for which wired mouse not working in that drive. Any way to reset that usb without restarting ubuntu ChatGPT said: Yes, in Ubuntu you can reset a specific USB port or device without rebooting the entire system using a few different methods. Here's how you can do it safely and quickly. ✅ Step-by-Step USB Port Reset (No Reboot) Option 1: Using usbreset utility This is the cleanest way to reset a USB device without unplugging. Install usbreset (if not available): bash Copy Edit sudo apt install usbutils build-essential wget https://raw.githubusercontent.com/jkulesza/usbreset/master/usbreset.c gcc usbreset.c -o usbreset Find your USB device (e.g., mouse): bash Copy Edit lsusb Example output: arduino Copy Edit Bus 001 Device 005 : ID 046 d:c077 Logitech, Inc. M105 Optical Mouse Get the device file : bash Copy Edit ls -l /dev/bus/usb/001/005 Run usbreset : bash Copy Edit sudo ./usbreset /dev/bus/usb/001/005 Op...