
Appendix E.
The GDB Agent Expression Mechanism
In some applications, it is not feasable for the debugger to interrupt the program’s execution long
enough for the developer to learn anything helpful about its behavior. If the program’s correctness
depends on its real-time behavior, delays introduced by a debugger might cause the program to fail,
even when the code itself is correct. It is useful to be able to observe the program’s behavior without
interrupting it.
Using GDB’s
trace
and
collect
commands, the user can specify locations in the program, and
arbitrary expressions to evaluate when those locations are reached. Later, using the
tfind
command,
she can examine the values those expressions had when the program hit the trace points. The expres-
sions may also denote objects in memory -- structures or arrays, for example -- whose values GDB
should record; while visiting a particular tracepoint, the user may inspect those objects as if they were
in memory at that moment. However, because GDB records these values without interacting with the
user, it can do so quickly and unobtrusively, hopefully not disturbing the program’s behavior.
When GDB is debugging a remote target, the GDB
agent
code running on the target computes the
values of the expressions itself. To avoid having a full symbolic expression evaluator on the agent,
GDB translates expressions in the source language into a simpler bytecode language, and then sends
the bytecode to the agent; the agent then executes the bytecode, and records the values for GDB to
retrieve later.
The bytecode language is simple; there are forty-odd opcodes, the bulk of which are the usual vocab-
ulary of C operands (addition, subtraction, shifts, and so on) and various sizes of literals and memory
reference operations. The bytecode interpreter operates strictly on machine-level values -- various
sizes of integers and floating point numbers -- and requires no information about types or symbols;
thus, the interpreter’s internal data structures are simple, and each bytecode requires only a few na-
tive machine instructions to implement it. The interpreter is small, and strict limits on the memory
and time required to evaluate an expression are easy to determine, making it suitable for use by the
debugging agent in real-time applications.
E.1. General Bytecode Design
The agent represents bytecode expressions as an array of bytes. Each instruction is one byte long
(thus the term
bytecode
). Some instructions are followed by operand bytes; for example, the
goto
instruction is followed by a destination for the jump.
The bytecode interpreter is a stack-based machine; most instructions pop their operands off the stack,
perform some operation, and push the result back on the stack for the next instruction to consume.
Each element of the stack may contain either a integer or a floating point value; these values are as
many bits wide as the largest integer that can be directly manipulated in the source language. Stack
elements carry no record of their type; bytecode could push a value as an integer, then pop it as a
floating point value. However, GDB will not generate code which does this. In C, one might define
the type of a stack element as follows:
union agent_val {
LONGEST l;
DOUBLEST d;
};
where
LONGEST
and
DOUBLEST
are
typedef
names for the largest integer and floating point types on
the machine.
Summary of Contents for ENTERPRISE LINUX 3 - SECURITY GUIDE
Page 1: ...Red Hat Enterprise Linux 3 Debugging with gdb ...
Page 12: ...2 Chapter 1 Debugging with gdb ...
Page 28: ...18 Chapter 4 Getting In and Out of gdb ...
Page 34: ...24 Chapter 5 gdb Commands ...
Page 44: ...34 Chapter 6 Running Programs Under gdb ...
Page 68: ...58 Chapter 8 Examining the Stack ...
Page 98: ...88 Chapter 10 Examining Data ...
Page 112: ...102 Chapter 12 Tracepoints ...
Page 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Page 138: ...128 Chapter 14 Using gdb with Different Languages ...
Page 144: ...134 Chapter 15 Examining the Symbol Table ...
Page 170: ...160 Chapter 19 Debugging remote programs ...
Page 198: ...188 Chapter 21 Controlling gdb ...
Page 204: ...194 Chapter 22 Canned Sequences of Commands ...
Page 206: ...196 Chapter 23 Command Interpreters ...
Page 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Page 296: ...286 Chapter 27 gdb Annotations ...
Page 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Page 322: ...312 Chapter 30 Using History Interactively ...
Page 362: ...352 Appendix D gdb Remote Serial Protocol ...
Page 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Page 386: ...376 Appendix G GNU Free Documentation License ...
Page 410: ......