Misc corrections Chpt 6 thru App A
[dwarf-doc.git] / dwarf5 / latexdoc / examples.tex
1 \chapter{Examples (Informative)}
2 \label{app:examplesinformative}
3
4 The following sections provide examples that illustrate
5 various aspects of the DWARF debugging information format.
6
7
8
9 \section{ Compilation Units and Abbreviations Table Example}
10 \label{app:compilationunitsandabbreviationstableexample}
11
12
13 Figure \refersec{fig:compilationunitsandabbreviationstable}
14 depicts the relationship of the abbreviations tables contained
15 \addtoindexx{abbreviations table!example}
16 \addtoindexx{.debug\_abbrev example}
17 \addtoindexx{.debug\_info example}
18 in the \addtoindex{.debug\_abbrev}
19 section to the information contained in
20 the \addtoindex{.debug\_info}
21 section. Values are given in symbolic form,
22 where possible.
23
24 The figure corresponds to the following two trivial source files:
25
26 File myfile.c
27 \begin{lstlisting}
28 typedef char* POINTER;
29 \end{lstlisting}
30 File myfile2.c
31 \begin{lstlisting}
32 typedef char* strp;
33 \end{lstlisting}
34
35 % Ensures we get the following float out before we go on.
36 \clearpage
37 \begin{figure}[here]
38 %\centering
39 \begin{minipage}{0.4\textwidth}
40 \centering
41 Compilation Unit 1: \addtoindex{.debug\_info}
42 \begin{framed}
43 \scriptsize
44 \begin{alltt}
45 \textit{length}
46 4
47 \textit{a1 (abbreviations table offset)}
48 4
49 \vspace{0.01cm}
50 \hrule
51 1
52 "myfile.c"
53 "Best Compiler Corp: Version 1.3"
54 "/home/mydir/src"
55 \livelink{chap:DWLANGC89}{DW\-\_LANG\-\_C89}
56 0x0
57 0x55
58 \livelink{chap:DWFORMsecoffset}{DW\-\_FORM\-\_sec\-\_offset}
59 0x0
60 \vspace{0.01cm}
61 \hrule
62 2
63 “char”
64 \livelink{chap:DWATEunsignedchar}{DW\-\_ATE\-\_unsigned\-\_char}
65 1
66 \vspace{0.01cm}
67 \hrule
68 3
69 e1
70 \vspace{0.01cm}
71 \hrule
72 4
73 “POINTER”
74 e2
75 \vspace{0.01cm}
76 \hrule
77 0
78 \end{alltt}
79 %
80 %
81 \end{framed}
82 Compilation Unit 2: \addtoindex{.debug\_info}
83 \begin{framed}
84 \scriptsize
85 \begin{alltt}
86 \textit{length}
87 4
88 \textit{a1 (abbreviations table offset)}
89 4
90 \vspace{0.01cm}
91 \hrule
92 ...
93 \vspace{0.01cm}
94 \hrule
95 4
96 “strp”
97 e2
98 \vspace{0.01cm}
99 \hrule
100 ...
101 \end{alltt}
102 %
103 %
104 \end{framed}
105 \end{minipage}
106 \hfill
107 \begin{minipage}{0.4\textwidth}
108 \centering
109 Abbreviation Table: \addtoindex{.debug\_abbrev}
110 \begin{framed}
111 \scriptsize
112 \begin{alltt}
113 \livelink{chap:DWTAGcompileunit}{DW\-\_TAG\-\_compile\-\_unit}
114 \livelink{chap:DWCHILDRENyes}{DW\-\_CHILDREN\-\_yes}
115 \livelink{chap:DWATname}{DW\-\_AT\-\_name}       \livelink{chap:DWFORMstring}{DW\-\_FORM\-\_string}
116 \livelink{chap:DWATproducer}{DW\-\_AT\-\_producer}   \livelink{chap:DWFORMstring}{DW\-\_FORM\-\_string}
117 \livelink{chap:DWATcompdir}{DW\-\_AT\-\_comp\-\_dir}   \livelink{chap:DWFORMstring}{DW\-\_FORM\-\_string}
118 \livelink{chap:DWATlanguage}{DW\-\_AT\-\_language}   \livelink{chap:DWFORMdata1}{DW\-\_FORM\-\_data1}
119 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}     \livelink{chap:DWFORMaddr}{DW\-\_FORM\-\_addr}
120 \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}    \livelink{chap:DWFORMdata1}{DW\-\_FORM\-\_data1}
121 \livelink{chap:DWATstmtlist}{DW\-\_AT\-\_stmt\-\_list}  \livelink{chap:DWFORMindirect}{DW\-\_FORM\-\_indirect}
122 0                  0
123 \vspace{0.01cm}
124 \hrule
125 2
126 \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
127 \livelink{chap:DWCHILDRENno}{DW\-\_CHILDREN\-\_no}
128 \livelink{chap:DWATname}{DW\-\_AT\-\_name}       \livelink{chap:DWFORMstring}{DW\-\_FORM\-\_string}
129 \livelink{chap:DWATencoding}{DW\-\_AT\-\_encoding}   \livelink{chap:DWFORMdata1}{DW\-\_FORM\-\_data1}
130 \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}  \livelink{chap:DWFORMdata1}{DW\-\_FORM\-\_data1}
131 0
132 \vspace{0.01cm}
133 \hrule
134 3
135 \livelink{chap:DWTAGpointertype}{DW\-\_TAG\-\_pointer\-\_type}
136 \livelink{chap:DWCHILDRENno}{DW\-\_CHILDREN\-\_no}
137 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}       \livelink{chap:DWFORMref4}{DW\-\_FORM\-\_ref4}
138 0
139 \vspace{0.01cm}
140 \hrule
141 4
142 \livelink{chap:DWTAGtypedef}{DW\-\_TAG\-\_typedef}
143 \livelink{chap:DWCHILDRENno}{DW\-\_CHILDREN\-\_no}
144 \livelink{chap:DWATname}{DW\-\_AT\-\_name}      \livelink{chap:DWFORMstring}{DW\-\_FORM\-\_string}
145 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}      \livelink{chap:DWFORMrefaddr}{DW\-\_FORM\-\_ref\-\_addr}
146 0
147 \vspace{0.01cm}
148 \hrule
149 0
150 \end{alltt}
151 \end{framed}
152 \end{minipage}
153 \caption{Compilation units and abbreviations table} \label{fig:compilationunitsandabbreviationstable}
154 \end{figure}
155
156 % Ensures we get the above float out before we go on.
157 \clearpage
158
159 \section{Aggregate Examples}
160 \label{app:aggregateexamples}
161
162 The following examples illustrate how to represent some of
163 the more complicated forms of array and record aggregates
164 using DWARF.
165
166 \subsection{Fortran 90 Example}
167 \label{app:fortran90example}
168 Consider the \addtoindex{Fortran 90} source fragment in 
169 \addtoindexx{array type entry!examples}
170 Figure \referfol{fig:fortran90examplesourcefragment}.
171
172 \begin{figure}[here]
173 \begin{lstlisting}
174 type array_ptr
175 real :: myvar
176 real, dimension (:), pointer :: ap
177 end type array_ptr
178 type(array_ptr), allocatable, dimension(:) :: arrays
179 allocate(arrays(20))
180 do i = 1, 20
181 allocate(arrays(i)%ap(i+10))
182 end do
183 \end{lstlisting}
184 \caption{Fortran 90 example: source fragment} \label{fig:fortran90examplesourcefragment}
185 \end{figure}
186
187 For allocatable and pointer arrays, it is essentially required
188 by the \addtoindex{Fortran 90} semantics that each array consist of 
189 \addtoindexx{descriptor!array}
190 two
191 \addtoindexx{array!descriptor for}
192 parts, which we here call 1) the descriptor and 2) the raw
193 data. (A descriptor has often been called a dope vector in
194 other contexts, although it is often a structure of some kind
195 rather than a simple vector.) Because there are two parts,
196 and because the lifetime of the descriptor is necessarily
197 longer than and includes that of the raw data, there must be
198 an address somewhere in the descriptor that points to the
199 raw data when, in fact, there is some (that is, when 
200 the ``variable'' is allocated or associated).
201
202 For concreteness, suppose that a descriptor looks something
203 like the C structure in 
204 Figure \referfol{fig:fortran90exampledescriptorrepresentation}.
205 Note, however, that it is
206 a property of the design that 1) a debugger needs no builtin
207 knowledge of this structure and 2) there does not need to
208 be an explicit representation of this structure in the DWARF
209 input to the 
210 \addtoindexx{Fortran 90}
211 debugger.
212
213 \begin{figure}[here]
214 \begin{lstlisting}
215 struct desc {
216     long el_len; // Element length
217     void * base; // Address of raw data
218     int ptr_assoc : 1; // Pointer is associated flag
219     int ptr_alloc : 1; // Pointer is allocated flag
220     int num_dims : 6; // Number of dimensions
221     struct dims_str { // For each dimension...  
222         long low_bound;
223         long upper_bound;
224         long stride;
225     } dims[63];
226 };
227 \end{lstlisting}
228 \caption{Fortran 90 example: descriptor representation}
229 \label{fig:fortran90exampledescriptorrepresentation}
230 \end{figure}
231
232
233 In practice, of course, a “real” descriptor will have
234 dimension substructures only for as many dimensions as are
235 specified in the num\_dims component. Let us use the notation
236 desc ,textless n \textgreater\   
237 to indicate a specialization of the desc struct in
238 which n is the bound for the dims component as well as the
239 contents of the num\_dims component.
240
241 Because the arrays considered here come in two parts, it is
242 necessary to distinguish the parts carefully. In particular,
243 the “address of the variable” or equivalently, the “base
244 address of the object” always refers to the descriptor. For
245 arrays that do not come in two parts, an implementation can
246 provide a descriptor anyway, thereby giving it two parts. (This
247 may be convenient for general runtime support unrelated to
248 debugging.) In this case the above vocabulary applies as
249 stated. Alternatively, an implementation can do without a
250 descriptor, in which case the “address of the variable”,
251 or equivalently the “base address of the object”, refers
252 to the “raw data” (the real data, the only thing around
253 that can be the object).
254
255 If an object has a descriptor, then the DWARF type for that
256 object will have a 
257 \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location} attribute. If an object
258 does not have a descriptor, then usually the DWARF type for the
259 object will not have a 
260 \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location}. 
261 (See the following
262 \addtoindex{Ada} example for a case where the type for an object without
263 a descriptor does have a \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location} attribute. In
264 that case the object doubles as its own descriptor.)
265
266 The \addtoindex{Fortran 90} derived type array\_ptr can now be redescribed
267 in C\dash like terms that expose some of the representation as in
268
269 \begin{lstlisting}
270 struct array_ptr {
271     float myvar;
272     desc<1> ap;
273 };
274 \end{lstlisting}
275
276 Similarly for variable arrays:
277 \begin{lstlisting}
278 desc<1> arrays;
279 \end{lstlisting}
280
281 (Recall that desc \textless 1 \textgreater 
282 indicates the 1\dash dimensional version of desc.)
283
284 Finally, the following notation is useful:
285
286 \begin{enumerate}[1.]
287 \item  sizeof(type): size in bytes of entities of the given type
288
289 \item offset(type, comp): offset in bytes of the comp component
290 within an entity of the given type
291 \end{enumerate}
292
293
294 The DWARF description is shown 
295 \addtoindexx{Fortran 90}
296 in 
297 Section \refersec{app:fortran90exampledwarfdescription}.
298
299 \subsection{Fortran 90 example: DWARF description}
300 \label{app:fortran90exampledwarfdescription}
301
302 \begin{alltt}
303 ! Description for type of 'ap'
304
305 1\$: \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type}
306         ! No name, default (Fortran) ordering, default stride
307         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to REAL)
308         \livelink{chap:DWATassociated}{DW\-\_AT\-\_associated}(expression= ! Test 'ptr\_assoc' \nolink{flag}
309             \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
310             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n == offset(ptr\_assoc)
311             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
312             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref}
313             \livelink{chap:DWOPlit1}{DW\-\_OP\-\_lit1} ! mask for 'ptr\_assoc' \nolink{flag}
314             \livelink{chap:DWOPand}{DW\-\_OP\-\_and})
315         \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location}(expression= ! Get raw data address
316             \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
317             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n == offset(base)
318             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
319             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref}) ! Type of index of array 'ap'
320 2\$:     \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
321         ! No name, default stride
322         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to INTEGER)
323         \livelink{chap:DWATlowerbound}{DW\-\_AT\-\_lower\-\_bound}(expression=
324         \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
325             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n ==
326                          !  offset(desc, dims) +
327                          !  offset(dims\_str, lower\_bound)
328             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
329             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref})
330         \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(expression=
331             \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
332             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n ==
333                          !  offset(desc, dims) +
334                          !  offset(dims\_str, upper\_bound)
335             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
336             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref})
337         !  Note: for the m'th dimension, the second operator becomes
338         !  \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<x> where
339         !  x == offset(desc, dims) +
340         !  (m-1)*sizeof(dims\_str) +
341         !  offset(dims\_str, [lower|upper]\_bound)
342         !  That is, the expression does not get longer for each
343         !  successive dimension (other than to express the larger
344         !  offsets involved).
345 3\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
346         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("array\_ptr")
347         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(constant sizeof(REAL) + sizeof(desc<1>))
348 4\$:     \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
349             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("myvar")
350             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to REAL)
351             \livelink{chap:DWATdatamemberlocation}{DW\-\_AT\-\_data\-\_member\-\_location}(constant 0)
352 5\$:     \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
353             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("ap");
354             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
355             \livelink{chap:DWATdatamemberlocation}{DW\-\_AT\-\_data\-\_member\-\_location}(constant sizeof(REAL))
356
357 6\$: \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type}
358         ! No name, default (Fortran) ordering, default stride
359         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 3\$)
360         \livelink{chap:DWATallocated}{DW\-\_AT\-\_allocated}(expression=
361              ! Test 'ptr\_alloc' \nolink{flag}
362             \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
363             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n == offset(ptr\_alloc)
364             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
365             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref}
366             \livetarg{chap:DWOPlit2}{DW\-\_OP\-\_lit2}
367              ! mask for 'ptr\_alloc' \nolink{flag}
368             \livelink{chap:DWOPand}{DW\-\_OP\-\_and})
369         \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location}(expression= ! Get raw data address
370             \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
371             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n = offset(base)
372             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
373             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref})
374
375 7\$: \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
376         ! No name, default stride
377         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to INTEGER)
378         \livelink{chap:DWATlowerbound}{DW\-\_AT\-\_lower\-\_bound}(expression=
379             \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
380             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n == ...
381             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
382             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref})
383         \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(expression=
384             \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}
385             \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n == ...
386             \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus}
387             \livelink{chap:DWOPderef}{DW\-\_OP\-\_deref})
388
389 8\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
390         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("arrays")
391         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 6\$)
392         \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(expression=
393             ...as appropriate...) ! Assume static allocation
394 \end{alltt}
395
396 \subsection{Fortran 90 example continued: DWARF description}
397 \label{app:fortran90examplecontinueddwarfdescription}
398
399 Suppose 
400 \addtoindexx{Fortran 90 example}
401 the program is stopped immediately following completion
402 of the do loop. Suppose further that the user enters the
403 following debug command:
404
405 \begin{lstlisting}
406 debug> print arrays(5)%ap(2)
407 \end{lstlisting}
408
409 Interpretation of this expression proceeds as follows:
410
411 \begin{enumerate}[1.]
412
413 \item Lookup name arrays. We find that it is a variable,
414 whose type is given by the unnamed type at 6\$. Notice that
415 the type is an array type.
416
417
418 \item Find the 5 element of that array object. To do array
419 indexing requires several pieces of information:
420
421 \begin{enumerate}[a]
422
423 \item  the address of the array data
424
425 \item the lower bounds of the array \\
426 % Using plain [] here gives trouble.
427 \lbrack To check that 5 is within bounds would require the upper
428 bound too, but we will skip that for this example. \rbrack
429
430 \item the stride 
431
432 \end{enumerate}
433
434 For a), check for a \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location} attribute. Since
435 there is one, go execute the expression, whose result is
436 the address needed. The object address used in this case
437 is the object we are working on, namely the variable named
438 arrays , whose address was found in step 1. (Had there been
439 no \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location} attribute, the desired address would
440 be the same as the address from step 1.)
441
442 For b), for each dimension of the array (only one
443 in this case), go interpret the usual lower bound
444 attribute. Again this is an expression, which again begins
445 with \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address}. This object is 
446 \textbf{still} arrays,
447 from step 1, because we have not begun to actually perform
448 any indexing yet.
449
450 For c), the default stride applies. Since there is no
451 \livelink{chap:DWATbytestride}{DW\-\_AT\-\_byte\-\_stride} attribute, use the size of the array element
452 type, which is the size of type array\_ptr (at 3\$).
453
454 Having acquired all the necessary data, perform the indexing
455 operation in the usual manner -  which has nothing to do with
456 any of the attributes involved up to now. Those just provide
457 the actual values used in the indexing step.
458
459 The result is an object within the memory that was dynamically
460 allocated for arrays.
461
462 \item  Find the ap component of the object just identified,
463 whose type is array\_ptr.
464
465 This is a conventional record component lookup and
466 interpretation. It happens that the ap component in this case
467 begins at offset 4 from the beginning of the containing object.
468 Component ap has the unnamed array type defined at 1\$ in the
469 symbol table.
470
471 \item  Find the second element of the array object found in step 3. To do array indexing requires
472 several pieces of information:
473
474 \begin{enumerate}[a]
475 \item  the address of the array storage
476
477 \item  the lower bounds of the array \\
478 % Using plain [] here gives trouble.
479 \lbrack To check that 2 is within bounds we would require the upper
480 %bound too, but we’ll skip that for this example \rbrack
481
482 \item  the stride
483
484 \end{enumerate}
485 \end{enumerate}
486
487 This is just like step 2), so the details are omitted. Recall
488 that because the DWARF type 1\$ has a \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location},
489 the address that results from step 4) is that of a
490 descriptor, and that address is the address pushed by the
491 \livelink{chap:DWOPpushobjectaddress}{DW\-\_OP\-\_push\-\_object\-\_address} operations in 1\$ and 2\$.
492
493 Note: we happen to be accessing a pointer array here instead
494 of an allocatable array; but because there is a common
495 underlying representation, the mechanics are the same. There
496 could be completely different descriptor arrangements and the
497 mechanics would still be the same — only the stack machines
498 would be different.
499
500
501
502 \subsection{Ada Example}
503 \label{app:adaexample}
504
505 Figure \referfol{fig:adaexamplesourcefragment}
506 illustrates two kinds of \addtoindex{Ada} 
507 parameterized array, one embedded in a record.
508
509
510 \begin{figure}[here]
511 \begin{lstlisting}
512 M : INTEGER := <exp>;
513 VEC1 : array (1..M) of INTEGER;
514 subtype TEENY is INTEGER range 1..100;
515 type ARR is array (INTEGER range <>) of INTEGER;
516 type REC2(N : TEENY := 100) is record
517     VEC2 : ARR(1..N);
518 end record;
519
520 OBJ2B : REC2;
521 \end{lstlisting}
522 \caption{Ada 90 example: source fragment}
523 \label{fig:adaexamplesourcefragment}
524 \end{figure}
525
526 VEC1 illustrates an (unnamed) array type where the upper bound
527 of the first and only dimension is determined at runtime. 
528 \addtoindex{Ada}
529 semantics require that the value of an array bound is fixed at
530 the time the array type is elaborated (where elaboration refers
531 to the runtime executable aspects of type processing). For
532 the purposes of this example, we assume that there are no
533 other assignments to M so that it safe for the REC1 type
534 description to refer directly to that variable (rather than
535 a compiler generated copy).
536
537 REC2 illustrates another array type (the unnamed type of
538 component VEC2) where the upper bound of the first and only
539 bound is also determined at runtime. In this case, the upper
540 bound is contained in a discriminant of the containing record
541 type. (A discriminant is a component of a record whose value
542 cannot be changed independently of the rest of the record
543 because that value is potentially used in the specification
544 of other components of the record.)
545
546 The DWARF description is shown in 
547 Section \refersec{app:adaexampledwarfdescription}
548
549
550 Interesting aspects about this example are:
551
552 \begin{enumerate}[1)]
553 \item The array VEC2 is ``immediately'' contained within structure
554 REC2 (there is no intermediate descriptor or indirection),
555 which is reflected in the absence of a \livelink{chap:DWATdatalocation}{DW\-\_AT\-\_data\-\_location}
556 attribute on the array type at 28\$.
557
558 \item One of the bounds of VEC2 is nonetheless dynamic and part of
559 the same containing record. It is described as a reference to
560 a member, and the location of the upper bound is determined
561 as for any member. That is, the location is determined using
562 an address calculation relative to the base of the containing
563 object.  A consumer must notice that the referenced bound is a
564 member of the same containing object and implicitly push the
565 base address of the containing object just as for accessing
566 a data member generally.
567
568 \item The lack of a subtype concept in DWARF means that DWARF types
569 serve the role of subtypes and must replicate information from
570 what should be the parent type. For this reason, DWARF for
571 the unconstrained array ARR is not needed for the purposes
572 of this example and therefore not shown.
573 \end{enumerate}
574
575 \subsubsection{Ada example: DWARF description}
576 \label{app:adaexampledwarfdescription}
577
578 \begin{alltt}
579 11\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
580         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("M")
581         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to INTEGER)
582 12\$: \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type}
583         ! No name, default (\addtoindex{Ada}) order, default stride
584         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to INTEGER)
585 13\$:    \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
586             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to INTEGER)
587             \livelink{chap:DWATlowerbound}{DW\-\_AT\-\_lower\-\_bound}(constant 1)
588             \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(reference to variable M at 11\$)
589 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
590         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("VEC1")
591         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to array type at 12\$)
592     . . .
593 21\$: \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
594         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TEENY")
595         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to INTEGER)
596         \livelink{chap:DWATlowerbound}{DW\-\_AT\-\_lower\-\_bound}(constant 1)
597         \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(constant 100)
598
599       . . .
600 26\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
601         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("REC2")
602 27\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
603             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("N")
604             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to subtype TEENY at 21\$)
605             \livelink{chap:DWATdatamemberlocation}{DW\-\_AT\-\_data\-\_member\-\_location}(constant 0)
606 28\$:   \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type}
607             ! No name, default (\addtoindex{Ada}) order, default stride
608             ! Default data location
609             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to INTEGER)
610 29\$:       \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
611                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to subrange TEENY at 21\$)
612                 \livelink{chap:DWATlowerbound}{DW\-\_AT\-\_lower\-\_bound}(constant 1)
613                 \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(reference to member N at 27\$)
614 30\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
615             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("VEC2")
616             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to array “subtype” at 28\$)
617             \livelink{chap:DWATdatamemberlocation}{DW\-\_AT\-\_data\-\_member\-\_location}(machine=
618                 \livelink{chap:DWOPlit}{DW\-\_OP\-\_lit}<n> ! where n == offset(REC2, VEC2)
619                 \livelink{chap:DWOPplus}{DW\-\_OP\-\_plus})
620       . . .
621 41\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
622         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OBJ2B")
623         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to REC2 at 26\$)
624         \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...as appropriate...)
625
626 \end{alltt}
627
628 \subsection{Pascal Example}
629 \label{app:pascalexample}
630
631 The Pascal \addtoindexx{Pascal example} source in 
632 Figure \referfol{fig:packedrecordexamplesourcefragment}
633 is used to illustrate the representation of packed unaligned
634 \addtoindex{bit fields}.
635
636 \begin{figure}[here]
637 \begin{lstlisting}
638 TYPE T : PACKED RECORD ! bit size is 2
639 F5 : BOOLEAN; ! bit offset is 0
640 F6 : BOOLEAN; ! bit offset is 1
641 END;
642 VAR V : PACKED RECORD
643 F1 : BOOLEAN; ! bit offset is 0
644 F2 : PACKED RECORD ! bit offset is 1
645 F3 : INTEGER; ! bit offset is 0 in F2, 1 in V
646 END;
647 F4 : PACKED ARRAY [0..1] OF T; ! bit offset is 33
648 F7 : T; ! bit offset is 37
649 END;
650 \end{lstlisting}
651 \caption{Packed record example: source fragment}
652 \label{fig:packedrecordexamplesourcefragment}
653 \end{figure}
654
655 The DWARF representation in 
656 Section \refersec{app:packedrecordexampledwarfdescription} 
657 is
658 appropriate. 
659 \livelink{chap:DWTAGpackedtype}{DW\-\_TAG\-\_packed\-\_type} entries could be added to
660 better represent the source, but these do not otherwise affect
661 the example and are omitted for clarity. Note that this same
662 representation applies to both typical big\dash \ and 
663 little\dash endian
664 architectures using the conventions described in 
665 Section \refersec{chap:datamemberentries}.
666
667
668 \subsection{Packed record example: DWARF description}
669 \label{app:packedrecordexampledwarfdescription}
670 % DWARF4 had some entries here as \livelink{chap:DWATmember}{DW_AT_member} .
671 % Those are fixed here to \livelink{chap:DWTAGmember}{DW_TAG_member}
672 \begin{alltt}
673
674 21\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type} ! anonymous type for F2
675         \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
676             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("F3")
677             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
678 22\$: \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type} ! anonymous type for F4
679         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 20\$)
680         \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
681             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
682             \livelink{chap:DWATlowerbound}{DW\-\_AT\-\_lower\-\_bound}(0)
683             \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(1)
684         \livelink{chap:DWATbitstride}{DW\-\_AT\-\_bit\-\_stride}(2)
685         \livelink{chap:DWATbitsize}{DW\-\_AT\-\_bit\-\_size}(4) \addtoindexx{bit size attribute}
686 23\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type} ! anonymous type for V
687         \livelink{chap:DWATbitsize}{DW\-\_AT\-\_bit\-\_size}(39) \addtoindexx{bit size attribute}
688         \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
689             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("F1")
690             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 10\$)
691             \livelink{chap:DWATdatabitoffset}{DW\-\_AT\-\_data\-\_bit\-\_offset}(0)! may be omitted
692             \livelink{chap:DWATbitsize}{DW\-\_AT\-\_bit\-\_size}(1) ! may be omitted
693         \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
694             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("F2")
695             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 21\$)
696             \livelink{chap:DWATdatabitoffset}{DW\-\_AT\-\_data\-\_bit\-\_offset}(1)
697             \livelink{chap:DWATbitsize}{DW\-\_AT\-\_bit\-\_size}(32) ! may be omitted
698         \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
699             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("F4")
700             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 22\$)
701             \livelink{chap:DWATdatabitoffset}{DW\-\_AT\-\_data\-\_bit\-\_offset}(33)
702             \livelink{chap:DWATbitsize}{DW\-\_AT\-\_bit\-\_size}(4) ! may be omitted
703         \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
704             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("F7")
705             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 20\$) ! type T
706             \livelink{chap:DWATdatabitoffset}{DW\-\_AT\-\_data\-\_bit\-\_offset}(37)
707             \livelink{chap:DWATbitsize}{DW\-\_AT\-\_bit\-\_size}(2) \addtoindexx{bit size attribute}! may be omitted
708      \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
709         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("V")
710         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 23\$)
711         \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
712         ...
713 \end{alltt}
714
715 \section{Namespace Example}
716 \label{app:namespaceexample}
717
718
719 The C++ example in 
720 Figure \referfol{fig:namespaceexamplesourcefragment}
721 is used 
722 \addtoindexx{namespace (C++)!example}
723 to illustrate the representation of namespaces.
724
725 \begin{figure}[here]
726 \begin{lstlisting}
727 namespace {
728     int i;
729 }
730
731 namespace A {
732     namespace B {
733         int j;
734         int myfunc (int a);
735         float myfunc (float f) { return f – 2.0; }
736         int myfunc2(int a) { return a + 2; }
737     }
738 }
739 namespace Y {
740     using A::B::j;         // (1) using declaration
741     int foo;
742 }
743
744 using A::B::j;             // (2) using declaration
745 namespace Foo = A::B;      // (3) namespace alias
746 using Foo::myfunc;         // (4) using declaration
747 using namespace Foo;       // (5) using directive
748 namespace A {
749     namespace B {
750         using namespace Y; // (6) using directive
751         int k;
752     }
753 }
754 int Foo::myfunc(int a)
755 {
756     i = 3;
757     j = 4;
758     return myfunc2(3) + j + i + a + 2;
759 }
760 \end{lstlisting}
761 \caption{Namespace example: source fragment}
762 \label{fig:namespaceexamplesourcefragment}
763 \end{figure}
764
765
766 The DWARF representation in 
767 Section \referfol{app:namespaceexampledwarfdescription}
768 is appropriate.
769
770 \subsection{Namespace example: DWARF description}
771 \label{app:namespaceexampledwarfdescription}
772 \begin{alltt}
773
774 1\$:  \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
775         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("int")
776         ...
777 2\$:  \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
778         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("float")
779         ...
780 6\$:  \livelink{chap:DWTAGnamespace}{DW\-\_TAG\-\_namespace}
781         ! no \livelink{chap:DWATname}{DW\-\_AT\-\_name} attribute
782 7\$:
783         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
784             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("i")
785             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
786             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location} ...
787             ...
788 10\$: \livelink{chap:DWTAGnamespace}{DW\-\_TAG\-\_namespace}
789         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("A")
790 20\$:    \livelink{chap:DWTAGnamespace}{DW\-\_TAG\-\_namespace}
791             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("B")
792 30\$:        \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
793                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("j")
794                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
795                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location} ...
796                 ...
797 34\$:        \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
798                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("myfunc")
799                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
800                 ...
801 36\$:        \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
802                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("myfunc")
803                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 2\$)
804                 ...
805 38\$:        \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
806                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("myfunc2")
807                 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc} ...
808                 \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc} ...
809                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
810                 ...
811
812 40\$: \livelink{chap:DWTAGnamespace}{DW\-\_TAG\-\_namespace}
813         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Y")
814         \livelink{chap:DWTAGimporteddeclaration}{DW\-\_TAG\-\_imported\-\_declaration}    ! (1) using-declaration
815             \livelink{chap:DWATimport}{DW\-\_AT\-\_import}(reference to 30\$)
816         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
817             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("foo")
818             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
819             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location} ...
820             ...
821      \livelink{chap:DWTAGimporteddeclaration}{DW\-\_TAG\-\_imported\-\_declaration}       ! (2) using declaration
822         \livelink{chap:DWATimport}{DW\-\_AT\-\_import}(reference to 30\$)
823         \livelink{chap:DWTAGimporteddeclaration}{DW\-\_TAG\-\_imported\-\_declaration}    ! (3) namespace alias
824             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Foo")
825             \livelink{chap:DWATimport}{DW\-\_AT\-\_import}(reference to 20\$)
826         \livelink{chap:DWTAGimporteddeclaration}{DW\-\_TAG\-\_imported\-\_declaration}    ! (4) using declaration
827             \livelink{chap:DWATimport}{DW\-\_AT\-\_import}(reference to 34\$) ! - part 1
828         \livelink{chap:DWTAGimporteddeclaration}{DW\-\_TAG\-\_imported\-\_declaration}    ! (4) using declaration
829             \livelink{chap:DWATimport}{DW\-\_AT\-\_import}(reference to 36\$) !  - part 2
830         \livelink{chap:DWTAGimportedmodule}{DW\-\_TAG\-\_imported\-\_module}         ! (5) using directive
831             \livelink{chap:DWATimport}{DW\-\_AT\-\_import}(reference to 20\$)
832         \livelink{chap:DWTAGnamespace}{DW\-\_TAG\-\_namespace}
833             \livelink{chap:DWATextension}{DW\-\_AT\-\_extension}(reference to 10\$)
834             \livelink{chap:DWTAGnamespace}{DW\-\_TAG\-\_namespace}
835                 \livelink{chap:DWATextension}{DW\-\_AT\-\_extension}(reference to 20\$)
836                 \livelink{chap:DWTAGimportedmodule}{DW\-\_TAG\-\_imported\-\_module} ! (6) using directive
837                     \livelink{chap:DWATimport}{DW\-\_AT\-\_import}(reference to 40\$)
838                 \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
839                     \livelink{chap:DWATname}{DW\-\_AT\-\_name}("k")
840                     \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
841                     \livelink{chap:DWATlocation}{DW\-\_AT\-\_location} ...
842                     ...
843 60\$: \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
844         \livelink{chap:DWATspecification}{DW\-\_AT\-\_specification}(reference to 34\$)
845         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc} ...
846         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc} ...
847         ...
848 \end{alltt}
849
850 \section{Member Function Example}
851 \label{app:memberfunctionexample}
852
853 Consider the member function example fragment in 
854 Figure \referfol{fig:memberfunctionexamplesourcefragment}.
855
856 \begin{figure}[here]
857 \begin{lstlisting}
858 class A
859 {
860     void func1(int x1);
861     void func2() const;
862     static void func3(int x3);
863 };
864 void A::func1(int x) {}
865 \end{lstlisting}
866 \caption{Member function example: source fragment}
867 \label{fig:memberfunctionexamplesourcefragment}
868 \end{figure}
869
870
871
872 The DWARF representation in 
873 Section \refersec{app:memberfunctionexampledwarfdescription}
874 is appropriate.
875
876 \subsection{Member function example: DWARF description}
877 \label{app:memberfunctionexampledwarfdescription}
878
879
880 \begin{alltt}
881 1\$: \livelink{chap:DWTAGunspecifiedtype}{DW\-\_TAG\-\_unspecified\-\_type}
882         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("void")
883                 ...
884 2\$ \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
885         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("int")
886         ...
887 3\$: \livelink{chap:DWTAGclasstype}{DW\-\_TAG\-\_class\-\_type}
888         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("A")
889         ...
890 4\$:    \livelink{chap:DWTAGpointertype}{DW\-\_TAG\-\_pointer\-\_type}
891             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 3\$)
892             ...
893 5\$:    \livelink{chap:DWTAGconsttype}{DW\-\_TAG\-\_const\-\_type}
894             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 3\$)
895             ...
896 6\$:    \livelink{chap:DWTAGpointertype}{DW\-\_TAG\-\_pointer\-\_type}
897             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 5\$)
898             ...
899
900 7\$:    \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
901             \livelink{chap:DWATdeclaration}{DW\-\_AT\-\_declaration}
902             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("func1")
903             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
904             \livelink{chap:DWATobjectpointer}{DW\-\_AT\-\_object\-\_pointer}(reference to 8\$) \addtoindexx{object pointer attribute}
905                 ! References a formal parameter in this 
906                 ! member function
907             ...
908 8\$:        \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
909                 \livelink{chap:DWATartificial}{DW\-\_AT\-\_artificial}(true)
910                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("this")
911                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 4\$)
912                     ! Makes type of 'this' as 'A*' =>
913                     ! func1 has not been marked const 
914                     ! or volatile
915                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location} ...
916                 ...
917 9\$:        \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
918                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}(x1)
919                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 2\$)
920                 ...
921 10\$:    \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
922              \livelink{chap:DWATdeclaration}{DW\-\_AT\-\_declaration}
923              \livelink{chap:DWATname}{DW\-\_AT\-\_name}("func2")
924              \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
925              \livelink{chap:DWATobjectpointer}{DW\-\_AT\-\_object\-\_pointer}(reference to 11\$) \addtoindexx{object pointer attribute}
926              ! References a formal parameter in this 
927              ! member function
928              ...
929 11\$:        \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
930                  \livelink{chap:DWATartificial}{DW\-\_AT\-\_artificial}(true)
931                  \livelink{chap:DWATname}{DW\-\_AT\-\_name}("this")
932                  \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 6\$)
933                      ! Makes type of 'this' as 'A const*' =>
934                  !     func2 marked as const
935                  \livelink{chap:DWATlocation}{DW\-\_AT\-\_location} ...
936                  ...
937 12\$:    \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
938              \livelink{chap:DWATdeclaration}{DW\-\_AT\-\_declaration}
939              \livelink{chap:DWATname}{DW\-\_AT\-\_name}("func3")
940              \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
941              ...
942                  ! No object pointer reference formal parameter
943                  ! implies func3 is static
944 13\$:        \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
945                  \livelink{chap:DWATname}{DW\-\_AT\-\_name}(x3)
946                  \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 2\$)
947                  ...
948 \end{alltt}
949
950 \section{Line Number Program Example}
951 \label{app:linenumberprogramexample}
952
953 Consider the simple source file and the resulting machine
954 code for the Intel 8086 processor in 
955 Figure \referfol{fig:linenumberprogramexamplemachinecode}.
956
957 \begin{figure}[here]
958 \begin{lstlisting}
959 1: int
960 2: main()
961     0x239: push pb
962     0x23a: mov bp,sp
963 3: {
964 4: printf("Omit needless words\n");
965     0x23c: mov ax,0xaa
966     0x23f: push ax
967     0x240: call _printf
968     0x243: pop cx
969 5: exit(0);
970     0x244: xor ax,ax
971     0x246: push ax
972     0x247: call _exit
973     0x24a: pop cx
974 6: }
975     0x24b: pop bp
976     0x24c: ret
977 7: 0x24d:
978 \end{lstlisting}
979 \caption{Line number program example: machine code}
980 \label{fig:linenumberprogramexamplemachinecode}
981 \end{figure}
982
983 Suppose the line number program header includes the following
984 (header fields not 
985 needed 
986 \addtoindexx{line\_base}
987 below 
988 \addtoindexx{line\_range}
989 are 
990 \addtoindexx{opcode\_base}
991 not 
992 \addtoindexx{minumum\_instruction\_length}
993 shown):
994
995
996 \begin{alltt}
997 version                    4
998 minimum_instruction_length 1
999 opcode_base               10 ! Opcodes 10-12 not needed
1000 line_base                  1
1001 line_range                15
1002 \end{alltt}
1003
1004
1005 Table \referfol{tab:linenumberprogramexampleoneencoding}
1006 shows one encoding of the line number program, which occupies
1007 12 bytes (the opcode SPECIAL(m,n) indicates the special opcode
1008 generated for a line increment of m and an address increment
1009 of n).
1010
1011
1012 \begin{centering}
1013 \setlength{\extrarowheight}{0.1cm}
1014 \begin{longtable}{lll}
1015   \caption{Line number program example: one encoding}
1016   \label{tab:linenumberprogramexampleoneencoding} \\
1017   \hline \\ \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream \\ \hline
1018 \endfirsthead
1019   \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream\\ \hline
1020 \endhead
1021   \hline \emph{Continued on next page}
1022 \endfoot
1023   \hline
1024 \endlastfoot
1025 \livelink{chap:DWLNSadvancepc}{DW\-\_LNS\-\_advance\-\_pc}&LEB128(0x239)&0x2, 0xb9, 0x04 \\
1026 SPECIAL(2, 0)&0xb  & \\
1027 SPECIAL(2, 3)&0x38 & \\
1028 SPECIAL(1, 8)&0x82 & \\
1029 SPECIAL(1, 7)&0x73 & \\
1030 \livelink{chap:DWLNSadvancepc}{DW\-\_LNS\-\_advance\-\_pc}&LEB128(2)&0x2, 0x2 \\
1031 \livelink{chap:DWLNEendsequence}{DW\-\_LNE\-\_end\-\_sequence} &&0x0, 0x1, 0x1 \\
1032 \end{longtable}
1033 \end{centering}
1034
1035
1036 Table \referfol{tab:linenumberprogramexamplealternateencoding}
1037 shows an alternate 
1038 encoding of the same program using 
1039 standard opcodes to advance
1040 the program counter; 
1041 this encoding occupies 22 bytes.
1042
1043 \begin{centering}
1044 \setlength{\extrarowheight}{0.1cm}
1045 \begin{longtable}{lll}
1046   \caption{Line number program example: alternate encoding} 
1047   \label{tab:linenumberprogramexamplealternateencoding} \\
1048   \hline \\ \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream \\ \hline
1049 \endfirsthead
1050   \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream\\ \hline
1051 \endhead
1052   \hline \emph{Continued on next page}
1053 \endfoot
1054   \hline
1055 \endlastfoot
1056 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x239&0x9, 0x39, 0x2        \\
1057 SPECIAL(2, 0)&& 0xb        \\
1058 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x3&0x9, 0x3, 0x0        \\
1059 SPECIAL(2, 0)&&0xb        \\
1060 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x8&0x9, 0x8, 0x0        \\
1061 SPECIAL(1, 0)&& 0xa        \\
1062 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x7&0x9, 0x7, 0x0        \\
1063 SPECIAL(1, 0) && 0xa        \\
1064 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x2&0x9, 0x2, 0x0        \\
1065 \livelink{chap:DWLNEendsequence}{DW\-\_LNE\-\_end\-\_sequence}&&0x0, 0x1, 0x1        \\
1066 \end{longtable}
1067 \end{centering}
1068
1069
1070 \section{Call Frame Information Example}
1071 \label{app:callframeinformationexample}
1072
1073 The following example uses a hypothetical RISC machine in
1074 the style of the Motorola 88000.
1075
1076 \begin{itemize}
1077 \item Memory is byte addressed.
1078
1079 \item Instructions are all 4 bytes each and word aligned.
1080
1081 \item Instruction operands are typically of the form:
1082
1083 \begin{alltt}
1084 <destination.reg>, <source.reg>, <constant>
1085 \end{alltt}
1086
1087 \item The address for the load and store instructions is computed
1088 by adding the contents of the
1089 source register with the constant.
1090
1091 \item There are 8 4\dash byte registers:
1092
1093 \begin{alltt}
1094 R0 always 0
1095 R1 holds return address on call
1096 R2-R3 temp registers (not preserved on call)
1097 R4-R6 preserved on call
1098 R7 stack pointer.
1099 \end{alltt}
1100
1101 \item  The stack grows in the negative direction.
1102
1103 \item The architectural ABI committee specifies that the
1104 stack pointer (R7) is the same as the CFA
1105
1106 \end{itemize}
1107
1108 Figure \referfol{fig:callframeinformationexamplemachinecodefragments}
1109 shows two code fragments from a subroutine called
1110 foo that uses a frame pointer (in addition to the stack
1111 pointer). The first column values are byte addresses. 
1112 % The \space is so we get a space after >
1113 \textless~fs~\textgreater \  denotes the stack frame size in bytes, namely 12.
1114
1115
1116 \begin{figure}[here]
1117 \begin{lstlisting}
1118        ;; start prologue
1119 foo    sub R7, R7, <fs>        ; Allocate frame
1120 foo+4  store R1, R7, (<fs>-4)  ; Save the return address
1121 foo+8  store R6, R7, (<fs>-8)  ; Save R6
1122 foo+12 add R6, R7, 0           ; R6 is now the Frame ptr
1123 foo+16 store R4, R6, (<fs>-12) ; Save a preserved reg
1124        ;; This subroutine does not change R5
1125        ...
1126        ;; Start epilogue (R7 is returned to entry value)
1127 foo+64 load R4, R6, (<fs>-12)  ; Restore R4
1128 foo+68 load R6, R7, (<fs>-8)   ; Restore R6
1129 foo+72 load R1, R7, (<fs>-4)   ; Restore return address
1130 foo+76 add R7, R7, <fs>        ; Deallocate frame
1131 foo+80 jump R1 ; Return
1132 foo+84
1133 \end{lstlisting}
1134 \caption{Call frame information example: machine code fragments}
1135 \label{fig:callframeinformationexamplemachinecodefragments}
1136 \end{figure}
1137
1138
1139 An abstract table 
1140 (see Section \refersec{chap:structureofcallframeinformation}) 
1141 for the foo subroutine is shown in 
1142 Table \referfol{tab:callframeinformationexampleconceptualmatrix}.
1143 Corresponding fragments from the
1144 \addtoindex{.debug\_frame} section are shown in 
1145 Table \refersec{tab:callframeinformationexamplecommoninformationentryencoding}.
1146
1147 The following notations apply in 
1148 Table \refersec{tab:callframeinformationexampleconceptualmatrix}:
1149
1150 \begin{alltt}
1151 1. R8 is the return address
1152 2. s = same\_value rule
1153 3. u = undefined rule
1154 4. rN = register(N) rule
1155 5. cN = offset(N) rule
1156 6. a = architectural rule
1157 \end{alltt}
1158
1159 \begin{centering}
1160 \setlength{\extrarowheight}{0.1cm}
1161 \begin{longtable}{lllllllllll}
1162   \caption{Call frame inforation example: conceptual matrix} 
1163   \label{tab:callframeinformationexampleconceptualmatrix} \\
1164   \hline \\ \bfseries Location & \bfseries CFA & \bfseries R0 & \bfseries R1 & \bfseries R2 & \bfseries R3 & \bfseries R4 & \bfseries R5 & \bfseries R6 & \bfseries R7 & \bfseries R8 \\ \hline
1165 \endfirsthead
1166   \bfseries Location &\bfseries CFA &\bfseries R0 & \bfseries R1 & \bfseries R2 &\bfseries R3 &\bfseries R4 &\bfseries R5 &\bfseries R6 &\bfseries R7 &\bfseries R8\\ \hline
1167 \endhead
1168   \hline \emph{Continued on next page}
1169 \endfoot
1170   \hline
1171 \endlastfoot
1172 foo&[R7]+0&s&u&u&u&s&s&s&a&r1 \\
1173 foo+4&[R7]+fs&s&u&u&u&s&s&s&a&r1 \\
1174 foo+8&[R7]+fs&s&u&u&u&s&s&s&a&c-4 \\
1175 foo+12&[R7]+fs&s&u&u&u&s&s&c-8&a&c-4 \\
1176 foo+16&[R6]+fs&s&u&u&u&s&s&c-8&a&c-4 \\
1177 foo+20&[R6]+fs&s&u&u&u&c-12&s&c-8&a&c-4 \\
1178 ...&&&&&&&&&& \\
1179 foo+64&[R6]+fs&s&u&u&u&c-12&s&c-8&a&c-4 \\
1180 foo+68&[R6]+fs&s&u&u&u&s&s&c-8&a&c-4  \\
1181 foo+72&[R7]+fs&s&u&u&u&s&s&s&a&c-4  \\
1182 foo+76&[R7]+fs&s&u&u&u&s&s&s&a&r1 \\
1183 foo+80&[R7]+0&s&u&u&u&s&s&s&a&r1 \\
1184 \end{longtable}
1185 \end{centering}
1186
1187
1188 \begin{centering}
1189 \setlength{\extrarowheight}{0.1cm}
1190 \begin{longtable}{lll}
1191   \caption{Call frame information example: common information entry encoding} 
1192   \label{tab:callframeinformationexamplecommoninformationentryencoding} \\
1193   \hline \\ \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1194 \endfirsthead
1195   \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1196 \endhead
1197   \hline \emph{Continued on next page}
1198 \endfoot
1199   \hline
1200 \endlastfoot
1201 cie&36&length    \\
1202 cie+4&0xffffffff&CIE\_id    \\
1203 cie+8&4&version    \\
1204 cie+9&0&augmentation     \\
1205 cie+10&4&address size    \\
1206 cie+11&0&segment size    \\
1207 cie+12&4&code\_alignment\_factor, \textless caf \textgreater    \\
1208 cie+13&-4&data\_alignment\_factor, \textless daf \textgreater    \\
1209 cie+14&8&R8 is the return addr.    \\
1210 cie+15&\livelink{chap:DWCFAdefcfa}{DW\-\_CFA\-\_def\-\_cfa} (7, 0)&CFA = [R7]+0    \\
1211 cie+18&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (0)&R0 not modified (=0)    \\
1212 cie+20&\livelink{chap:DWCFAundefined}{DW\-\_CFA\-\_undefined} (1)&R1 scratch    \\
1213 cie+22&\livelink{chap:DWCFAundefined}{DW\-\_CFA\-\_undefined} (2)&R2 scratch    \\
1214 cie+24&\livelink{chap:DWCFAundefined}{DW\-\_CFA\-\_undefined} (3)&R3 scratch    \\
1215 cie+26&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (4)&R4 preserve    \\
1216 cie+28&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (5)&R5 preserve    \\
1217 cie+30&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (6)&R6 preserve    \\
1218 cie+32&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (7)&R7 preserve    \\
1219 cie+34&\livelink{chap:DWCFAregister}{DW\-\_CFA\-\_register} (8, 1)&R8 is in R1    \\
1220 cie+37&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding    \\
1221 cie+38&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}& padding \\
1222 cie+39& \livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding  \\
1223 cie+40 &&  \\
1224 \end{longtable}
1225 \end{centering}
1226
1227
1228 The following notations apply in 
1229 Table \refersec{tab:callframeinformationexampleframedescriptionentryencoding}:
1230
1231 \begin{alltt}
1232 1. <fs> = frame size
1233 2. <caf> = code alignment factor
1234 3. <daf> = data alignment factor
1235 \end{alltt}
1236
1237
1238 \begin{centering}
1239 \setlength{\extrarowheight}{0.1cm}
1240 \begin{longtable}{lll}
1241   \caption{Call frame information example: frame description entry encoding} \label{tab:callframeinformationexampleframedescriptionentryencoding} \\
1242   \hline \\ \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1243 \endfirsthead
1244   \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1245 \endhead
1246   \hline \emph{Continued on next page}
1247 \endfoot
1248   \hline
1249 \endlastfoot
1250 fde&40&length \\
1251 fde+4&cie&CIE\_ptr \\
1252 fde+8&foo&initial\_location \\
1253 fde+12&84&address\_range \\
1254 fde+16&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1)&instructions \\
1255 fde+17&\livelink{chap:DWCFAdefcfaoffset}{DW\-\_CFA\-\_def\-\_cfa\-\_offset}(12)& \textless fs \textgreater \\
1256 fde+19&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1)&4/ \textless caf \textgreater \\
1257 fde+20&\livelink{chap:DWCFAoffset}{DW\-\_CFA\-\_offset}(8,1)&-4/ \textless daf \textgreater (second parameter) \\
1258 fde+22&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1)& \\
1259 fde+23&\livelink{chap:DWCFAoffset}{DW\-\_CFA\-\_offset}(6,2)&-8/ \textless daf> \textgreater (2nd parameter)  \\
1260 fde+25&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1261 fde+26&\livelink{chap:DWCFAdefcfaregister}{DW\-\_CFA\-\_def\-\_cfa\-\_register}(6) & \\
1262 fde+28&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1263 fde+29&\livelink{chap:DWCFAoffset}{DW\-\_CFA\-\_offset}(4,3)&-12/ \textless daf \textgreater (2nd parameter) \\
1264 fde+31&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(12)&44/ \textless caf \textgreater \\
1265 fde+32&\livelink{chap:DWCFArestore}{DW\-\_CFA\-\_restore}(4)& \\
1266 fde+33&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1267 fde+34&\livelink{chap:DWCFArestore}{DW\-\_CFA\-\_restore}(6) & \\
1268 fde+35&\livelink{chap:DWCFAdefcfaregister}{DW\-\_CFA\-\_def\-\_cfa\-\_register}(7)  & \\
1269 fde+37&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1270 fde+38&\livelink{chap:DWCFArestore}{DW\-\_CFA\-\_restore}(8) &\\
1271 fde+39&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) &\\
1272 fde+40&\livelink{chap:DWCFAdefcfaoffset}{DW\-\_CFA\-\_def\-\_cfa\-\_offset}(0)  &\\
1273 fde+42&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding \\
1274 fde+43&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding \\
1275 fde+44 && \\
1276 \end{longtable}
1277 \end{centering}
1278
1279 \section{Inlining Examples}
1280 \label{app:inliningexamples}
1281 The pseudo\dash source in 
1282 Figure \referfol{fig:inliningexamplespseudosourcefragment}
1283 is used to illustrate the
1284 \addtoindexx{inlined subprogram call!examples}
1285 use of DWARF to describe inlined subroutine calls. This
1286 example involves a nested subprogram INNER that makes uplevel
1287 references to the formal parameter and local variable of the
1288 containing subprogram OUTER.
1289
1290 \begin{figure}[here]
1291 \begin{lstlisting}
1292 inline procedure OUTER (OUTER_FORMAL : integer) =
1293     begin
1294     OUTER_LOCAL : integer;
1295     procedure INNER (INNER_FORMAL : integer) =
1296         begin
1297         INNER_LOCAL : integer;
1298         print(INNER_FORMAL + OUTER_LOCAL);
1299         end;
1300     INNER(OUTER_LOCAL);
1301     ...
1302     INNER(31);
1303     end;
1304 ! Call OUTER
1305 !
1306 OUTER(7);
1307 \end{lstlisting}
1308 \caption{Inlining examples: pseudo-source fragmment} 
1309 \label{fig:inliningexamplespseudosourcefragment}
1310 \end{figure}
1311
1312
1313 There are several approaches that a compiler might take to
1314 inlining for this sort of example. This presentation considers
1315 three such approaches, all of which involve inline expansion
1316 of subprogram OUTER. (If OUTER is not inlined, the inlining
1317 reduces to a simpler single level subset of the two level
1318 approaches considered here.)
1319
1320 The approaches are:
1321
1322 \begin{itemize}[1.]
1323 \item  Inline both OUTER and INNER in all cases
1324
1325 \item Inline OUTER, multiple INNERs \\
1326 Treat INNER as a non\dash inlinable part of OUTER, compile and
1327 call a distinct normal version of INNER defined within each
1328 inlining of OUTER.
1329
1330 \item Inline OUTER, one INNER \\
1331 Compile INNER as a single normal subprogram which is called
1332 from every inlining of OUTER.
1333 \end{itemize}
1334
1335 This discussion does not consider why a compiler might choose
1336 one of these approaches; it considers only how to describe
1337 the result.
1338
1339 In the examples that follow in this section, the debugging
1340 information entries are given mnemonic labels of the following
1341 form
1342
1343 \begin{lstlisting}
1344 <io>.<ac>.<n>.<s>
1345 \end{lstlisting}
1346
1347 where \begin{verbatim}<io>\end{verbatim}
1348 is either INNER or OUTER to indicate to which
1349 subprogram the debugging information entry applies, 
1350 \begin{verbatim}<ac>\end{verbatim}
1351 is either AI or CI to indicate ``abstract instance'' or
1352 ``concrete instance'' respectively, 
1353 \begin{verbatim}<n>\end{verbatim}
1354 is the number of the
1355 alternative being considered, and 
1356 \begin{verbatim}<s>\end{verbatim}
1357 is a sequence number that
1358 distinguishes the individual entries. There is no implication
1359 that symbolic labels, nor any particular naming convention,
1360 are required in actual use.
1361
1362 For conciseness, declaration coordinates and call coordinates are omitted.
1363
1364 \subsection{Alternative 1: inline both OUTER and INNER}
1365 \label{app:inlinebothouterandinner}
1366
1367 A suitable abstract instance for an alternative where both
1368 OUTER and INNER are always inlined is shown in 
1369 Figure \refersec{app:inliningexample1abstractinstance}
1370
1371 Notice in 
1372 Section \refersec{app:inliningexample1abstractinstance} 
1373 that the debugging information entry for
1374 INNER (labelled INNER.AI.1.1) is nested in (is a child of)
1375 that for OUTER (labelled OUTER.AI.1.1). Nonetheless, the
1376 abstract instance tree for INNER is considered to be separate
1377 and distinct from that for OUTER.
1378
1379 The call of OUTER shown in 
1380 Figure \refersec{fig:inliningexamplespseudosourcefragment}
1381 might be described as
1382 shown in 
1383 Section \refersec{app:inliningexample1concreteinstance}.
1384
1385
1386 \subsubsection{Inlining example \#1: abstract instance}
1387 \label{app:inliningexample1abstractinstance}
1388 \begin{alltt}
1389     ! Abstract instance for OUTER
1390     ! \addtoindexx{abstract instance!example}
1391 OUTER.AI.1.1:
1392     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1393         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1394         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1395         ! No low/high PCs
1396 OUTER.AI.1.2:
1397         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1398             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1399             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1400             ! No location
1401 OUTER.AI.1.3:
1402         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1403             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1404             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1405             ! No location
1406         !
1407         ! Abstract instance for INNER
1408         !
1409 INNER.AI.1.1:
1410         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1411             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1412             \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1413             ! No low/high PCs
1414 INNER.AI.1.2:
1415             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1416                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1417                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1418                 ! No location
1419 INNER.AI.1.3:
1420             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1421                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1422                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1423                 ! No location
1424             ...
1425             0
1426         ! No \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine} (concrete instance)
1427         ! for INNER corresponding to calls of INNER
1428         ...
1429         0
1430 \end{alltt}
1431
1432
1433 \subsubsection{Inlining example \#1: concrete instance}
1434 \label{app:inliningexample1concreteinstance}
1435 \begin{alltt}
1436 ! Concrete instance for call "OUTER(7)"
1437 ! \addtoindexx{concrete instance!example}
1438 OUTER.CI.1.1:
1439     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1440         ! No name
1441         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.1)
1442         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1443         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1444 OUTER.CI.1.2:
1445         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1446             ! No name
1447             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.2)
1448             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(7)
1449 OUTER.CI.1.3:
1450         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1451             ! No name
1452             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.3)
1453             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1454         !
1455         ! No \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} (abstract instance) for INNER
1456         !
1457         ! Concrete instance for call INNER(OUTER\_LOCAL)
1458         !
1459 INNER.CI.1.1:
1460         \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1461             ! No name
1462             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.1)
1463             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1464             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1465             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1466 INNER.CI.1.2:
1467             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1468                 ! No name
1469                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.2)
1470                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1471 INNER.CI.1.3:
1472              \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1473                 ! No name
1474                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.3)
1475                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1476             ...
1477             0
1478         ! Another concrete instance of INNER within OUTER
1479         ! for the call "INNER(31)"
1480         ...
1481         0
1482 \end{alltt}
1483
1484 \subsection{Alternative 2: Inline OUTER, multiple INNERs}
1485 \label{app:inlineoutermultiipleinners}
1486
1487
1488 In the second alternative we assume that subprogram INNER
1489 is not inlinable for some reason, but subprogram OUTER is
1490 inlinable. 
1491 \addtoindexx{concrete instance!example}
1492 Each concrete inlined instance of OUTER has its
1493 own normal instance of INNER. 
1494 The abstract instance for OUTER,
1495 \addtoindexx{abstract instance!example}
1496 which includes INNER, is shown in 
1497 Section \refersec{app:inliningexample2abstractinstance}.
1498
1499 Note that the debugging information in this Figure differs from
1500 that in 
1501 Section \refersec{app:inliningexample1abstractinstance}
1502 in that INNER lacks a 
1503 \livelink{chap:DWATinline}{DW\-\_AT\-\_inline} attribute
1504 and therefore is not a distinct abstract instance. INNER
1505 is merely an out\dash of\dash line routine that is part of OUTER’s
1506 abstract instance. This is reflected in the Figure 70 by
1507 \addtoindexx{abstract instance!example}
1508 the fact that the labels for INNER use the substring OUTER
1509 instead of INNER.
1510
1511 A resulting 
1512 \addtoindexx{concrete instance!example}
1513 concrete inlined instance of OUTER is shown in
1514 Section \referfol{app:inliningexample2concreteinstance}.
1515
1516 Notice in 
1517 Section \referfol{app:inliningexample2concreteinstance}.
1518 that OUTER is expanded as a concrete
1519 \addtoindexx{concrete instance!example}
1520 inlined instance, and that INNER is nested within it as a
1521 concrete out\dash of\dash line subprogram. Because INNER is cloned
1522 for each inline expansion of OUTER, only the invariant
1523 attributes of INNER 
1524 (for example, \livelink{chap:DWATname}{DW\-\_AT\-\_name}) are specified
1525 in the abstract instance of OUTER, and the low\dash level,
1526 \addtoindexx{abstract instance!example}
1527 instance\dash specific attributes of INNER (for example,
1528 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}) are specified in 
1529 each concrete instance of OUTER.
1530 \addtoindexx{concrete instance!example}
1531 The several calls of INNER within OUTER are compiled as normal
1532 calls to the instance of INNER that is specific to the same
1533 instance of OUTER that contains the calls.
1534
1535
1536 \subsubsection{Inlining example 2: abstract instance}
1537 \label{app:inliningexample2abstractinstance}
1538 \begin{alltt}
1539     ! Abstract instance for OUTER
1540     ! \addtoindex{abstract instance}
1541 OUTER.AI.2.1:
1542     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1543         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1544         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1545         ! No low/high PCs
1546 OUTER.AI.2.2:
1547         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1548             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1549             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1550             ! No location
1551 OUTER.AI.2.3:
1552         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1553             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1554             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1555             ! No location
1556         !
1557         ! Nested out-of-line INNER subprogram
1558         !
1559 OUTER.AI.2.4:
1560         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1561             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1562             ! No \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}
1563             ! No low/high PCs, frame\_base, etc.
1564 OUTER.AI.2.5:
1565             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1566                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1567                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1568                 ! No location
1569 OUTER.AI.2.6:
1570             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1571                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1572                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1573                 ! No location
1574             ...
1575             0
1576         ...
1577         0
1578 \end{alltt}
1579
1580 \subsubsection{Inlining example 2: concrete instance}
1581 \label{app:inliningexample2concreteinstance}
1582 \begin{alltt}
1583
1584     ! Concrete instance for call "OUTER(7)"
1585     !
1586 OUTER.CI.2.1:
1587     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1588         ! No name
1589         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.1)
1590         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1591         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1592 OUTER.CI.2.2:
1593         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1594             ! No name
1595             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.2)
1596             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1597 OUTER.CI.2.3:
1598         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1599             ! No name
1600             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.3)
1601             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1602         !
1603         ! Nested out-of-line INNER subprogram
1604         !
1605 OUTER.CI.2.4:
1606         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1607             ! No name
1608             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.4)
1609             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1610             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1611             \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1612             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1613 OUTER.CI.2.5:
1614             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1615                 ! No name
1616                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.5)
1617                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1618 OUTER.CI.2.6:
1619             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1620                 ! No name
1621                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AT.2.6)
1622                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1623             ...
1624             0
1625         ...
1626         0
1627 \end{alltt}
1628
1629 \subsection{Alternative 3: inline OUTER, one normal INNER}
1630 \label{app:inlineouteronenormalinner}
1631
1632 In the third approach, one normal subprogram for INNER is
1633 compiled which is called from all concrete inlined instances of
1634 \addtoindexx{concrete instance!example}
1635 \addtoindexx{abstract instance!example}
1636 OUTER. The abstract instance for OUTER is shown in 
1637 Section \refersec{app:inliningexample3abstractinstance}.
1638
1639 The most distinctive aspect of that Figure is that subprogram
1640 INNER exists only within the abstract instance of OUTER,
1641 and not in OUTER’s concrete instance. In the abstract
1642 \addtoindexx{concrete instance!example}
1643 \addtoindexx{abstract instance!example}
1644 instance of OUTER, the description of INNER has the full
1645 complement of attributes that would be expected for a
1646 normal subprogram. 
1647 While attributes such as 
1648 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc},
1649 \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}, 
1650 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location},
1651 and so on, typically are omitted
1652 \addtoindexx{high PC attribute}
1653 from 
1654 \addtoindexx{low PC attribute}
1655 an 
1656 \addtoindexx{location attribute}
1657 abstract instance because they are not invariant across
1658 instances of the containing abstract instance, in this case
1659 those same attributes are included precisely because they are
1660 invariant -- there is only one subprogram INNER to be described
1661 and every description is the same.
1662
1663 A concrete inlined instance of OUTER is illustrated in
1664 \refersec{app:inliningexample3concreteinstance}.
1665
1666 Notice in 
1667 \refersec{app:inliningexample3abstractinstance}
1668 that there is no DWARF representation for
1669 INNER at all; the representation of INNER does not vary across
1670 instances of OUTER and the abstract instance of OUTER includes
1671 the complete description of INNER, so that the description of
1672 INNER may be (and for reasons of space efficiency, should be)
1673 omitted from each 
1674 \addtoindexx{concrete instance!example}
1675 concrete instance of OUTER.
1676
1677 There is one aspect of this approach that is problematical from
1678 the DWARF perspective. The single compiled instance of INNER
1679 is assumed to access up\dash level variables of OUTER; however,
1680 those variables may well occur at varying positions within
1681 the frames that contain the 
1682 \addtoindexx{concrete instance!example}
1683 concrete inlined instances. A
1684 compiler might implement this in several ways, including the
1685 use of additional compiler generated parameters that provide
1686 reference parameters for the up\dash level variables, or a compiler
1687 generated static link like parameter that points to the group
1688 of up\dash level entities, among other possibilities. In either of
1689 these cases, the DWARF description for the location attribute
1690 of each uplevel variable needs to be different if accessed
1691 from within INNER compared to when accessed from within the
1692 instances of OUTER. An implementation is likely to require
1693 vendor\dash specific DWARF attributes and/or debugging information
1694 entries to describe such cases.
1695
1696 Note that in C++, a member function of a class defined within
1697 a function definition does not require any vendor\dash specific
1698 extensions because the C++ language disallows access to
1699 entities that would give rise to this problem. (Neither extern
1700 variables nor static members require any form of static link
1701 for accessing purposes.)
1702
1703 \subsubsection{Inlining example 3: abstract instance}
1704 \label{app:inliningexample3abstractinstance}
1705 \begin{alltt}
1706     ! Abstract instance for OUTER
1707     ! \addtoindexx{abstract instance!example}
1708 OUTER.AI.3.1:
1709     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1710         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1711         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1712         ! No low/high PCs
1713 OUTER.AI.3.2:
1714         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1715             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1716             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1717             ! No location
1718 OUTER.AI.3.3:
1719         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1720             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1721             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1722             ! No location
1723         !
1724         ! Normal INNER
1725         !
1726 OUTER.AI.3.4:
1727         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1728             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1729             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1730             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1731             \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1732             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1733 OUTER.AI.3.5:
1734             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1735                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1736                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1737                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1738 OUTER.AI.3.6:
1739             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1740                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1741                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1742                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1743             ...
1744             0
1745         ...
1746         0
1747 \end{alltt}
1748
1749
1750 \subsubsection{Inlining example 3: concrete instance}
1751 \label{app:inliningexample3concreteinstance}
1752 \begin{alltt}
1753     ! Concrete instance for call "OUTER(7)"
1754     ! \addtoindexx{concrete instance!example}
1755 OUTER.CI.3.1:
1756     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1757         ! No name
1758         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.1)
1759         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1760         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1761         \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1762 OUTER.CI.3.2:
1763         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1764             ! No name
1765             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.2)
1766             ! No type
1767             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1768 OUTER.CI.3.3:
1769         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1770             ! No name
1771             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.3)
1772             ! No type
1773             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1774         ! No \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} for "INNER"
1775         ...
1776         0
1777 \end{alltt}
1778
1779 \section{Constant Expression Example}
1780 \label{app:constantexpressionexample}
1781 C++ generalizes the notion of constant expressions to include
1782 constant expression user-defined literals and functions.
1783
1784 \begin{figure}[here]
1785 \begin{lstlisting}
1786 constexpr double mass = 9.8;
1787 constexpr int square (int x) { return x * x; }
1788 float arr[square(9)]; // square() called and inlined
1789 \end{lstlisting}
1790 \caption{Constant expressions: C++ source} \label{fig:constantexpressionscsource}
1791 \end{figure}
1792
1793 These declarations can be represented as illustrated in 
1794 Section \refersec{app:constantexpressionsdwarfdescription}.
1795
1796 \subsection{Constant expressions: DWARF description}
1797 \label{app:constantexpressionsdwarfdescription}
1798 \begin{alltt}
1799
1800       ! For variable mass
1801       !
1802 1\$:  \livelink{chap:DWTAGconsttype}{DW\-\_TAG\-\_const\-\_type}
1803         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "double")
1804 2\$:  \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1805         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("mass")
1806         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
1807         \livelink{chap:DWATconstexpr}{DW\-\_AT\-\_const\-\_expr}(true)
1808         \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(9.8)
1809       ! Abstract instance for square
1810       !
1811 10\$: \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1812         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("square")
1813         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1814         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLinlined}{DW\-\_INL\-\_inlined})
1815 11\$:   \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1816             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("x")
1817             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1818       ! Concrete instance for square(9)
1819       ! \addtoindexx{concrete instance!example}
1820 20\$: \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1821         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to 10\$)
1822         \livelink{chap:DWATconstexpr}{DW\-\_AT\-\_const\-\_expr}(present)
1823         \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(81)
1824         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1825             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to 11\$)
1826             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(9)
1827       ! Anonymous array type for arr
1828       !
1829 30\$: \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type}
1830         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "float")
1831         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(324) ! 81*4
1832         \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
1833             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1834             \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(reference to 20\$)
1835       ! Variable arr
1836       !
1837 40\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1838         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("arr")
1839         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
1840 \end{alltt}
1841
1842
1843 \section{Unicode Character Example}
1844 \label{app:unicodecharacterexample}
1845 \addtoindexx{Unicode|see {\textit{also} UTF-8}}
1846 \addtoindex{Unicode} character encodings can be described in DWARF as
1847 illustrated in 
1848 Section \refersec{app:unicodecharacterexamplesub}.
1849
1850 \begin{lstlisting}
1851 // C++ source
1852 //
1853 char16_t chr_a = u'h';
1854 char32_t chr_b = U'h';
1855 \end{lstlisting}
1856
1857 \subsection{Unicode Character Example}
1858 \label{app:unicodecharacterexamplesub}
1859 \begin{alltt}
1860
1861 ! DWARF description
1862 !
1863 1\$: \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
1864         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("char16\_t")
1865         \livelink{chap:DWATencoding}{DW\-\_AT\-\_encoding}(\livelink{chap:DWATEUTF}{DW\-\_ATE\-\_UTF})
1866         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(2)
1867 2\$: \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
1868         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("char32\_t")
1869         \livelink{chap:DWATencoding}{DW\-\_AT\-\_encoding}(\livelink{chap:DWATEUTF}{DW\-\_ATE\-\_UTF})
1870         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(4)
1871 3\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1872         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("chr\_a")
1873         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
1874 4\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1875         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("chr\_b")
1876         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 2\$)
1877 \end{alltt}
1878
1879
1880
1881 \section{Type-Safe Enumeration Example}
1882 \label{app:typesafeenumerationexample}
1883
1884
1885 C++ type\dash safe enumerations 
1886 \addtoindexx{type-safe enumeration}
1887 can be described in DWARF as illustrated in 
1888 Section \refersec{app:ctypesafeenumerationexample}.
1889
1890 \begin{lstlisting}
1891 // C++ source
1892 //
1893 enum class E { E1, E2=100 };
1894 E e1;
1895 \end{lstlisting}
1896
1897 \subsection{C++ type-safe enumeration example}
1898 \label{app:ctypesafeenumerationexample}
1899 \begin{alltt}
1900 ! DWARF description
1901 !
1902 11\$: \livelink{chap:DWTAGenumerationtype}{DW\-\_TAG\-\_enumeration\-\_type}
1903         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E")
1904         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1905         \livelink{chap:DWATenumclass}{DW\-\_AT\-\_enum\-\_class}(present)
1906 12\$:   \livelink{chap:DWTAGenumerator}{DW\-\_TAG\-\_enumerator}
1907             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E1")
1908             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(0)
1909 13\$:
1910          \livelink{chap:DWTAGenumerator}{DW\-\_TAG\-\_enumerator}
1911             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E2")
1912             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(100)
1913 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1914         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("e1")
1915         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1916 \end{alltt}
1917
1918 \section{Template Example}
1919 \label{app:templateexample}
1920
1921 C++ templates can be described in DWARF as illustrated in 
1922 Section \refersec{app:ctemplateexample1}.
1923
1924
1925
1926 \begin{lstlisting}
1927 // C++ source
1928 //
1929 template<class T>
1930 struct wrapper {
1931     T comp;
1932 };
1933 wrapper<int> obj;
1934 \end{lstlisting}
1935
1936 \subsection{C++ template example 1}
1937 \label{app:ctemplateexample1}
1938 \begin{alltt}
1939 ! DWARF description
1940 !
1941 11\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
1942         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("wrapper")
1943 12\$: \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1944         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
1945         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1946 13\$ \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
1947         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("comp")
1948         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 12\$)
1949 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1950         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("obj")
1951         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1952 \end{alltt}
1953
1954 The actual type of the component comp is int, but in the DWARF
1955 the type references the \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter} for
1956 T, which in turn references int. This implies that in the
1957 original template comp was of type T and that was replaced
1958 with int in the instance.  There exist situations where it is
1959 not possible for the DWARF to imply anything about the nature
1960 of the original template. 
1961
1962 Consider following C++ source and DWARF 
1963 that can describe it in
1964 Section \refersec{app:ctemplateexample2}.
1965
1966
1967 \begin{lstlisting}
1968 // C++ source
1969 //
1970     template<class T>
1971     struct wrapper {
1972         T comp;
1973     };
1974     template<class U>
1975     void consume(wrapper<U> formal)
1976     {
1977         ...
1978     }
1979     wrapper<int> obj;
1980     consume(obj);
1981 \end{lstlisting}
1982
1983 \subsection{C++ template example 2}
1984 \label{app:ctemplateexample2}
1985 \begin{alltt}
1986 ! DWARF description
1987 !
1988 11\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
1989         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("wrapper")
1990 12\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1991             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
1992             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1993 13\$    \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
1994             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("comp")
1995             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 12\$)
1996 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1997         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("obj")
1998         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1999 21\$: \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
2000         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("consume")
2001 22\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2002             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("U")
2003             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
2004 23\$:   \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
2005             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("formal")
2006             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
2007 \end{alltt}
2008
2009 In the \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} entry for the instance of consume,
2010 U is described as 
2011 int. 
2012 The type of formal is 
2013 \begin{alltt}
2014 wrapper<U>
2015 \end{alltt}
2016  in
2017 the source. DWARF only represents instantiations of templates;
2018 there is no entry which represents 
2019 \begin{alltt}
2020 wrapper<U>, 
2021 \end{alltt}
2022 which is neither
2023 a template parameter nor a template instantiation. The type
2024 of formal is described as 
2025 \begin{alltt}
2026 wrapper<int>, 
2027 \end{alltt}
2028 the instantiation of
2029 \begin{alltt}
2030 wrapper<U>, 
2031 \end{alltt}
2032 in the \livelink{chap:DWATtype}{DW\-\_AT\-\_type} attribute at 
2033 23\$. 
2034 There is no
2035 description of the relationship between template type parameter
2036 T at 12\$ and U at 
2037 22\$ which was used to instantiate 
2038 \begin{alltt}
2039 wrapper<U>.
2040 \end{alltt}
2041
2042 A consequence of this is that the DWARF information would
2043 not distinguish between the existing example and one where
2044 the formal of consume were declared in the source to be
2045 \begin{alltt}
2046 wrapper<int>.
2047 \end{alltt}
2048
2049 \section{Template Alias Examples}
2050 \label{app:templatealiasexample}
2051
2052 C++ template aliases can be described in DWARF as illustrated 
2053 \addtoindexx{template alias example}
2054 in 
2055 Section \refersec{app:templatealiasexample1}
2056 and 
2057 Section \refersec{app:templatealiasexample2}.
2058
2059
2060 \begin{lstlisting}
2061 // C++ source, template alias example 1
2062 //
2063 template<typename T, typename U>
2064 struct Alpha {
2065     T tango;
2066     U uniform;
2067 };
2068 template<typename V> using Beta = Alpha<V,V>;
2069 Beta<long> b;
2070 \end{lstlisting}
2071
2072
2073 \subsection{template alias example 1}
2074 \addtoindexx{template alias example 1}
2075 \label{app:templatealiasexample1}
2076 \begin{alltt}
2077 ! DWARF representation for variable 'b'
2078 !
2079 20\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2080         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Alpha")
2081 21\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2082             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
2083             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2084 22\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2085             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("U")
2086             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2087 23\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
2088             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("tango")
2089             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 21\$)
2090 24\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
2091             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("uniform")
2092             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 22\$)
2093 25\$: \livelink{chap:DWTAGtemplatealias}{DW\-\_TAG\-\_template\-\_alias}
2094         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Beta")
2095         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 20\$)
2096 26\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2097             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("V")
2098             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2099 27\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2100         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("b")
2101         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 25\$)
2102 \end{alltt}
2103
2104
2105 \begin{lstlisting}
2106 // C++ source, template alias example 2
2107 //
2108 template<class TX> struct X { };
2109 template<class TY> struct Y { };
2110 template<class T> using Z = Y<T>;
2111 X<Y<int>> y;
2112 X<Z<int>> z;
2113 \end{lstlisting}
2114
2115
2116 \subsection{template alias example 2}
2117 \addtoindexx{template alias example 2}
2118 \label{app:templatealiasexample2}
2119 \begin{alltt}
2120 ! DWARF representation for X<Y<int>>
2121 !
2122 30\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2123         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Y")
2124 31\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2125             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TY")
2126             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
2127 32\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2128         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("X")
2129 33\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2130             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TX")
2131             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
2132
2133 ! DWARF representation for X<Z<int>>
2134 !
2135 40\$: \livelink{chap:DWTAGtemplatealias}{DW\-\_TAG\-\_template\-\_alias}
2136 using Z = Y<int>;
2137         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Z")
2138         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
2139 41\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2140             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
2141             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
2142 42\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2143         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("X")
2144 43\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2145             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TX")
2146             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 40\$)
2147 ! Note that 32\$ and 42\$ are actually the same type
2148 !
2149 50\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2150         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("y")
2151         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to \$32)
2152 51\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2153         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("z")
2154         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to \$42)
2155 \end{alltt}