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