9693b04731059d4e7ce6c2797d558b40f3e89d30
[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 
976 needed 
977 \addtoindexx{line\_base}
978 below 
979 \addtoindexx{line\_range}
980 are 
981 \addtoindexx{opcode\_base}
982 not 
983 \addtoindexx{minumum\_instruction\_length}
984 shown):
985
986
987 \begin{alltt}
988 version                    4
989 minimum_instruction_length 1
990 opcode_base               10 ! Opcodes 10-12 not needed
991 line_base                  1
992 line_range                15
993 \end{alltt}
994
995
996 Figure \refersec{tab:linenumberprogramexampleoneencoding}
997 shows one encoding of the line number program, which occupies
998 12 bytes (the opcode SPECIAL(m,n) indicates the special opcode
999 generated for a line increment of m and an address increment
1000 of n).
1001
1002
1003 \begin{centering}
1004 \setlength{\extrarowheight}{0.1cm}
1005 \begin{longtable}{lll}
1006   \caption{Line number program example: one encoding} \label{tab:linenumberprogramexampleoneencoding} \\
1007   \hline \\ \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream \\ \hline
1008 \endfirsthead
1009   \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream\\ \hline
1010 \endhead
1011   \hline \emph{Continued on next page}
1012 \endfoot
1013   \hline
1014 \endlastfoot
1015 \livelink{chap:DWLNSadvancepc}{DW\-\_LNS\-\_advance\-\_pc}&LEB128(0x239)&0x2, 0xb9, 0x04 \\
1016 SPECIAL(2, 0)&0xb  & \\
1017 SPECIAL(2, 3)&0x38 & \\
1018 SPECIAL(1, 8)&0x82 & \\
1019 SPECIAL(1, 7)&0x73 & \\
1020 \livelink{chap:DWLNSadvancepc}{DW\-\_LNS\-\_advance\-\_pc}&LEB128(2)&0x2, 0x2 \\
1021 \livelink{chap:DWLNEendsequence}{DW\-\_LNE\-\_end\-\_sequence} &&0x0, 0x1, 0x1 \\
1022 \end{longtable}
1023 \end{centering}
1024
1025
1026 Table \refersec{tab:linenumberprogramexamplealternateencoding}
1027 shows an alternate 
1028 encoding of the same program using 
1029 standard opcodes to advance
1030 the program counter; 
1031 this encoding occupies 22 bytes.
1032
1033 \begin{centering}
1034 \setlength{\extrarowheight}{0.1cm}
1035 \begin{longtable}{lll}
1036   \caption{Line number program example: alternate encoding} \label{tab:linenumberprogramexamplealternateencoding} \\
1037   \hline \\ \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream \\ \hline
1038 \endfirsthead
1039   \bfseries Opcode &\bfseries Operand &\bfseries Byte Stream\\ \hline
1040 \endhead
1041   \hline \emph{Continued on next page}
1042 \endfoot
1043   \hline
1044 \endlastfoot
1045 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x239&0x9, 0x39, 0x2        \\
1046 SPECIAL(2, 0)&& 0xb        \\
1047 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x3&0x9, 0x3, 0x0        \\
1048 SPECIAL(2, 0)&&0xb        \\
1049 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x8&0x9, 0x8, 0x0        \\
1050 SPECIAL(1, 0)&& 0xa        \\
1051 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x7&0x9, 0x7, 0x0        \\
1052 SPECIAL(1, 0) && 0xa        \\
1053 \livelink{chap:DWLNSfixedadvancepc}{DW\-\_LNS\-\_fixed\-\_advance\-\_pc}&0x2&0x9, 0x2, 0x0        \\
1054 \livelink{chap:DWLNEendsequence}{DW\-\_LNE\-\_end\-\_sequence}&&0x0, 0x1, 0x1        \\
1055 \end{longtable}
1056 \end{centering}
1057
1058
1059 \section{Call Frame Information Example}
1060 \label{app:callframeinformationexample}
1061
1062 The following example uses a hypothetical RISC machine in
1063 the style of the Motorola 88000.
1064
1065 \begin{itemize}
1066 \item Memory is byte addressed.
1067
1068 \item Instructions are all 4 bytes each and word aligned.
1069
1070 \item Instruction operands are typically of the form:
1071
1072 \begin{alltt}
1073 <destination.reg>, <source.reg>, <constant>
1074 \end{alltt}
1075
1076 \item The address for the load and store instructions is computed
1077 by adding the contents of the
1078 source register with the constant.
1079
1080 \item There are 8 4\dash byte registers:
1081
1082 \begin{alltt}
1083 R0 always 0
1084 R1 holds return address on call
1085 R2-R3 temp registers (not preserved on call)
1086 R4-R6 preserved on call
1087 R7 stack pointer.
1088 \end{alltt}
1089
1090 \item  The stack grows in the negative direction.
1091
1092 \item The architectural ABI committee specifies that the
1093 stack pointer (R7) is the same as the CFA
1094
1095 \end{itemize}
1096
1097 The following 
1098 (Figure refersec{fig:callframeinformationexamplemachinecodefragments}
1099 are two code fragments from a subroutine called
1100 foo that uses a frame pointer (in addition to the stack
1101 pointer). The first column values are byte addresses. 
1102 % The \space is so we get a space after >
1103 \textless~fs~\textgreater \  denotes the stack frame size in bytes, namely 12.
1104
1105
1106 \begin{figure}[here]
1107 \begin{lstlisting}
1108        ;; start prologue
1109 foo    sub R7, R7, <fs>        ; Allocate frame
1110 foo+4  store R1, R7, (<fs>-4)  ; Save the return address
1111 foo+8  store R6, R7, (<fs>-8)  ; Save R6
1112 foo+12 add R6, R7, 0           ; R6 is now the Frame ptr
1113 foo+16 store R4, R6, (<fs>-12) ; Save a preserved reg
1114        ;; This subroutine does not change R5
1115        ...
1116        ;; Start epilogue (R7 is returned to entry value)
1117 foo+64 load R4, R6, (<fs>-12)  ; Restore R4
1118 foo+68 load R6, R7, (<fs>-8)   ; Restore R6
1119 foo+72 load R1, R7, (<fs>-4)   ; Restore return address
1120 foo+76 add R7, R7, <fs>        ; Deallocate frame
1121 foo+80 jump R1 ; Return
1122 foo+84
1123 \end{lstlisting}
1124 \caption{Call frame information example: machine code fragments} \label{fig:callframeinformationexamplemachinecodefragments}
1125 \end{figure}
1126
1127
1128 An abstract table 
1129 (see Section \refersec{chap:structureofcallframeinformation}) 
1130 for the foo subroutine
1131 is shown in 
1132 Table \refersec{tab:callframeinformationexampleconceptualmatrix}.
1133 Corresponding fragments from the
1134 \addtoindex{.debug\_frame} section are shown in 
1135 Table \refersec{tab:callframeinformationexamplecommoninformationentryencoding}.
1136
1137 The following notations apply in 
1138 Table \refersec{tab:callframeinformationexampleconceptualmatrix}:
1139
1140 \begin{alltt}
1141 1. R8 is the return address
1142 2. s = same\_value rule
1143 3. u = undefined rule
1144 4. rN = register(N) rule
1145 5. cN = offset(N) rule
1146 6. a = architectural rule
1147 \end{alltt}
1148
1149 \begin{centering}
1150 \setlength{\extrarowheight}{0.1cm}
1151 \begin{longtable}{lllllllllll}
1152   \caption{Call frame inforation example: conceptual matrix} \label{tab:callframeinformationexampleconceptualmatrix} \\
1153   \hline \\ \bfseries Location & \bfseries CFA & \bfseries R0 & \bfseries R1 & \bfseries R2 & \bfseries R3 & \bfseries R4 & \bfseries R5 & \bfseries R6 & \bfseries R7 & \bfseries R8 \\ \hline
1154 \endfirsthead
1155   \bfseries Location &\bfseries CFA &\bfseries R0 & \bfseries R1 & \bfseries R2 &\bfseries R3 &\bfseries R4 &\bfseries R5 &\bfseries R6 &\bfseries R7 &\bfseries R8\\ \hline
1156 \endhead
1157   \hline \emph{Continued on next page}
1158 \endfoot
1159   \hline
1160 \endlastfoot
1161 foo&[R7]+0&s&u&u&u&s&s&s&a&r1 \\
1162 foo+4&[R7]+fs&s&u&u&u&s&s&s&a&r1 \\
1163 foo+8&[R7]+fs&s&u&u&u&s&s&s&a&c-4 \\
1164 foo+12&[R7]+fs&s&u&u&u&s&s&c-8&a&c-4 \\
1165 foo+16&[R6]+fs&s&u&u&u&s&s&c-8&a&c-4 \\
1166 foo+20&[R6]+fs&s&u&u&u&c-12&s&c-8&a&c-4 \\
1167 ...&&&&&&&&&& \\
1168 foo+64&[R6]+fs&s&u&u&u&c-12&s&c-8&a&c-4 \\
1169 foo+68&[R6]+fs&s&u&u&u&s&s&c-8&a&c-4  \\
1170 foo+72&[R7]+fs&s&u&u&u&s&s&s&a&c-4  \\
1171 foo+76&[R7]+fs&s&u&u&u&s&s&s&a&r1 \\
1172 foo+80&[R7]+0&s&u&u&u&s&s&s&a&r1 \\
1173 \end{longtable}
1174 \end{centering}
1175
1176
1177 \begin{centering}
1178 \setlength{\extrarowheight}{0.1cm}
1179 \begin{longtable}{lll}
1180   \caption{Call frame information example: common information entry encoding} \label{tab:callframeinformationexamplecommoninformationentryencoding} \\
1181   \hline \\ \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1182 \endfirsthead
1183   \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1184 \endhead
1185   \hline \emph{Continued on next page}
1186 \endfoot
1187   \hline
1188 \endlastfoot
1189 cie&36&length    \\
1190 cie+4&0xffffffff&CIE\_id    \\
1191 cie+8&4&version    \\
1192 cie+9&0&augmentation     \\
1193 cie+10&4&address size    \\
1194 cie+11&0&segment size    \\
1195 cie+12&4&code\_alignment\_factor, \textless caf \textgreater    \\
1196 cie+13&-4&data\_alignment\_factor, \textless daf \textgreater    \\
1197 cie+14&8&R8 is the return addr.    \\
1198 cie+15&\livelink{chap:DWCFAdefcfa}{DW\-\_CFA\-\_def\-\_cfa} (7, 0)&CFA = [R7]+0    \\
1199 cie+18&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (0)&R0 not modified (=0)    \\
1200 cie+20&\livelink{chap:DWCFAundefined}{DW\-\_CFA\-\_undefined} (1)&R1 scratch    \\
1201 cie+22&\livelink{chap:DWCFAundefined}{DW\-\_CFA\-\_undefined} (2)&R2 scratch    \\
1202 cie+24&\livelink{chap:DWCFAundefined}{DW\-\_CFA\-\_undefined} (3)&R3 scratch    \\
1203 cie+26&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (4)&R4 preserve    \\
1204 cie+28&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (5)&R5 preserve    \\
1205 cie+30&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (6)&R6 preserve    \\
1206 cie+32&\livelink{chap:DWCFAsamevalue}{DW\-\_CFA\-\_same\-\_value} (7)&R7 preserve    \\
1207 cie+34&\livelink{chap:DWCFAregister}{DW\-\_CFA\-\_register} (8, 1)&R8 is in R1    \\
1208 cie+37&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding    \\
1209 cie+38&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}& padding \\
1210 cie+39& \livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding  \\
1211 cie+40 &&  \\
1212 \end{longtable}
1213 \end{centering}
1214
1215
1216 The following notations apply in 
1217 Table \refersec{tab:callframeinformationexampleframedescriptionentryencoding}:
1218
1219 \begin{alltt}
1220 1. <fs> = frame size
1221 2. <caf> = code alignment factor
1222 3. <daf> = data alignment factor
1223 \end{alltt}
1224
1225
1226 \begin{centering}
1227 \setlength{\extrarowheight}{0.1cm}
1228 \begin{longtable}{lll}
1229   \caption{Call frame information example: frame description entry encoding} \label{tab:callframeinformationexampleframedescriptionentryencoding} \\
1230   \hline \\ \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1231 \endfirsthead
1232   \bfseries Address &\bfseries Value &\bfseries Comment \\ \hline
1233 \endhead
1234   \hline \emph{Continued on next page}
1235 \endfoot
1236   \hline
1237 \endlastfoot
1238 fde&40&length \\
1239 fde+4&cie&CIE\_ptr \\
1240 fde+8&foo&initial\_location \\
1241 fde+12&84&address\_range \\
1242 fde+16&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1)&instructions \\
1243 fde+17&\livelink{chap:DWCFAdefcfaoffset}{DW\-\_CFA\-\_def\-\_cfa\-\_offset}(12)& \textless fs \textgreater \\
1244 fde+19&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1)&4/ \textless caf \textgreater \\
1245 fde+20&\livelink{chap:DWCFAoffset}{DW\-\_CFA\-\_offset}(8,1)&-4/ \textless daf \textgreater (second parameter) \\
1246 fde+22&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1)& \\
1247 fde+23&\livelink{chap:DWCFAoffset}{DW\-\_CFA\-\_offset}(6,2)&-8/ \textless daf> \textgreater (2nd parameter)  \\
1248 fde+25&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1249 fde+26&\livelink{chap:DWCFAdefcfaregister}{DW\-\_CFA\-\_def\-\_cfa\-\_register}(6) & \\
1250 fde+28&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1251 fde+29&\livelink{chap:DWCFAoffset}{DW\-\_CFA\-\_offset}(4,3)&-12/ \textless daf \textgreater (2nd parameter) \\
1252 fde+31&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(12)&44/ \textless caf \textgreater \\
1253 fde+32&\livelink{chap:DWCFArestore}{DW\-\_CFA\-\_restore}(4)& \\
1254 fde+33&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1255 fde+34&\livelink{chap:DWCFArestore}{DW\-\_CFA\-\_restore}(6) & \\
1256 fde+35&\livelink{chap:DWCFAdefcfaregister}{DW\-\_CFA\-\_def\-\_cfa\-\_register}(7)  & \\
1257 fde+37&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) & \\
1258 fde+38&\livelink{chap:DWCFArestore}{DW\-\_CFA\-\_restore}(8) &\\
1259 fde+39&\livelink{chap:DWCFAadvanceloc}{DW\-\_CFA\-\_advance\-\_loc}(1) &\\
1260 fde+40&\livelink{chap:DWCFAdefcfaoffset}{DW\-\_CFA\-\_def\-\_cfa\-\_offset}(0)  &\\
1261 fde+42&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding \\
1262 fde+43&\livelink{chap:DWCFAnop}{DW\-\_CFA\-\_nop}&padding \\
1263 fde+44 && \\
1264 \end{longtable}
1265 \end{centering}
1266
1267 \section{Inlining Examples}
1268 \label{app:inliningexamples}
1269 The pseudo\dash source in 
1270 Figure \refersec{fig:inliningexamplespseudosourcefragment}
1271 is used to illustrate the
1272 \addtoindexx{inlined subprogram call!examples}
1273 use of DWARF to describe inlined subroutine calls. This
1274 example involves a nested subprogram INNER that makes uplevel
1275 references to the formal parameter and local variable of the
1276 containing subprogram OUTER.
1277
1278 \begin{figure}[here]
1279 \begin{lstlisting}
1280 inline procedure OUTER (OUTER_FORMAL : integer) =
1281     begin
1282     OUTER_LOCAL : integer;
1283     procedure INNER (INNER_FORMAL : integer) =
1284         begin
1285         INNER_LOCAL : integer;
1286         print(INNER_FORMAL + OUTER_LOCAL);
1287         end;
1288     INNER(OUTER_LOCAL);
1289     ...
1290     INNER(31);
1291     end;
1292 ! Call OUTER
1293 !
1294 OUTER(7);
1295 \end{lstlisting}
1296 \caption{Inlining examples: pseudo-source fragmment} \label{fig:inliningexamplespseudosourcefragment}
1297 \end{figure}
1298
1299
1300 There are several approaches that a compiler might take to
1301 inlining for this sort of example. This presentation considers
1302 three such approaches, all of which involve inline expansion
1303 of subprogram OUTER. (If OUTER is not inlined, the inlining
1304 reduces to a simpler single level subset of the two level
1305 approaches considered here.)
1306
1307 The approaches are:
1308
1309 \begin{itemize}[1.]
1310 \item  Inline both OUTER and INNER in all cases
1311
1312 \item Inline OUTER, multiple INNERs \\
1313 Treat INNER as a non\dash inlinable part of OUTER, compile and
1314 call a distinct normal version of INNER defined within each
1315 inlining of OUTER.
1316
1317 \item Inline OUTER, one INNER \\
1318 Compile INNER as a single normal subprogram which is called
1319 from every inlining of OUTER.
1320 \end{itemize}
1321
1322 This discussion does not consider why a compiler might choose
1323 one of these approaches; it considers only how to describe
1324 the result.
1325
1326 In the examples that follow in this section, the debugging
1327 information entries are given mnemonic labels of the following
1328 form
1329
1330 \begin{lstlisting}
1331 <io>.<ac>.<n>.<s>
1332 \end{lstlisting}
1333
1334 where \begin{verbatim}<io>\end{verbatim}
1335 is either INNER or OUTER to indicate to which
1336 subprogram the debugging information entry applies, 
1337 \begin{verbatim}<ac>\end{verbatim}
1338 is either AI or CI to indicate ``abstract instance'' or
1339 ``concrete instance'' respectively, 
1340 \begin{verbatim}<n>\end{verbatim}
1341 is the number of the
1342 alternative being considered, and 
1343 \begin{verbatim}<s>\end{verbatim}
1344 is a sequence number that
1345 distinguishes the individual entries. There is no implication
1346 that symbolic labels, nor any particular naming convention,
1347 are required in actual use.
1348
1349 For conciseness, declaration coordinates and call coordinates are omitted.
1350
1351 \subsection{Alternative 1: inline both OUTER and INNER}
1352 \label{app:inlinebothouterandinner}
1353
1354 A suitable abstract instance for an alternative where both
1355 OUTER and INNER are always inlined is shown in 
1356 Figure \refersec{app:inliningexample1abstractinstance}
1357
1358 Notice in 
1359 Section \refersec{app:inliningexample1abstractinstance} 
1360 that the debugging information entry for
1361 INNER (labelled INNER.AI.1.1) is nested in (is a child of)
1362 that for OUTER (labelled OUTER.AI.1.1). Nonetheless, the
1363 abstract instance tree for INNER is considered to be separate
1364 and distinct from that for OUTER.
1365
1366 The call of OUTER shown in 
1367 Figure \refersec{fig:inliningexamplespseudosourcefragment}
1368 might be described as
1369 shown in 
1370 Section \refersec{app:inliningexample1concreteinstance}.
1371
1372
1373 \subsubsection{Inlining example \#1: abstract instance}
1374 \label{app:inliningexample1abstractinstance}
1375 \begin{alltt}
1376     ! Abstract instance for OUTER
1377     ! \addtoindexx{abstract instance!example}
1378 OUTER.AI.1.1:
1379     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1380         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1381         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1382         ! No low/high PCs
1383 OUTER.AI.1.2:
1384         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1385             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1386             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1387             ! No location
1388 OUTER.AI.1.3:
1389         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1390             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1391             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1392             ! No location
1393         !
1394         ! Abstract instance for INNER
1395         !
1396 INNER.AI.1.1:
1397         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1398             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1399             \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1400             ! No low/high PCs
1401 INNER.AI.1.2:
1402             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1403                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1404                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1405                 ! No location
1406 INNER.AI.1.3:
1407             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1408                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1409                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1410                 ! No location
1411             ...
1412             0
1413         ! No \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine} (concrete instance)
1414         ! for INNER corresponding to calls of INNER
1415         ...
1416         0
1417 \end{alltt}
1418
1419
1420 \subsubsection{Inlining example \#1: concrete instance}
1421 \label{app:inliningexample1concreteinstance}
1422 \begin{alltt}
1423 ! Concrete instance for call "OUTER(7)"
1424 ! \addtoindexx{concrete instance!example}
1425 OUTER.CI.1.1:
1426     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1427         ! No name
1428         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.1)
1429         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1430         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1431 OUTER.CI.1.2:
1432         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1433             ! No name
1434             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.2)
1435             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(7)
1436 OUTER.CI.1.3:
1437         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1438             ! No name
1439             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.1.3)
1440             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1441         !
1442         ! No \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} (abstract instance) for INNER
1443         !
1444         ! Concrete instance for call INNER(OUTER\_LOCAL)
1445         !
1446 INNER.CI.1.1:
1447         \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1448             ! No name
1449             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.1)
1450             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1451             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1452             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1453 INNER.CI.1.2:
1454             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1455                 ! No name
1456                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.2)
1457                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1458 INNER.CI.1.3:
1459              \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1460                 ! No name
1461                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to INNER.AI.1.3)
1462                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1463             ...
1464             0
1465         ! Another concrete instance of INNER within OUTER
1466         ! for the call "INNER(31)"
1467         ...
1468         0
1469 \end{alltt}
1470
1471 \subsection{Alternative 2: Inline OUTER, multiple INNERs}
1472 \label{app:inlineoutermultiipleinners}
1473
1474
1475 In the second alternative we assume that subprogram INNER
1476 is not inlinable for some reason, but subprogram OUTER is
1477 inlinable. 
1478 \addtoindexx{concrete instance!example}
1479 Each concrete inlined instance of OUTER has its
1480 own normal instance of INNER. 
1481 The abstract instance for OUTER,
1482 \addtoindexx{abstract instance!example}
1483 which includes INNER, is shown in 
1484 Section \refersec{app:inliningexample2abstractinstance}.
1485
1486 Note that the debugging information in this Figure differs from
1487 that in 
1488 Section \refersec{app:inliningexample1abstractinstance}
1489 in that INNER lacks a 
1490 \livelink{chap:DWATinline}{DW\-\_AT\-\_inline} attribute
1491 and therefore is not a distinct abstract instance. INNER
1492 is merely an out\dash of\dash line routine that is part of OUTER’s
1493 abstract instance. This is reflected in the Figure 70 by
1494 \addtoindexx{abstract instance!example}
1495 the fact that the labels for INNER use the substring OUTER
1496 instead of INNER.
1497
1498 A resulting 
1499 \addtoindexx{concrete instance!example}
1500 concrete inlined instance of OUTER is shown in
1501 Section \refersec{app:inliningexample2concreteinstance}.
1502
1503 Notice in 
1504 Section \refersec{app:inliningexample2concreteinstance}.
1505 that OUTER is expanded as a concrete
1506 \addtoindexx{concrete instance!example}
1507 inlined instance, and that INNER is nested within it as a
1508 concrete out\dash of\dash line subprogram. Because INNER is cloned
1509 for each inline expansion of OUTER, only the invariant
1510 attributes of INNER 
1511 (for example, \livelink{chap:DWATname}{DW\-\_AT\-\_name}) are specified
1512 in the abstract instance of OUTER, and the low\dash level,
1513 \addtoindexx{abstract instance!example}
1514 instance\dash specific attributes of INNER (for example,
1515
1516 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}) are specified in 
1517 each concrete instance of OUTER.
1518 \addtoindexx{concrete instance!example}
1519 The several calls of INNER within OUTER are compiled as normal
1520 calls to the instance of INNER that is specific to the same
1521 instance of OUTER that contains the calls.
1522
1523
1524 \subsubsection{Inlining example 2: abstract instance}
1525 \label{app:inliningexample2abstractinstance}
1526 \begin{alltt}
1527     ! Abstract instance for OUTER
1528     ! \addtoindex{abstract instance}
1529 OUTER.AI.2.1:
1530     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1531         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1532         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1533         ! No low/high PCs
1534 OUTER.AI.2.2:
1535         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1536             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1537             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1538             ! No location
1539 OUTER.AI.2.3:
1540         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1541             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1542             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1543             ! No location
1544         !
1545         ! Nested out-of-line INNER subprogram
1546         !
1547 OUTER.AI.2.4:
1548         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1549             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1550             ! No \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}
1551             ! No low/high PCs, frame\_base, etc.
1552 OUTER.AI.2.5:
1553             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1554                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1555                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1556                 ! No location
1557 OUTER.AI.2.6:
1558             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1559                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1560                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1561                 ! No location
1562             ...
1563             0
1564         ...
1565         0
1566 \end{alltt}
1567
1568 \subsubsection{Inlining example 2: concrete instance}
1569 \label{app:inliningexample2concreteinstance}
1570 \begin{alltt}
1571
1572     ! Concrete instance for call "OUTER(7)"
1573     !
1574 OUTER.CI.2.1:
1575     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1576         ! No name
1577         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.1)
1578         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1579         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1580 OUTER.CI.2.2:
1581         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1582             ! No name
1583             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.2)
1584             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1585 OUTER.CI.2.3:
1586         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1587             ! No name
1588             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.3)
1589             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1590         !
1591         ! Nested out-of-line INNER subprogram
1592         !
1593 OUTER.CI.2.4:
1594         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1595             ! No name
1596             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.4)
1597             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1598             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1599             \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1600             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1601 OUTER.CI.2.5:
1602             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1603                 ! No name
1604                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.2.5)
1605                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1606 OUTER.CI.2.6:
1607             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1608                 ! No name
1609                 \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AT.2.6)
1610                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1611             ...
1612             0
1613         ...
1614         0
1615 \end{alltt}
1616
1617 \subsection{Alternative 3: inline OUTER, one normal INNER}
1618 \label{app:inlineouteronenormalinner}
1619
1620 In the third approach, one normal subprogram for INNER is
1621 compiled which is called from all concrete inlined instances of
1622 \addtoindexx{concrete instance!example}
1623 \addtoindexx{abstract instance!example}
1624 OUTER. The abstract instance for OUTER is shown in 
1625 Section \refersec{app:inliningexample3abstractinstance}.
1626
1627 The most distinctive aspect of that Figure is that subprogram
1628 INNER exists only within the abstract instance of OUTER,
1629 and not in OUTER’s concrete instance. In the abstract
1630 \addtoindexx{concrete instance!example}
1631 \addtoindexx{abstract instance!example}
1632 instance of OUTER, the description of INNER has the full
1633 complement of attributes that would be expected for a
1634 normal subprogram. 
1635 While attributes such as 
1636 \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc},
1637 \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}, 
1638 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location},
1639 and so on, typically are omitted
1640 \addtoindexx{high PC attribute}
1641 from 
1642 \addtoindexx{low PC attribute}
1643 an 
1644 \addtoindexx{location attribute}
1645 abstract instance because they are not invariant across
1646 instances of the containing abstract instance, in this case
1647 those same attributes are included precisely because they are
1648 invariant -- there is only one subprogram INNER to be described
1649 and every description is the same.
1650
1651 A concrete inlined instance of OUTER is illustrated in
1652 \refersec{app:inliningexample3concreteinstance}.
1653
1654 Notice in 
1655 \refersec{app:inliningexample3abstractinstance}
1656 that there is no DWARF representation for
1657 INNER at all; the representation of INNER does not vary across
1658 instances of OUTER and the abstract instance of OUTER includes
1659 the complete description of INNER, so that the description of
1660 INNER may be (and for reasons of space efficiency, should be)
1661 omitted from each 
1662 \addtoindexx{concrete instance!example}
1663 concrete instance of OUTER.
1664
1665 There is one aspect of this approach that is problematical from
1666 the DWARF perspective. The single compiled instance of INNER
1667 is assumed to access up\dash level variables of OUTER; however,
1668 those variables may well occur at varying positions within
1669 the frames that contain the 
1670 \addtoindexx{concrete instance!example}
1671 concrete inlined instances. A
1672 compiler might implement this in several ways, including the
1673 use of additional compiler generated parameters that provide
1674 reference parameters for the up\dash level variables, or a compiler
1675 generated static link like parameter that points to the group
1676 of up\dash level entities, among other possibilities. In either of
1677 these cases, the DWARF description for the location attribute
1678 of each uplevel variable needs to be different if accessed
1679 from within INNER compared to when accessed from within the
1680 instances of OUTER. An implementation is likely to require
1681 vendor\dash specific DWARF attributes and/or debugging information
1682 entries to describe such cases.
1683
1684 Note that in C++, a member function of a class defined within
1685 a function definition does not require any vendor\dash specific
1686 extensions because the C++ language disallows access to
1687 entities that would give rise to this problem. (Neither extern
1688 variables nor static members require any form of static link
1689 for accessing purposes.)
1690
1691 \subsubsection{Inlining example 3: abstract instance}
1692 \label{app:inliningexample3abstractinstance}
1693 \begin{alltt}
1694     ! Abstract instance for OUTER
1695     ! \addtoindexx{abstract instance!example}
1696 OUTER.AI.3.1:
1697     \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1698         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER")
1699         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLdeclaredinlined}{DW\-\_INL\-\_declared\-\_inlined})
1700         ! No low/high PCs
1701 OUTER.AI.3.2:
1702         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1703             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_FORMAL")
1704             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1705             ! No location
1706 OUTER.AI.3.3:
1707         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1708             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("OUTER\_LOCAL")
1709             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1710             ! No location
1711         !
1712         ! Normal INNER
1713         !
1714 OUTER.AI.3.4:
1715         \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1716             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER")
1717             \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1718             \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1719             \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1720             \livelink{chap:DWATstaticlink}{DW\-\_AT\-\_static\-\_link}(...)
1721 OUTER.AI.3.5:
1722             \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1723                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_FORMAL")
1724                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1725                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1726 OUTER.AI.3.6:
1727             \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1728                 \livelink{chap:DWATname}{DW\-\_AT\-\_name}("INNER\_LOCAL")
1729                 \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to integer)
1730                 \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1731             ...
1732             0
1733         ...
1734         0
1735 \end{alltt}
1736
1737
1738 \subsubsection{Inlining example 3: concrete instance}
1739 \label{app:inliningexample3concreteinstance}
1740 \begin{alltt}
1741     ! Concrete instance for call "OUTER(7)"
1742     ! \addtoindexx{concrete instance!example}
1743 OUTER.CI.3.1:
1744     \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1745         ! No name
1746         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.1)
1747         \livelink{chap:DWATlowpc}{DW\-\_AT\-\_low\-\_pc}(...)
1748         \livelink{chap:DWAThighpc}{DW\-\_AT\-\_high\-\_pc}(...)
1749         \livelink{chap:DWATframebase}{DW\-\_AT\-\_frame\-\_base}(...)
1750 OUTER.CI.3.2:
1751         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1752             ! No name
1753             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.2)
1754             ! No type
1755             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1756 OUTER.CI.3.3:
1757         \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1758             ! No name
1759             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to OUTER.AI.3.3)
1760             ! No type
1761             \livelink{chap:DWATlocation}{DW\-\_AT\-\_location}(...)
1762         ! No \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} for "INNER"
1763         ...
1764         0
1765 \end{alltt}
1766
1767 \section{Constant Expression Example}
1768 \label{app:constantexpressionexample}
1769 C++ generalizes the notion of constant expressions to include
1770 constant expression user-defined literals and functions.
1771
1772 \begin{figure}[here]
1773 \begin{lstlisting}
1774 constexpr double mass = 9.8;
1775 constexpr int square (int x) { return x * x; }
1776 float arr[square(9)]; // square() called and inlined
1777 \end{lstlisting}
1778 \caption{Constant expressions: C++ source} \label{fig:constantexpressionscsource}
1779 \end{figure}
1780
1781 These declarations can be represented as illustrated in 
1782 Section \refersec{app:constantexpressionsdwarfdescription}.
1783
1784 \subsection{Constant expressions: DWARF description}
1785 \label{app:constantexpressionsdwarfdescription}
1786 \begin{alltt}
1787
1788       ! For variable mass
1789       !
1790 1\$:  \livelink{chap:DWTAGconsttype}{DW\-\_TAG\-\_const\-\_type}
1791         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "double")
1792 2\$:  \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1793         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("mass")
1794         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
1795         \livelink{chap:DWATconstexpr}{DW\-\_AT\-\_const\-\_expr}(true)
1796         \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(9.8)
1797       ! Abstract instance for square
1798       !
1799 10\$: \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1800         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("square")
1801         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1802         \livelink{chap:DWATinline}{DW\-\_AT\-\_inline}(\livelink{chap:DWINLinlined}{DW\-\_INL\-\_inlined})
1803 11\$:   \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1804             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("x")
1805             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1806       ! Concrete instance for square(9)
1807       ! \addtoindexx{concrete instance!example}
1808 20\$: \livelink{chap:DWTAGinlinedsubroutine}{DW\-\_TAG\-\_inlined\-\_subroutine}
1809         \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to 10\$)
1810         \livelink{chap:DWATconstexpr}{DW\-\_AT\-\_const\-\_expr}(present)
1811         \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(81)
1812         \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1813             \livelink{chap:DWATabstractorigin}{DW\-\_AT\-\_abstract\-\_origin}(reference to 11\$)
1814             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(9)
1815       ! Anonymous array type for arr
1816       !
1817 30\$: \livelink{chap:DWTAGarraytype}{DW\-\_TAG\-\_array\-\_type}
1818         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "float")
1819         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(324) ! 81*4
1820         \livelink{chap:DWTAGsubrangetype}{DW\-\_TAG\-\_subrange\-\_type}
1821             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1822             \livelink{chap:DWATupperbound}{DW\-\_AT\-\_upper\-\_bound}(reference to 20\$)
1823       ! Variable arr
1824       !
1825 40\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1826         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("arr")
1827         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
1828 \end{alltt}
1829
1830
1831 \section{Unicode Character Example}
1832 \label{app:unicodecharacterexample}
1833
1834 Unicode character encodings can be described in DWARF as
1835 illustrated in 
1836 Section \refersec{app:unicodecharacterexamplesub}.
1837
1838 \begin{lstlisting}
1839 // C++ source
1840 //
1841 char16_t chr_a = u'h';
1842 char32_t chr_b = U'h';
1843 \end{lstlisting}
1844
1845 \subsection{Unicode Character Example}
1846 \label{app:unicodecharacterexamplesub}
1847 \begin{alltt}
1848
1849 ! DWARF description
1850 !
1851 1\$: \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
1852         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("char16\_t")
1853         \livelink{chap:DWATencoding}{DW\-\_AT\-\_encoding}(\livelink{chap:DWATEUTF}{DW\-\_ATE\-\_UTF})
1854         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(2)
1855 2\$: \livelink{chap:DWTAGbasetype}{DW\-\_TAG\-\_base\-\_type}
1856         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("char32\_t")
1857         \livelink{chap:DWATencoding}{DW\-\_AT\-\_encoding}(\livelink{chap:DWATEUTF}{DW\-\_ATE\-\_UTF})
1858         \livelink{chap:DWATbytesize}{DW\-\_AT\-\_byte\-\_size}(4)
1859 3\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1860         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("chr\_a")
1861         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 1\$)
1862 4\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1863         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("chr\_b")
1864         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 2\$)
1865 \end{alltt}
1866
1867
1868
1869 \section{Type-Safe Enumeration Example}
1870 \label{app:typesafeenumerationexample}
1871
1872
1873 C++ type\dash safe enumerations can be described in DWARF as illustrated in 
1874 Section \refersec{app:ctypesafeenumerationexample}.
1875
1876 \begin{lstlisting}
1877 // C++ source
1878 //
1879 enum class E { E1, E2=100 };
1880 E e1;
1881 \end{lstlisting}
1882
1883 \subsection{C++ type-safe enumeration example}
1884 \label{app:ctypesafeenumerationexample}
1885 \begin{alltt}
1886 ! DWARF description
1887 !
1888 11\$: \livelink{chap:DWTAGenumerationtype}{DW\-\_TAG\-\_enumeration\-\_type}
1889         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E")
1890         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1891         \livelink{chap:DWATenumclass}{DW\-\_AT\-\_enum\-\_class}(present)
1892 12\$:   \livelink{chap:DWTAGenumerator}{DW\-\_TAG\-\_enumerator}
1893             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E1")
1894             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(0)
1895 13\$:
1896          \livelink{chap:DWTAGenumerator}{DW\-\_TAG\-\_enumerator}
1897             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("E2")
1898             \livelink{chap:DWATconstvalue}{DW\-\_AT\-\_const\-\_value}(100)
1899 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1900         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("e1")
1901         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1902 \end{alltt}
1903
1904 \section{Template Example}
1905 \label{app:templateexample}
1906
1907 C++ templates can be described in DWARF as illustrated in 
1908 Section \refersec{app:ctemplateexample1}.
1909
1910
1911
1912 \begin{lstlisting}
1913 // C++ source
1914 //
1915 template<class T>
1916 struct wrapper {
1917     T comp;
1918 };
1919 wrapper<int> obj;
1920 \end{lstlisting}
1921
1922 \subsection{C++ template example 1}
1923 \label{app:ctemplateexample1}
1924 \begin{alltt}
1925 ! DWARF description
1926 !
1927 11\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
1928         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("wrapper")
1929 12\$: \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1930         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
1931         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1932 13\$ \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
1933         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("comp")
1934         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 12\$)
1935 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1936         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("obj")
1937         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1938 \end{alltt}
1939
1940 The actual type of the component comp is int, but in the DWARF
1941 the type references the \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter} for
1942 T, which in turn references int. This implies that in the
1943 original template comp was of type T and that was replaced
1944 with int in the instance.  There exist situations where it is
1945 not possible for the DWARF to imply anything about the nature
1946 of the original template. 
1947
1948 Consider following C++ source and DWARF 
1949 that can describe it in
1950 Section \refersec{app:ctemplateexample2}.
1951
1952
1953 \begin{lstlisting}
1954 // C++ source
1955 //
1956     template<class T>
1957     struct wrapper {
1958         T comp;
1959     };
1960     template<class U>
1961     void consume(wrapper<U> formal)
1962     {
1963         ...
1964     }
1965     wrapper<int> obj;
1966     consume(obj);
1967 \end{lstlisting}
1968
1969 \subsection{C++ template example 2}
1970 \label{app:ctemplateexample2}
1971 \begin{alltt}
1972 ! DWARF description
1973 !
1974 11\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
1975         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("wrapper")
1976 12\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1977             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
1978             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1979 13\$    \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
1980             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("comp")
1981             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 12\$)
1982 14\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
1983         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("obj")
1984         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1985 21\$: \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram}
1986         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("consume")
1987 22\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
1988             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("U")
1989             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
1990 23\$:   \livelink{chap:DWTAGformalparameter}{DW\-\_TAG\-\_formal\-\_parameter}
1991             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("formal")
1992             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 11\$)
1993 \end{alltt}
1994
1995 In the \livelink{chap:DWTAGsubprogram}{DW\-\_TAG\-\_subprogram} entry for the instance of consume,
1996 U is described as 
1997 int. 
1998 The type of formal is 
1999 \begin{alltt}
2000 wrapper<U>
2001 \end{alltt}
2002  in
2003 the source. DWARF only represents instantiations of templates;
2004 there is no entry which represents 
2005 \begin{alltt}
2006 wrapper<U>, 
2007 \end{alltt}
2008 which is neither
2009 a template parameter nor a template instantiation. The type
2010 of formal is described as 
2011 \begin{alltt}
2012 wrapper<int>, 
2013 \end{alltt}
2014 the instantiation of
2015 \begin{alltt}
2016 wrapper<U>, 
2017 \end{alltt}
2018 in the \livelink{chap:DWATtype}{DW\-\_AT\-\_type} attribute at 
2019 23\$. 
2020 There is no
2021 description of the relationship between template type parameter
2022 T at 12\$ and U at 
2023 22\$ which was used to instantiate 
2024 \begin{alltt}
2025 wrapper<U>.
2026 \end{alltt}
2027
2028 A consequence of this is that the DWARF information would
2029 not distinguish between the existing example and one where
2030 the formal of consume were declared in the source to be
2031 \begin{alltt}
2032 wrapper<int>.
2033 \end{alltt}
2034
2035 \section{Template Alias Examples}
2036 \label{app:templatealiasexample}
2037
2038 C++ template aliases can be described in DWARF as illustrated in 
2039 Section \refersec{app:templatealiasexample1}
2040 and 
2041 Section \refersec{app:templatealiasexample2}.
2042
2043
2044 \begin{lstlisting}
2045 // C++ source, template alias example 1
2046 //
2047 template<typename T, typename U>
2048 struct Alpha {
2049     T tango;
2050     U uniform;
2051 };
2052 template<typename V> using Beta = Alpha<V,V>;
2053 Beta<long> b;
2054 \end{lstlisting}
2055
2056
2057 \subsection{template alias example 1}
2058 \label{app:templatealiasexample1}
2059 \begin{alltt}
2060 ! DWARF representation for variable 'b'
2061 !
2062 20\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2063         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Alpha")
2064 21\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2065             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
2066             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2067 22\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2068             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("U")
2069             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2070 23\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
2071             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("tango")
2072             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 21\$)
2073 24\$:   \livelink{chap:DWTAGmember}{DW\-\_TAG\-\_member}
2074             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("uniform")
2075             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 22\$)
2076 25\$: \livelink{chap:DWTAGtemplatealias}{DW\-\_TAG\-\_template\-\_alias}
2077         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Beta")
2078         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 20\$)
2079 26\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2080             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("V")
2081             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "long")
2082 27\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2083         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("b")
2084         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 25\$)
2085 \end{alltt}
2086
2087
2088 \begin{lstlisting}
2089 // C++ source, template alias example 2
2090 //
2091 template<class TX> struct X { };
2092 template<class TY> struct Y { };
2093 template<class T> using Z = Y<T>;
2094 X<Y<int>> y;
2095 X<Z<int>> z;
2096 \end{lstlisting}
2097
2098
2099 \subsection{template alias example 2}
2100 \label{app:templatealiasexample2}
2101 \begin{alltt}
2102 ! DWARF representation for X<Y<int>>
2103 !
2104 30\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2105         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Y")
2106 31\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2107             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TY")
2108             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
2109 32\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2110         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("X")
2111 33\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2112             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TX")
2113             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
2114
2115 ! DWARF representation for X<Z<int>>
2116 !
2117 40\$: \livelink{chap:DWTAGtemplatealias}{DW\-\_TAG\-\_template\-\_alias}
2118 using Z = Y<int>;
2119         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("Z")
2120         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 30\$)
2121 41\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2122             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("T")
2123             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to "int")
2124 42\$: \livelink{chap:DWTAGstructuretype}{DW\-\_TAG\-\_structure\-\_type}
2125         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("X")
2126 43\$:   \livelink{chap:DWTAGtemplatetypeparameter}{DW\-\_TAG\-\_template\-\_type\-\_parameter}
2127             \livelink{chap:DWATname}{DW\-\_AT\-\_name}("TX")
2128             \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to 40\$)
2129 ! Note that 32\$ and 42\$ are actually the same type
2130 !
2131 50\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2132         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("y")
2133         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to \$32)
2134 51\$: \livelink{chap:DWTAGvariable}{DW\-\_TAG\-\_variable}
2135         \livelink{chap:DWATname}{DW\-\_AT\-\_name}("z")
2136         \livelink{chap:DWATtype}{DW\-\_AT\-\_type}(reference to \$42)
2137 \end{alltt}