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