| 1 | \chapter{GNU Debugger} \label{GDB}
 | 
|---|
| 2 | 
 | 
|---|
| 3 | \section{Introduction}
 | 
|---|
| 4 | The GNU Project Debugger is a program that allows examination of what is going on
 | 
|---|
| 5 | inside another program while it executes, or examines the state of a program
 | 
|---|
| 6 | after it crashed \cite{Reference3}.
 | 
|---|
| 7 | 
 | 
|---|
| 8 | \section{Debug Information}
 | 
|---|
| 9 | In order to allow effective inspection of program state, the
 | 
|---|
| 10 | debugger requires debugging information for a program. Debugging
 | 
|---|
| 11 | information is a collection of data generated by a compiler and/or an assembler
 | 
|---|
| 12 | program. This information is optional as it is only required for compilation,
 | 
|---|
| 13 | and hence, it is normally not present during program execution when debugging
 | 
|---|
| 14 | occurs. When requested, debugging information is stored in an object file, and it describes
 | 
|---|
| 15 | information such as the type of each variable or function and
 | 
|---|
| 16 | the correspondence between source line numbers and addresses in the executable
 | 
|---|
| 17 | code \cite{Reference6}. Debugging information is requested via the \verb|-g|
 | 
|---|
| 18 | flag during the compilation stage of the
 | 
|---|
| 19 | program.
 | 
|---|
| 20 | 
 | 
|---|
| 21 | The debugging information must be written out in a canonical format for
 | 
|---|
| 22 | debuggers to read. DWARF is one of the supported debugging data formats, and its architecture is
 | 
|---|
| 23 | independent and applicable to any language, operating system, or processor \cite{Reference7}. This format uses a data structure called DIE to represent
 | 
|---|
| 24 | each variable, type, function, etc. A DIE is a pair: tag
 | 
|---|
| 25 | and its attribute \cite{Reference8}.
 | 
|---|
| 26 | 
 | 
|---|
| 27 | \section{Stack-Frame Information}
 | 
|---|
| 28 | A stack frame, or frame for short, is a collection of all data associated with
 | 
|---|
| 29 | one function call. A frame consists of parameters received from the function call, local variables declared in that
 | 
|---|
| 30 | function, and the address where the
 | 
|---|
| 31 | function returns. The frame-pointer register stores the address of a frame,
 | 
|---|
| 32 | during execution of a call. A call stack can have many frames \cite{Reference12}.
 | 
|---|
| 33 | 
 | 
|---|
| 34 | \section{Extending GDB}
 | 
|---|
| 35 | GDB provides three mechanisms for extending itself. The first is
 | 
|---|
| 36 | composition 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}
 | 
|---|
| 39 | Symbols are a key part of GDB's operation. Symbols can be variables, functions and
 | 
|---|
| 40 | types. 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 | 
 | 
|---|
| 50 | Debugging information for a large program can be very large, and reading all of
 | 
|---|
| 51 | these symbols can be a performance bottleneck in GDB, affecting the user
 | 
|---|
| 52 | experience. The solution is to lazily construct partial symbol-tables consisting of
 | 
|---|
| 53 | only selected symbols, and then eagerly expand them to full symbol-tables when
 | 
|---|
| 54 | necessary.
 | 
|---|
| 55 | The psymtabs is constructed by doing a quick pass over the executable file's
 | 
|---|
| 56 | debugging information.
 | 
|---|
| 57 | 
 | 
|---|
| 58 | \section{Name Demangling in GDB}
 | 
|---|
| 59 | The library \verb|libiberty| provides many functions and features that can be
 | 
|---|
| 60 | divided 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 | 
 | 
|---|
| 70 | In particular, this library provides the \CC demangler that is used in GDB and
 | 
|---|
| 71 | by \uC. A new
 | 
|---|
| 72 | demangler can also be added in this library, which is what Rust did, and what
 | 
|---|
| 73 | is necessary for \CFA.
 | 
|---|