a9f105a6fec7d0323b1214ba4c2b6d37aa79cfe9
[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 use of DWARF to describe inlined subroutine calls. This
1265 example involves a nested subprogram INNER that makes uplevel
1266 references to the formal parameter and local variable of the
1267 containing subprogram OUTER.
1268
1269 \begin{figure}[here]
1270 \begin{lstlisting}
1271 inline procedure OUTER (OUTER_FORMAL : integer) =
1272     begin
1273     OUTER_LOCAL : integer;
1274     procedure INNER (INNER_FORMAL : integer) =
1275         begin
1276         INNER_LOCAL : integer;
1277         print(INNER_FORMAL + OUTER_LOCAL);
1278         end;
1279     INNER(OUTER_LOCAL);
1280     ...
1281     INNER(31);
1282     end;
1283 ! Call OUTER
1284 !
1285 OUTER(7);
1286 \end{lstlisting}
1287 \caption{Inlining examples: pseudo-source fragmment} \label{fig:inliningexamplespseudosourcefragment}
1288 \end{figure}
1289
1290
1291 There are several approaches that a compiler might take to
1292 inlining for this sort of example. This presentation considers
1293 three such approaches, all of which involve inline expansion
1294 of subprogram OUTER. (If OUTER is not inlined, the inlining
1295 reduces to a simpler single level subset of the two level
1296 approaches considered here.)
1297
1298 The approaches are:
1299
1300 \begin{itemize}[1.]
1301 \item  Inline both OUTER and INNER in all cases
1302
1303 \item Inline OUTER, multiple INNERs \\
1304 Treat INNER as a non\dash inlinable part of OUTER, compile and
1305 call a distinct normal version of INNER defined within each
1306 inlining of OUTER.
1307
1308 \item Inline OUTER, one INNER \\
1309 Compile INNER as a single normal subprogram which is called
1310 from every inlining of OUTER.
1311 \end{itemize}
1312
1313 This discussion does not consider why a compiler might choose
1314 one of these approaches; it considers only how to describe
1315 the result.
1316
1317 In the examples that follow in this section, the debugging
1318 information entries are given mnemonic labels of the following
1319 form
1320
1321 \begin{lstlisting}
1322 <io>.<ac>.<n>.<s>
1323 \end{lstlisting}
1324
1325 where \begin{verbatim}<io>\end{verbatim}
1326 is either INNER or OUTER to indicate to which
1327 subprogram the debugging information entry applies, 
1328 \begin{verbatim}<ac>\end{verbatim}
1329 is either AI or CI to indicate ``abstract instance'' or
1330 ``concrete instance'' respectively, 
1331 \begin{verbatim}<n>\end{verbatim}
1332 is the number of the
1333 alternative being considered, and 
1334 \begin{verbatim}<s>\end{verbatim}
1335 is a sequence number that
1336 distinguishes the individual entries. There is no implication
1337 that symbolic labels, nor any particular naming convention,
1338 are required in actual use.
1339
1340 For conciseness, declaration coordinates and call coordinates are omitted.
1341
1342 \subsection{Alternative 1: inline both OUTER and INNER}
1343 \label{app:inlinebothouterandinner}
1344
1345 A suitable abstract instance for an alternative where both
1346 OUTER and INNER are always inlined is shown in 
1347 Figure \refersec{app:inliningexample1abstractinstance}
1348
1349 Notice in 
1350 Section \refersec{app:inliningexample1abstractinstance} 
1351 that the debugging information entry for
1352 INNER (labelled INNER.AI.1.1) is nested in (is a child of)
1353 that for OUTER (labelled OUTER.AI.1.1). Nonetheless, the
1354 abstract instance tree for INNER is considered to be separate
1355 and distinct from that for OUTER.
1356
1357 The call of OUTER shown in 
1358 Figure \refersec{fig:inliningexamplespseudosourcefragment}
1359 might be described as
1360 shown in 
1361 Section \refersec{app:inliningexample1concreteinstance}.
1362
1363
1364 \subsubsection{Inlining example \#1: abstract instance}
1365 \label{app:inliningexample1abstractinstance}
1366 \begin{alltt}
1367     ! Abstract instance for OUTER
1368     ! \addtoindexx{abstract instance!example}
1369 OUTER.AI.1.1:
1370     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1371         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1372         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1373         ! No low/high PCs
1374 OUTER.AI.1.2:
1375         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1376             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1377             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1378             ! No location
1379 OUTER.AI.1.3:
1380         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1381             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1382             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1383             ! No location
1384         !
1385         ! Abstract instance for INNER
1386         !
1387 INNER.AI.1.1:
1388         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1389             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1390             \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1391             ! No low/high PCs
1392 INNER.AI.1.2:
1393             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1394                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1395                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1396                 ! No location
1397 INNER.AI.1.3:
1398             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1399                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1400                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1401                 ! No location
1402             ...
1403             0
1404         ! No \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine} (concrete instance)
1405         ! for INNER corresponding to calls of INNER
1406         ...
1407         0
1408 \end{alltt}
1409
1410
1411 \subsubsection{Inlining example \#1: concrete instance}
1412 \label{app:inliningexample1concreteinstance}
1413 \begin{alltt}
1414 ! Concrete instance for call "OUTER(7)"
1415 ! \addtoindexx{concrete instance!example}
1416 OUTER.CI.1.1:
1417     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1418         ! No name
1419         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.1)
1420         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1421         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1422 OUTER.CI.1.2:
1423         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1424             ! No name
1425             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.2)
1426             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(7)
1427 OUTER.CI.1.3:
1428         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1429             ! No name
1430             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.3)
1431             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1432         !
1433         ! No \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} (abstract instance) for INNER
1434         !
1435         ! Concrete instance for call INNER(OUTER\_LOCAL)
1436         !
1437 INNER.CI.1.1:
1438         \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1439             ! No name
1440             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.1)
1441             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1442             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1443             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1444 INNER.CI.1.2:
1445             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1446                 ! No name
1447                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.2)
1448                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1449 INNER.CI.1.3:
1450              \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1451                 ! No name
1452                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.3)
1453                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1454             ...
1455             0
1456         ! Another concrete instance of INNER within OUTER
1457         ! for the call "INNER(31)"
1458         ...
1459         0
1460 \end{alltt}
1461
1462 \subsection{Alternative 2: Inline OUTER, multiple INNERs}
1463 \label{app:inlineoutermultiipleinners}
1464
1465
1466 In the second alternative we assume that subprogram INNER
1467 is not inlinable for some reason, but subprogram OUTER is
1468 inlinable. 
1469 \addtoindexx{concrete instance!example}
1470 Each concrete inlined instance of OUTER has its
1471 own normal instance of INNER. 
1472 The abstract instance for OUTER,
1473 \addtoindexx{abstract instance!example}
1474 which includes INNER, is shown in 
1475 Section \refersec{app:inliningexample2abstractinstance}.
1476
1477 Note that the debugging information in this Figure differs from
1478 that in 
1479 Section \refersec{app:inliningexample1abstractinstance}
1480 in that INNER lacks a 
1481 \livelink{chap:DWATinline}{DW\-\_AT\-\_inline} attribute
1482 and therefore is not a distinct abstract instance. INNER
1483 is merely an out\dash of\dash line routine that is part of OUTER’s
1484 abstract instance. This is reflected in the Figure 70 by
1485 \addtoindexx{abstract instance!example}
1486 the fact that the labels for INNER use the substring OUTER
1487 instead of INNER.
1488
1489 A resulting 
1490 \addtoindexx{concrete instance!example}
1491 concrete inlined instance of OUTER is shown in
1492 Section \refersec{app:inliningexample2concreteinstance}.
1493
1494 Notice in 
1495 Section \refersec{app:inliningexample2concreteinstance}.
1496 that OUTER is expanded as a concrete
1497 \addtoindexx{concrete instance!example}
1498 inlined instance, and that INNER is nested within it as a
1499 concrete out\dash of\dash line subprogram. Because INNER is cloned
1500 for each inline expansion of OUTER, only the invariant
1501 attributes of INNER 
1502 (for example, \livelink{chap:DWATname}{DW\-\_AT\-\_name}) are specified
1503 in the abstract instance of OUTER, and the low\dash level,
1504 \addtoindexx{abstract instance!example}
1505 instance\dash specific attributes of INNER (for example,
1506
1507 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}) are specified in 
1508 each concrete instance of OUTER.
1509 \addtoindexx{concrete instance!example}
1510 The several calls of INNER within OUTER are compiled as normal
1511 calls to the instance of INNER that is specific to the same
1512 instance of OUTER that contains the calls.
1513
1514
1515 \subsubsection{Inlining example 2: abstract instance}
1516 \label{app:inliningexample2abstractinstance}
1517 \begin{alltt}
1518     ! Abstract instance for OUTER
1519     ! \addtoindex{abstract instance}
1520 OUTER.AI.2.1:
1521     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1522         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1523         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1524         ! No low/high PCs
1525 OUTER.AI.2.2:
1526         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1527             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1528             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1529             ! No location
1530 OUTER.AI.2.3:
1531         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1532             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1533             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1534             ! No location
1535         !
1536         ! Nested out-of-line INNER subprogram
1537         !
1538 OUTER.AI.2.4:
1539         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1540             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1541             ! No \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}
1542             ! No low/high PCs, frame\_base, etc.
1543 OUTER.AI.2.5:
1544             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1545                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1546                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1547                 ! No location
1548 OUTER.AI.2.6:
1549             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1550                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1551                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1552                 ! No location
1553             ...
1554             0
1555         ...
1556         0
1557 \end{alltt}
1558
1559 \subsubsection{Inlining example 2: concrete instance}
1560 \label{app:inliningexample2concreteinstance}
1561 \begin{alltt}
1562
1563     ! Concrete instance for call "OUTER(7)"
1564     !
1565 OUTER.CI.2.1:
1566     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1567         ! No name
1568         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.1)
1569         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1570         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1571 OUTER.CI.2.2:
1572         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1573             ! No name
1574             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.2)
1575             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1576 OUTER.CI.2.3:
1577         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1578             ! No name
1579             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.3)
1580             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1581         !
1582         ! Nested out-of-line INNER subprogram
1583         !
1584 OUTER.CI.2.4:
1585         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1586             ! No name
1587             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.4)
1588             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1589             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1590             \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1591             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1592 OUTER.CI.2.5:
1593             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1594                 ! No name
1595                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.5)
1596                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1597 OUTER.CI.2.6:
1598             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1599                 ! No name
1600                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AT.2.6)
1601                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1602             ...
1603             0
1604         ...
1605         0
1606 \end{alltt}
1607
1608 \subsection{Alternative 3: inline OUTER, one normal INNER}
1609 \label{app:inlineouteronenormalinner}
1610
1611 In the third approach, one normal subprogram for INNER is
1612 compiled which is called from all concrete inlined instances of
1613 \addtoindexx{concrete instance!example}
1614 \addtoindexx{abstract instance!example}
1615 OUTER. The abstract instance for OUTER is shown in 
1616 Section \refersec{app:inliningexample3abstractinstance}.
1617
1618 The most distinctive aspect of that Figure is that subprogram
1619 INNER exists only within the abstract instance of OUTER,
1620 and not in OUTER’s concrete instance. In the abstract
1621 \addtoindexx{concrete instance!example}
1622 \addtoindexx{abstract instance!example}
1623 instance of OUTER, the description of INNER has the full
1624 complement of attributes that would be expected for a
1625 normal subprogram. 
1626 While attributes such as 
1627 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc},
1628 \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}, 
1629 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location},
1630 and so on, typically are omitted
1631 \addtoindexx{high PC attribute}
1632 from 
1633 \addtoindexx{low PC attribute}
1634 an 
1635 \addtoindexx{location attribute}
1636 abstract instance because they are not invariant across
1637 instances of the containing abstract instance, in this case
1638 those same attributes are included precisely because they are
1639 invariant -- there is only one subprogram INNER to be described
1640 and every description is the same.
1641
1642 A concrete inlined instance of OUTER is illustrated in
1643 \refersec{app:inliningexample3concreteinstance}.
1644
1645 Notice in 
1646 \refersec{app:inliningexample3abstractinstance}
1647 that there is no DWARF representation for
1648 INNER at all; the representation of INNER does not vary across
1649 instances of OUTER and the abstract instance of OUTER includes
1650 the complete description of INNER, so that the description of
1651 INNER may be (and for reasons of space efficiency, should be)
1652 omitted from each 
1653 \addtoindexx{concrete instance!example}
1654 concrete instance of OUTER.
1655
1656 There is one aspect of this approach that is problematical from
1657 the DWARF perspective. The single compiled instance of INNER
1658 is assumed to access up\dash level variables of OUTER; however,
1659 those variables may well occur at varying positions within
1660 the frames that contain the 
1661 \addtoindexx{concrete instance!example}
1662 concrete inlined instances. A
1663 compiler might implement this in several ways, including the
1664 use of additional compiler generated parameters that provide
1665 reference parameters for the up\dash level variables, or a compiler
1666 generated static link like parameter that points to the group
1667 of up\dash level entities, among other possibilities. In either of
1668 these cases, the DWARF description for the location attribute
1669 of each uplevel variable needs to be different if accessed
1670 from within INNER compared to when accessed from within the
1671 instances of OUTER. An implementation is likely to require
1672 vendor\dash specific DWARF attributes and/or debugging information
1673 entries to describe such cases.
1674
1675 Note that in C++, a member function of a class defined within
1676 a function definition does not require any vendor\dash specific
1677 extensions because the C++ language disallows access to
1678 entities that would give rise to this problem. (Neither extern
1679 variables nor static members require any form of static link
1680 for accessing purposes.)
1681
1682 \subsubsection{Inlining example 3: abstract instance}
1683 \label{app:inliningexample3abstractinstance}
1684 \begin{alltt}
1685     ! Abstract instance for OUTER
1686     ! \addtoindexx{abstract instance!example}
1687 OUTER.AI.3.1:
1688     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1689         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1690         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1691         ! No low/high PCs
1692 OUTER.AI.3.2:
1693         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1694             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1695             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1696             ! No location
1697 OUTER.AI.3.3:
1698         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1699             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1700             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1701             ! No location
1702         !
1703         ! Normal INNER
1704         !
1705 OUTER.AI.3.4:
1706         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1707             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1708             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1709             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1710             \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1711             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1712 OUTER.AI.3.5:
1713             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1714                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1715                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1716                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1717 OUTER.AI.3.6:
1718             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1719                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1720                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1721                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1722             ...
1723             0
1724         ...
1725         0
1726 \end{alltt}
1727
1728
1729 \subsubsection{Inlining example 3: concrete instance}
1730 \label{app:inliningexample3concreteinstance}
1731 \begin{alltt}
1732     ! Concrete instance for call "OUTER(7)"
1733     ! \addtoindexx{concrete instance!example}
1734 OUTER.CI.3.1:
1735     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1736         ! No name
1737         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.1)
1738         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1739         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1740         \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1741 OUTER.CI.3.2:
1742         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1743             ! No name
1744             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.2)
1745             ! No type
1746             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1747 OUTER.CI.3.3:
1748         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1749             ! No name
1750             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.3)
1751             ! No type
1752             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1753         ! No \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} for "INNER"
1754         ...
1755         0
1756 \end{alltt}
1757
1758 \section{Constant Expression Example}
1759 \label{app:constantexpressionexample}
1760 C++ generalizes the notion of constant expressions to include
1761 constant expression user-defined literals and functions.
1762
1763 \begin{figure}[here]
1764 \begin{lstlisting}
1765 constexpr double mass = 9.8;
1766 constexpr int square (int x) { return x * x; }
1767 float arr[square(9)]; // square() called and inlined
1768 \end{lstlisting}
1769 \caption{Constant expressions: C++ source} \label{fig:constantexpressionscsource}
1770 \end{figure}
1771
1772 These declarations can be represented as illustrated in 
1773 Section \refersec{app:constantexpressionsdwarfdescription}.
1774
1775 \subsection{Constant expressions: DWARF description}
1776 \label{app:constantexpressionsdwarfdescription}
1777 \begin{alltt}
1778
1779       ! For variable mass
1780       !
1781 1\$:  \livelink{chap:DWTAGconsttype}{DW\-\_TAG\-\_const\-\_type}
1782         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "double")
1783 2\$:  \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1784         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("mass")
1785         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
1786         \livelink{chap:DWATconstexpr}{DW\-\_AT\-\_const\-\_expr}(true)
1787         \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(9.8)
1788       ! Abstract instance for square
1789       !
1790 10\$: \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1791         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("square")
1792         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1793         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLinlined}{DW\-\_INL\-\_inlined})
1794 11\$:   \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1795             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("x")
1796             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1797       ! Concrete instance for square(9)
1798       ! \addtoindexx{concrete instance!example}
1799 20\$: \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1800         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to 10\$)
1801         \livelink{chap:DWATconstexpr}{DW\-\_AT\-\_const\-\_expr}(present)
1802         \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(81)
1803         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1804             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to 11\$)
1805             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(9)
1806       ! Anonymous array type for arr
1807       !
1808 30\$: \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type}
1809         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "float")
1810         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(324) ! 81*4
1811         \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
1812             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1813             \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(reference to 20\$)
1814       ! Variable arr
1815       !
1816 40\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1817         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("arr")
1818         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
1819 \end{alltt}
1820
1821
1822 \section{Unicode Character Example}
1823 \label{app:unicodecharacterexample}
1824
1825 Unicode character encodings can be described in DWARF as
1826 illustrated in 
1827 Section \refersec{app:unicodecharacterexamplesub}.
1828
1829 \begin{lstlisting}
1830 // C++ source
1831 //
1832 char16_t chr_a = u'h';
1833 char32_t chr_b = U'h';
1834 \end{lstlisting}
1835
1836 \subsection{Unicode Character Example}
1837 \label{app:unicodecharacterexamplesub}
1838 \begin{alltt}
1839
1840 ! DWARF description
1841 !
1842 1\$: \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
1843         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("char16\_t")
1844         \livelink{chap:DWATencoding}{DW\-\_AT\-\_encoding}(\livelink{chap:DWATEUTF}{DW\-\_ATE\-\_UTF})
1845         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(2)
1846 2\$: \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
1847         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("char32\_t")
1848         \livelink{chap:DWATencoding}{DW\-\_AT\-\_encoding}(\livelink{chap:DWATEUTF}{DW\-\_ATE\-\_UTF})
1849         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(4)
1850 3\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1851         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("chr\_a")
1852         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
1853 4\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1854         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("chr\_b")
1855         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 2\$)
1856 \end{alltt}
1857
1858
1859
1860 \section{Type-Safe Enumeration Example}
1861 \label{app:typesafeenumerationexample}
1862
1863
1864 C++ type\dash safe enumerations can be described in DWARF as illustrated in 
1865 Section \refersec{app:ctypesafeenumerationexample}.
1866
1867 \begin{lstlisting}
1868 // C++ source
1869 //
1870 enum class E { E1, E2=100 };
1871 E e1;
1872 \end{lstlisting}
1873
1874 \subsection{C++ type-safe enumeration example}
1875 \label{app:ctypesafeenumerationexample}
1876 \begin{alltt}
1877 ! DWARF description
1878 !
1879 11\$: \livelink{chap:DWTAGenumerationtype}{DW\-\_TAG\-\_enumeration\-\_type}
1880         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E")
1881         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1882         \livelink{chap:DWATenumclass}{DW\-\_AT\-\_enum\-\_class}(present)
1883 12\$:   \livelink{chap:DWTAGenumerator}{DW\-\_TAG\-\_enumerator}
1884             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E1")
1885             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(0)
1886 13\$:
1887          \livelink{chap:DWTAGenumerator}{DW\-\_TAG\-\_enumerator}
1888             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E2")
1889             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(100)
1890 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1891         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("e1")
1892         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1893 \end{alltt}
1894
1895 \section{Template Example}
1896 \label{app:templateexample}
1897
1898 C++ templates can be described in DWARF as illustrated in 
1899 Section \refersec{app:ctemplateexample1}.
1900
1901
1902
1903 \begin{lstlisting}
1904 // C++ source
1905 //
1906 template<class T>
1907 struct wrapper {
1908     T comp;
1909 };
1910 wrapper<int> obj;
1911 \end{lstlisting}
1912
1913 \subsection{C++ template example 1}
1914 \label{app:ctemplateexample1}
1915 \begin{alltt}
1916 ! DWARF description
1917 !
1918 11\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
1919         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("wrapper")
1920 12\$: \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1921         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
1922         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1923 13\$ \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
1924         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("comp")
1925         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 12\$)
1926 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1927         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("obj")
1928         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1929 \end{alltt}
1930
1931 The actual type of the component comp is int, but in the DWARF
1932 the type references the \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter} for
1933 T, which in turn references int. This implies that in the
1934 original template comp was of type T and that was replaced
1935 with int in the instance.  There exist situations where it is
1936 not possible for the DWARF to imply anything about the nature
1937 of the original template. 
1938
1939 Consider following C++ source and DWARF 
1940 that can describe it in
1941 Section \refersec{app:ctemplateexample2}.
1942
1943
1944 \begin{lstlisting}
1945 // C++ source
1946 //
1947     template<class T>
1948     struct wrapper {
1949         T comp;
1950     };
1951     template<class U>
1952     void consume(wrapper<U> formal)
1953     {
1954         ...
1955     }
1956     wrapper<int> obj;
1957     consume(obj);
1958 \end{lstlisting}
1959
1960 \subsection{C++ template example 2}
1961 \label{app:ctemplateexample2}
1962 \begin{alltt}
1963 ! DWARF description
1964 !
1965 11\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
1966         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("wrapper")
1967 12\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1968             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
1969             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1970 13\$    \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
1971             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("comp")
1972             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 12\$)
1973 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1974         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("obj")
1975         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1976 21\$: \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1977         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("consume")
1978 22\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1979             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("U")
1980             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1981 23\$:   \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1982             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("formal")
1983             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1984 \end{alltt}
1985
1986 In the \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} entry for the instance of consume,
1987 U is described as 
1988 int. 
1989 The type of formal is 
1990 \begin{alltt}
1991 wrapper<U>
1992 \end{alltt}
1993  in
1994 the source. DWARF only represents instantiations of templates;
1995 there is no entry which represents 
1996 \begin{alltt}
1997 wrapper<U>, 
1998 \end{alltt}
1999 which is neither
2000 a template parameter nor a template instantiation. The type
2001 of formal is described as 
2002 \begin{alltt}
2003 wrapper<int>, 
2004 \end{alltt}
2005 the instantiation of
2006 \begin{alltt}
2007 wrapper<U>, 
2008 \end{alltt}
2009 in the \livelink{chap:DWATtype}{DW\-\_AT\-\_type} attribute at 
2010 23\$. 
2011 There is no
2012 description of the relationship between template type parameter
2013 T at 12\$ and U at 
2014 22\$ which was used to instantiate 
2015 \begin{alltt}
2016 wrapper<U>.
2017 \end{alltt}
2018
2019 A consequence of this is that the DWARF information would
2020 not distinguish between the existing example and one where
2021 the formal of consume were declared in the source to be
2022 \begin{alltt}
2023 wrapper<int>.
2024 \end{alltt}
2025
2026 \section{Template Alias Examples}
2027 \label{app:templatealiasexample}
2028
2029 C++ template aliases can be described in DWARF as illustrated in 
2030 Section \refersec{app:templatealiasexample1}
2031 and 
2032 Section \refersec{app:templatealiasexample2}.
2033
2034
2035 \begin{lstlisting}
2036 // C++ source, template alias example 1
2037 //
2038 template<typename T, typename U>
2039 struct Alpha {
2040     T tango;
2041     U uniform;
2042 };
2043 template<typename V> using Beta = Alpha<V,V>;
2044 Beta<long> b;
2045 \end{lstlisting}
2046
2047
2048 \subsection{template alias example 1}
2049 \label{app:templatealiasexample1}
2050 \begin{alltt}
2051 ! DWARF representation for variable 'b'
2052 !
2053 20\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2054         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Alpha")
2055 21\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2056             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
2057             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2058 22\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2059             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("U")
2060             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2061 23\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
2062             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("tango")
2063             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 21\$)
2064 24\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
2065             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("uniform")
2066             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 22\$)
2067 25\$: \livelink{chap:DWTAGtemplatealias}{DW\-\_TAG\-\_template\-\_alias}
2068         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Beta")
2069         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 20\$)
2070 26\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2071             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("V")
2072             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2073 27\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2074         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("b")
2075         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 25\$)
2076 \end{alltt}
2077
2078
2079 \begin{lstlisting}
2080 // C++ source, template alias example 2
2081 //
2082 template<class TX> struct X { };
2083 template<class TY> struct Y { };
2084 template<class T> using Z = Y<T>;
2085 X<Y<int>> y;
2086 X<Z<int>> z;
2087 \end{lstlisting}
2088
2089
2090 \subsection{template alias example 2}
2091 \label{app:templatealiasexample2}
2092 \begin{alltt}
2093 ! DWARF representation for X<Y<int>>
2094 !
2095 30\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2096         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Y")
2097 31\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2098             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TY")
2099             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
2100 32\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2101         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("X")
2102 33\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2103             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TX")
2104             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
2105
2106 ! DWARF representation for X<Z<int>>
2107 !
2108 40\$: \livelink{chap:DWTAGtemplatealias}{DW\-\_TAG\-\_template\-\_alias}
2109 using Z = Y<int>;
2110         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Z")
2111         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
2112 41\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2113             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
2114             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
2115 42\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2116         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("X")
2117 43\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2118             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TX")
2119             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 40\$)
2120 ! Note that 32\$ and 42\$ are actually the same type
2121 !
2122 50\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2123         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("y")
2124         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to \$32)
2125 51\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2126         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("z")
2127         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to \$42)
2128 \end{alltt}