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: Rationale</title>
18
19<meta name="description" content="Debugging with GDB: Rationale">
20<meta name="keywords" content="Debugging with GDB: Rationale">
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="Agent-Expressions.html#Agent-Expressions" rel="up" title="Agent Expressions">
29<link href="Target-Descriptions.html#Target-Descriptions" rel="next" title="Target Descriptions">
30<link href="Varying-Target-Capabilities.html#Varying-Target-Capabilities" rel="previous" title="Varying Target Capabilities">
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="Rationale"></a>
65<div class="header">
66<p>
67Previous: <a href="Varying-Target-Capabilities.html#Varying-Target-Capabilities" accesskey="p" rel="previous">Varying Target Capabilities</a>, Up: <a href="Agent-Expressions.html#Agent-Expressions" accesskey="u" rel="up">Agent Expressions</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="Rationale-1"></a>
71<h3 class="section">F.5 Rationale</h3>
72
73<p>Some of the design decisions apparent above are arguable.
74</p>
75<dl compact="compact">
76<dt><b>What about stack overflow/underflow?</b></dt>
77<dd><p>GDB should be able to query the target to discover its stack size.
78Given that information, GDB can determine at translation time whether a
79given expression will overflow the stack.  But this spec isn&rsquo;t about
80what kinds of error-checking GDB ought to do.
81</p>
82</dd>
83<dt><b>Why are you doing everything in LONGEST?</b></dt>
84<dd>
85<p>Speed isn&rsquo;t important, but agent code size is; using LONGEST brings in a
86bunch of support code to do things like division, etc.  So this is a
87serious concern.
88</p>
89<p>First, note that you don&rsquo;t need different bytecodes for different
90operand sizes.  You can generate code without <em>knowing</em> how big the
91stack elements actually are on the target.  If the target only supports
9232-bit ints, and you don&rsquo;t send any 64-bit bytecodes, everything just
93works.  The observation here is that the MIPS and the Alpha have only
94fixed-size registers, and you can still get C&rsquo;s semantics even though
95most instructions only operate on full-sized words.  You just need to
96make sure everything is properly sign-extended at the right times.  So
97there is no need for 32- and 64-bit variants of the bytecodes.  Just
98implement everything using the largest size you support.
99</p>
100<p>GDB should certainly check to see what sizes the target supports, so the
101user can get an error earlier, rather than later.  But this information
102is not necessary for correctness.
103</p>
104
105</dd>
106<dt><b>Why don&rsquo;t you have <code>&gt;</code> or <code>&lt;=</code> operators?</b></dt>
107<dd><p>I want to keep the interpreter small, and we don&rsquo;t need them.  We can
108combine the <code>less_</code> opcodes with <code>log_not</code>, and swap the order
109of the operands, yielding all four asymmetrical comparison operators.
110For example, <code>(x &lt;= y)</code> is <code>! (x &gt; y)</code>, which is <code>! (y &lt;
111x)</code>.
112</p>
113</dd>
114<dt><b>Why do you have <code>log_not</code>?</b></dt>
115<dt><b>Why do you have <code>ext</code>?</b></dt>
116<dt><b>Why do you have <code>zero_ext</code>?</b></dt>
117<dd><p>These are all easily synthesized from other instructions, but I expect
118them to be used frequently, and they&rsquo;re simple, so I include them to
119keep bytecode strings short.
120</p>
121<p><code>log_not</code> is equivalent to <code>const8 0 equal</code>; it&rsquo;s used in half
122the relational operators.
123</p>
124<p><code>ext <var>n</var></code> is equivalent to <code>const8 <var>s-n</var> lsh const8
125<var>s-n</var> rsh_signed</code>, where <var>s</var> is the size of the stack elements;
126it follows <code>ref<var>m</var></code> and <var>reg</var> bytecodes when the value
127should be signed.  See the next bulleted item.
128</p>
129<p><code>zero_ext <var>n</var></code> is equivalent to <code>const<var>m</var> <var>mask</var>
130log_and</code>; it&rsquo;s used whenever we push the value of a register, because we
131can&rsquo;t assume the upper bits of the register aren&rsquo;t garbage.
132</p>
133</dd>
134<dt><b>Why not have sign-extending variants of the <code>ref</code> operators?</b></dt>
135<dd><p>Because that would double the number of <code>ref</code> operators, and we
136need the <code>ext</code> bytecode anyway for accessing bitfields.
137</p>
138</dd>
139<dt><b>Why not have constant-address variants of the <code>ref</code> operators?</b></dt>
140<dd><p>Because that would double the number of <code>ref</code> operators again, and
141<code>const32 <var>address</var> ref32</code> is only one byte longer.
142</p>
143</dd>
144<dt><b>Why do the <code>ref<var>n</var></code> operators have to support unaligned fetches?</b></dt>
145<dd><p>GDB will generate bytecode that fetches multi-byte values at unaligned
146addresses whenever the executable&rsquo;s debugging information tells it to.
147Furthermore, GDB does not know the value the pointer will have when GDB
148generates the bytecode, so it cannot determine whether a particular
149fetch will be aligned or not.
150</p>
151<p>In particular, structure bitfields may be several bytes long, but follow
152no alignment rules; members of packed structures are not necessarily
153aligned either.
154</p>
155<p>In general, there are many cases where unaligned references occur in
156correct C code, either at the programmer&rsquo;s explicit request, or at the
157compiler&rsquo;s discretion.  Thus, it is simpler to make the GDB agent
158bytecodes work correctly in all circumstances than to make GDB guess in
159each case whether the compiler did the usual thing.
160</p>
161</dd>
162<dt><b>Why are there no side-effecting operators?</b></dt>
163<dd><p>Because our current client doesn&rsquo;t want them?  That&rsquo;s a cheap answer.  I
164think the real answer is that I&rsquo;m afraid of implementing function
165calls.  We should re-visit this issue after the present contract is
166delivered.
167</p>
168</dd>
169<dt><b>Why aren&rsquo;t the <code>goto</code> ops PC-relative?</b></dt>
170<dd><p>The interpreter has the base address around anyway for PC bounds
171checking, and it seemed simpler.
172</p>
173</dd>
174<dt><b>Why is there only one offset size for the <code>goto</code> ops?</b></dt>
175<dd><p>Offsets are currently sixteen bits.  I&rsquo;m not happy with this situation
176either:
177</p>
178<p>Suppose we have multiple branch ops with different offset sizes.  As I
179generate code left-to-right, all my jumps are forward jumps (there are
180no loops in expressions), so I never know the target when I emit the
181jump opcode.  Thus, I have to either always assume the largest offset
182size, or do jump relaxation on the code after I generate it, which seems
183like a big waste of time.
184</p>
185<p>I can imagine a reasonable expression being longer than 256 bytes.  I
186can&rsquo;t imagine one being longer than 64k.  Thus, we need 16-bit offsets.
187This kind of reasoning is so bogus, but relaxation is pathetic.
188</p>
189<p>The other approach would be to generate code right-to-left.  Then I&rsquo;d
190always know my offset size.  That might be fun.
191</p>
192</dd>
193<dt><b>Where is the function call bytecode?</b></dt>
194<dd>
195<p>When we add side-effects, we should add this.
196</p>
197</dd>
198<dt><b>Why does the <code>reg</code> bytecode take a 16-bit register number?</b></dt>
199<dd>
200<p>Intel&rsquo;s IA-64 architecture has 128 general-purpose registers,
201and 128 floating-point registers, and I&rsquo;m sure it has some random
202control registers.
203</p>
204</dd>
205<dt><b>Why do we need <code>trace</code> and <code>trace_quick</code>?</b></dt>
206<dd><p>Because GDB needs to record all the memory contents and registers an
207expression touches.  If the user wants to evaluate an expression
208<code>x-&gt;y-&gt;z</code>, the agent must record the values of <code>x</code> and
209<code>x-&gt;y</code> as well as the value of <code>x-&gt;y-&gt;z</code>.
210</p>
211</dd>
212<dt><b>Don&rsquo;t the <code>trace</code> bytecodes make the interpreter less general?</b></dt>
213<dd><p>They do mean that the interpreter contains special-purpose code, but
214that doesn&rsquo;t mean the interpreter can only be used for that purpose.  If
215an expression doesn&rsquo;t use the <code>trace</code> bytecodes, they don&rsquo;t get in
216its way.
217</p>
218</dd>
219<dt><b>Why doesn&rsquo;t <code>trace_quick</code> consume its arguments the way everything else does?</b></dt>
220<dd><p>In general, you do want your operators to consume their arguments; it&rsquo;s
221consistent, and generally reduces the amount of stack rearrangement
222necessary.  However, <code>trace_quick</code> is a kludge to save space; it
223only exists so we needn&rsquo;t write <code>dup const8 <var>SIZE</var> trace</code>
224before every memory reference.  Therefore, it&rsquo;s okay for it not to
225consume its arguments; it&rsquo;s meant for a specific context in which we
226know exactly what it should do with the stack.  If we&rsquo;re going to have a
227kludge, it should be an effective kludge.
228</p>
229</dd>
230<dt><b>Why does <code>trace16</code> exist?</b></dt>
231<dd><p>That opcode was added by the customer that contracted Cygnus for the
232data tracing work.  I personally think it is unnecessary; objects that
233large will be quite rare, so it is okay to use <code>dup const16
234<var>size</var> trace</code> in those cases.
235</p>
236<p>Whatever we decide to do with <code>trace16</code>, we should at least leave
237opcode 0x30 reserved, to remain compatible with the customer who added
238it.
239</p>
240</dd>
241</dl>
242
243<hr>
244<div class="header">
245<p>
246Previous: <a href="Varying-Target-Capabilities.html#Varying-Target-Capabilities" accesskey="p" rel="previous">Varying Target Capabilities</a>, Up: <a href="Agent-Expressions.html#Agent-Expressions" accesskey="u" rel="up">Agent Expressions</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>
247</div>
248
249
250
251</body>
252</html>
253