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