1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc.
4
5Permission is granted to copy, distribute and/or modify this document
6under the terms of the GNU Free Documentation License, Version 1.3 or
7any later version published by the Free Software Foundation; with the
8Invariant Sections being "Free Software" and "Free Software Needs
9Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
10and with the Back-Cover Texts as in (a) below.
11
12(a) The FSF's Back-Cover Text is: "You are free to copy and modify
13this GNU Manual.  Buying copies from GNU Press supports the FSF in
14developing GNU and promoting software freedom." -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>Debugging with GDB: Agent Expressions</title>
18
19<meta name="description" content="Debugging with GDB: Agent Expressions">
20<meta name="keywords" content="Debugging with GDB: Agent Expressions">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="index.html#Top" rel="up" title="Top">
29<link href="General-Bytecode-Design.html#General-Bytecode-Design" rel="next" title="General Bytecode Design">
30<link href="Branch-Trace-Configuration-Format.html#Branch-Trace-Configuration-Format" rel="previous" title="Branch Trace Configuration Format">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="Agent-Expressions"></a>
65<div class="header">
66<p>
67Next: <a href="Target-Descriptions.html#Target-Descriptions" accesskey="n" rel="next">Target Descriptions</a>, Previous: <a href="Remote-Protocol.html#Remote-Protocol" accesskey="p" rel="previous">Remote Protocol</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
68</div>
69<hr>
70<a name="The-GDB-Agent-Expression-Mechanism"></a>
71<h2 class="appendix">Appendix F The GDB Agent Expression Mechanism</h2>
72
73<p>In some applications, it is not feasible for the debugger to interrupt
74the program&rsquo;s execution long enough for the developer to learn anything
75helpful about its behavior.  If the program&rsquo;s correctness depends on its
76real-time behavior, delays introduced by a debugger might cause the
77program to fail, even when the code itself is correct.  It is useful to
78be able to observe the program&rsquo;s behavior without interrupting it.
79</p>
80<p>Using GDB&rsquo;s <code>trace</code> and <code>collect</code> commands, the user can
81specify locations in the program, and arbitrary expressions to evaluate
82when those locations are reached.  Later, using the <code>tfind</code>
83command, she can examine the values those expressions had when the
84program hit the trace points.  The expressions may also denote objects
85in memory &mdash; structures or arrays, for example &mdash; whose values GDB
86should record; while visiting a particular tracepoint, the user may
87inspect those objects as if they were in memory at that moment.
88However, because GDB records these values without interacting with the
89user, it can do so quickly and unobtrusively, hopefully not disturbing
90the program&rsquo;s behavior.
91</p>
92<p>When GDB is debugging a remote target, the GDB <em>agent</em> code running
93on the target computes the values of the expressions itself.  To avoid
94having a full symbolic expression evaluator on the agent, GDB translates
95expressions in the source language into a simpler bytecode language, and
96then sends the bytecode to the agent; the agent then executes the
97bytecode, and records the values for GDB to retrieve later.
98</p>
99<p>The bytecode language is simple; there are forty-odd opcodes, the bulk
100of which are the usual vocabulary of C operands (addition, subtraction,
101shifts, and so on) and various sizes of literals and memory reference
102operations.  The bytecode interpreter operates strictly on machine-level
103values &mdash; various sizes of integers and floating point numbers &mdash; and
104requires no information about types or symbols; thus, the interpreter&rsquo;s
105internal data structures are simple, and each bytecode requires only a
106few native machine instructions to implement it.  The interpreter is
107small, and strict limits on the memory and time required to evaluate an
108expression are easy to determine, making it suitable for use by the
109debugging agent in real-time applications.
110</p>
111<table class="menu" border="0" cellspacing="0">
112<tr><td align="left" valign="top">&bull; <a href="General-Bytecode-Design.html#General-Bytecode-Design" accesskey="1">General Bytecode Design</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Overview of the interpreter.
113</td></tr>
114<tr><td align="left" valign="top">&bull; <a href="Bytecode-Descriptions.html#Bytecode-Descriptions" accesskey="2">Bytecode Descriptions</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">What each one does.
115</td></tr>
116<tr><td align="left" valign="top">&bull; <a href="Using-Agent-Expressions.html#Using-Agent-Expressions" accesskey="3">Using Agent Expressions</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How agent expressions fit into the big picture.
117</td></tr>
118<tr><td align="left" valign="top">&bull; <a href="Varying-Target-Capabilities.html#Varying-Target-Capabilities" accesskey="4">Varying Target Capabilities</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How to discover what the target can do.
119</td></tr>
120<tr><td align="left" valign="top">&bull; <a href="Rationale.html#Rationale" accesskey="5">Rationale</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Why we did it this way.
121</td></tr>
122</table>
123
124
125
126
127<hr>
128<div class="header">
129<p>
130Next: <a href="Target-Descriptions.html#Target-Descriptions" accesskey="n" rel="next">Target Descriptions</a>, Previous: <a href="Remote-Protocol.html#Remote-Protocol" accesskey="p" rel="previous">Remote Protocol</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
131</div>
132
133
134
135</body>
136</html>
137