Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
GNU Debugger
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Technical details== ===Features=== GDB offers extensive facilities for tracing and altering the execution of [[computer program]]s. The user can monitor and modify the values of programs' internal [[variable (programming)|variables]], and even call [[subroutine|functions]] independently of the program's normal behavior. GDB target processors (as of 2003){{needs update|date=March 2025}} include: [[DEC Alpha|Alpha]], [[ARM architecture family|ARM]], [[Atmel AVR|AVR]], [[Hitachi H8|H8/300]], Altera [[Nios (computer processor)|Nios]]/[[Nios II]], [[System/370]], [[System 390]], [[x86]] and its 64-bit extension [[x86-64]], [[Itanium|IA-64]] "Itanium", [[Motorola 68000]], [[MIPS architecture|MIPS]], [[PA-RISC]], [[PowerPC]], [[RISC-V]], [[SuperH]], [[SPARC]], and [[VAX]]. Lesser-known target processors supported in the standard release have included [[A29K]], [[ARC (processor)|ARC]], [[ETRAX CRIS]], [[D10V]], [[D30V]], [[FR-30]], [[FR-V]], [[Intel i960]], [[Motorola 68HC11|68HC11]], [[Motorola 88000]], [[MCORE]], [[MN10200]], [[MN10300]], [[320xx microprocessor|NS32K]], [[Stormy16]], and [[Zilog Z8000|Z8000]]. (Newer releases will likely not support some of these.) GDB has compiled-in [[Instruction set simulator|simulators]] for even lesser-known target processors such like [[M32R]] or [[V850]].<ref>{{cite web | title = GDB Documentation - Summary - Contributors | url = http://sourceware.org/gdb/current/onlinedocs/gdb/Contributors.html#Contributors | access-date = 2011-12-01 | archive-date = 2011-09-29 | archive-url = https://web.archive.org/web/20110929153415/http://sourceware.org/gdb/current/onlinedocs/gdb/Contributors.html#Contributors | url-status = dead }}</ref> GDB is still actively being developed. As of version 7.0 new features include support for [[Python (programming language)|Python]] scripting<ref>{{cite web | title = GDB 7.0 Release Notes | url = http://sourceware.org/gdb/wiki/GDB_7.0_Release | access-date = 2011-11-28 }}</ref> and as of version 7.8 [[GNU Guile]] scripting as well.<ref>{{cite web |url=https://sourceware.org/ml/gdb/2014-07/msg00032.html |title=GDB 7.8 released! |author=Joel Brobecker |date=2014-07-29 |access-date=2014-07-30}}</ref> Since version 7.0, support for "reversible debugging" β allowing a debugging session to step backward, much like rewinding a crashed program to see what happened β is available.<ref>{{cite web | title = Reverse Debugging with GDB | url = https://www.gnu.org/software/gdb/news/reversible.html | access-date = 2014-01-20 }}</ref> ===Remote debugging=== GDB offers a "remote" mode often used when debugging embedded systems. Remote operation is when GDB runs on one machine and the program being debugged runs on another. GDB can communicate to the remote "stub" that understands GDB protocol through a serial device or TCP/IP.<ref>{{cite web|url=http://www.embecosm.com/appnotes/ean4/embecosm-howto-rsp-server-ean4-issue-2.pdf|title=Howto: GDB Remote Serial Protocol: Writing a RSP Server}}</ref> A stub program can be created by linking to the appropriate stub files provided with GDB, which implement the target side of the communication protocol.<ref>{{cite web|url=http://davis.lbl.gov/Manuals/GDB/gdb_17.html#SEC140|title=Implementing a remote stub}}</ref> Alternatively, [[gdbserver]] can be used to remotely debug the program without needing to change it in any way. The same mode is also used by [[KGDB]] for debugging a running [[Linux kernel]] on the source level with gdb. With KGDB, kernel developers can debug a kernel in much the same way as they debug application programs. It makes it possible to place breakpoints in kernel code, step through the code, and observe variables. On architectures where hardware debugging registers are available, watchpoints can be set which trigger breakpoints when specified memory addresses are executed or accessed. KGDB requires an additional machine which is connected to the machine to be debugged using a [[serial cable]] or [[Ethernet]]. On [[FreeBSD]], it is also possible to debug using [[FireWire]] [[direct memory access]] (DMA).<ref>{{cite web|url=http://www.freebsd.org/doc/en/books/developers-handbook/kerneldebug-dcons.html|title=Kernel debugging with Dcons}}</ref> ===Graphical user interface=== The debugger does not contain its own [[graphical user interface]], and defaults to a [[command-line interface]], although it does contain a [[Text User Interface|text user interface]]. Several front-ends have been built for it, such as [[UltraGDB]], [[Xxgdb]], [[Data Display Debugger]] (DDD), Nemiver, [[KDbg]], the [[Xcode]] debugger, GDBtk/Insight, Gede [https://gede.dexar.se/], Seer [https://github.com/epasveer/seer], and HP Wildebeest Debugger GUI (WDB GUI). [[Integrated development environment|IDE]]s such as [[Codelite]], [[Code::Blocks]], [[Dev-C++]], [[Geany]], GNAT Programming Studio (GPS), [[KDevelop]], [[Qt Creator]], [[Lazarus (IDE)|Lazarus]], [[MonoDevelop]], [[List of Eclipse projects#Tools projects|Eclipse]], [[NetBeans]], and [[Visual Studio]] can interface with GDB. [[GNU Emacs]] has a "GUD mode" and tools for [[Vim (text editor)|Vim]] exist (e.g. clewn). These offer facilities similar to debuggers found in IDEs. Some other debugging tools have been designed to work with GDB, such as [[memory leak]] detectors. ===Internals === GDB uses a system call named [[ptrace]] (the name is an abbreviation of "process trace") to observe and control the execution of another process, and examine and change the process' memory and registers. {{aligned table|class=wikitable|cols=2|col1header=y|col1align=left|row1header=y | Common gdb commands | Corresponding ptrace calls | <syntaxhighlight lang="console" inline>(gdb) start</syntaxhighlight> | {{mono|PTRACE_TRACEME}} β makes parent a tracer (called by a tracee) | <syntaxhighlight lang="console" inline>(gdb) attach PID</syntaxhighlight> | {{mono|PTRACE_ATTACH}} β attach to a running process | <syntaxhighlight lang="console" inline>(gdb) stop</syntaxhighlight> | {{code|kill(child_pid, SIGSTOP)}} (or {{mono|PTRACE_INTERRUPT}}) | <syntaxhighlight lang="console" inline>(gdb) continue</syntaxhighlight> | {{mono|PTRACE_CONT}} | <syntaxhighlight lang="console" inline>(gdb) info registers</syntaxhighlight> | {{mono|PTRACE_GET(FP)REGS(ET)}} and {{mono|PTRACE_SET(FP)REGS(ET)}} | <syntaxhighlight lang="console" inline>(gdb) x</syntaxhighlight> | {{mono|PTRACE_PEEKTEXT}} and {{mono|PTRACE_POKETEXT}} }} A breakpoint is implemented by replacing an instruction at a given memory address with another special instruction. Executing breakpoint instruction causes SIGTRAP.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)