Debugging
lastmod 2025-03-08created 2017-01-3027 edits
Debug (debug), debugging (debugging), or fixing refers to the testing process of finding errors in the correctness or logic (bugs) of a computer program. It is also called debugging (debugging) or fixing. Common debugging methods include checks during testing, testing with machines, and testing with real data.
Binary Tools
- [Recommended] Understanding what a Linux binary is doing 1
- [Recommended] UNIX as IDE: 6. Debugging (strace, ltrace)
A set of tools for binary debugging:
- strings
- file
- objdump
- strace - monitors system commands
- ltrace - monitors library calls
- gdb
- sysdig
- ldd
- size
- readelf
- nm
- pmap - view memory allocation details
GUI Disassembler
Tip/Trick
Python gdb debugging
Finding the crash location
- Debugging tip: finding where a program crashes on Linux
- (gdb) The GNU Debugger : 3. Analyzing Stack information
Find the address where the crash occurred, then use addr2line to locate it.
Example:
Segfault debugging
- How to get a core dump for a segfault on Linux
- (basics only) How to find Segmentation Error in C & C++ ? (Using GDB)
- (basics only) 7.2 Example Debugging Session: Segmentation Fault Example
-
Obtaining a stack trace in C upon SIGSEGV(Chinese site, good content. Refer to the PDF if possible: Obtaining_a_stack_trace_in_C_upon_SIGSEGV.pdf) - How to debug a GCC segmentation fault - GNU Project - Free Software Foundation (FSF)
Configure GCC with --enable-checking. Compile it with -g -O0 so that you can use gdb.
Compile your test case with -v -da -Q.
-
-Q: will show which function in the test case is causing it to crash. -
-v: shows how cc1 was invoked (useful for invoking cc1 manually in gdb). -
-da: dumps the RTL to a file after each stage.
Next, use gdb to get a stack trace:
Print out the values of interesting variables, e.g., the ones in the statement which got the segmentation fault. You can use the pt and pr macros from the gdbinit.in file to display GCC data. For example, if there is a value of type tree named t, and a value of type rtx named r, you can use these commands:
See also
- Valgrind
- memwatch
- YAMD
- rmdebug
- Dmalloc
- mtrace
- Breakpoint
- addr2line
- gdb
- lldb
- DebugView
- CodeTracer - a time-traveling debugger written in Nim and Rust
Favorite site
Tip & Guide
- How to debug when a segmentation fault occurs
- Debugging when a Segmentation Fault occurs
- Debugging tip: finding where a program crashes on Linux
- How to debug with the address when a Segmentation fault occurs
- Introducing GEF – GDB Enhanced Features
- Linux Exploits made easy – using the peda debugger
- Debugging B2G using GDB and related Tools
MSVC
Guide
- Implementing backtrace through stack walking 2
- Tools for dynamically tracing programs 3
- Friends for memory debugging 4