source: doc/theses/lynn_tran_SE499/Chapters/GDB.tex @ b965774

Last change on this file since b965774 was 1b34b87, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

Lynn's GDB essay

  • Property mode set to 100644
File size: 3.8 KB
Line 
1\chapter{GNU Debugger} \label{GDB}
2
3\section{Introduction}
4The GNU Project Debugger is a program that allows examination of what is going on
5inside another program while it executes, or examines the state of a program
6after it crashed \cite{Reference3}.
7
8\section{Debug Information}
9In order to allow effective inspection of program state, the
10debugger requires debugging information for a program. Debugging
11information is a collection of data generated by a compiler and/or an assembler
12program. This information is optional as it is only required for compilation,
13and hence, it is normally not present during program execution when debugging
14occurs. When requested, debugging information is stored in an object file, and it describes
15information such as the type of each variable or function and
16the correspondence between source line numbers and addresses in the executable
17code \cite{Reference6}. Debugging information is requested via the \verb|-g|
18flag during the compilation stage of the
19program.
20
21The debugging information must be written out in a canonical format for
22debuggers to read. DWARF is one of the supported debugging data formats, and its architecture is
23independent and applicable to any language, operating system, or processor \cite{Reference7}. This format uses a data structure called DIE to represent
24each variable, type, function, etc. A DIE is a pair: tag
25and its attribute \cite{Reference8}.
26
27\section{Stack-Frame Information}
28A stack frame, or frame for short, is a collection of all data associated with
29one function call. A frame consists of parameters received from the function call, local variables declared in that
30function, and the address where the
31function returns. The frame-pointer register stores the address of a frame,
32during execution of a call. A call stack can have many frames \cite{Reference12}.
33
34\section{Extending GDB}
35GDB provides three mechanisms for extending itself. The first is
36composition of GDB commands, the second is using the Python GDB API, and the third is defining new aliases for existing commands.
37
38\section{Symbol Handling}
39Symbols are a key part of GDB's operation. Symbols can be variables, functions and
40types. GDB has three kinds of symbol tables:
41\begin{itemize}
42    \item \textcolor{ForestGreen}{Full symbol-tables (symtabs)}: These contain the main information
43        about symbols and addresses
44    \item \textcolor{ForestGreen} {Partial symbol-tables (psymtabs)}: These contain enough information to
45        know when to read the corresponding part of the full symbol-table.
46    \item \textcolor{ForestGreen}{Minimal symbol-tables (msymtabs)}: These
47        contain information extracted from non-debugging symbols.
48\end{itemize}
49
50Debugging information for a large program can be very large, and reading all of
51these symbols can be a performance bottleneck in GDB, affecting the user
52experience. The solution is to lazily construct partial symbol-tables consisting of
53only selected symbols, and then eagerly expand them to full symbol-tables when
54necessary.
55The psymtabs is constructed by doing a quick pass over the executable file's
56debugging information.
57
58\section{Name Demangling in GDB}
59The library \verb|libiberty| provides many functions and features that can be
60divided into three groups:
61\begin{itemize}
62    \item \textcolor{ForestGreen}{Supplemental functions}: additional functions
63        that may be missing in
64        the underlying operating system.
65    \item \textcolor{ForestGreen}{Replacement functions}: simple and unified equivalent functions for
66        commonly used standard functions.
67    \item \textcolor{ForestGreen}{Extensions}: additional functions beyond the standard.
68\end{itemize}
69
70In particular, this library provides the \CC demangler that is used in GDB and
71by \uC. A new
72demangler can also be added in this library, which is what Rust did, and what
73is necessary for \CFA.
Note: See TracBrowser for help on using the repository browser.