1d4e76214Sopenharmony_ci\documentclass{article}
2d4e76214Sopenharmony_ci\usepackage[fancyhdr,pdf]{latex2man}
3d4e76214Sopenharmony_ci
4d4e76214Sopenharmony_ci\input{common.tex}
5d4e76214Sopenharmony_ci
6d4e76214Sopenharmony_ci\begin{document}
7d4e76214Sopenharmony_ci
8d4e76214Sopenharmony_ci\begin{Name}{3}{libunwind-dynamic}{David Mosberger-Tang}{Programming Library}{Introduction to dynamic unwind-info}libunwind-dynamic -- libunwind-support for runtime-generated code
9d4e76214Sopenharmony_ci\end{Name}
10d4e76214Sopenharmony_ci
11d4e76214Sopenharmony_ci\section{Introduction}
12d4e76214Sopenharmony_ci
13d4e76214Sopenharmony_ciFor \Prog{libunwind} to do its job, it needs to be able to reconstruct
14d4e76214Sopenharmony_cithe \emph{frame state} of each frame in a call-chain.  The frame state
15d4e76214Sopenharmony_cidescribes the subset of the machine-state that consists of the
16d4e76214Sopenharmony_ci\emph{frame registers} (typically the instruction-pointer and the
17d4e76214Sopenharmony_cistack-pointer) and all callee-saved registers (preserved registers).
18d4e76214Sopenharmony_ciThe frame state describes each register either by providing its
19d4e76214Sopenharmony_cicurrent value (for frame registers) or by providing the location at
20d4e76214Sopenharmony_ciwhich the current value is stored (callee-saved registers).
21d4e76214Sopenharmony_ci
22d4e76214Sopenharmony_ciFor statically generated code, the compiler normally takes care of
23d4e76214Sopenharmony_ciemitting \emph{unwind-info} which provides the minimum amount of
24d4e76214Sopenharmony_ciinformation needed to reconstruct the frame-state for each instruction
25d4e76214Sopenharmony_ciin a procedure.  For dynamically generated code, the runtime code
26d4e76214Sopenharmony_cigenerator must use the dynamic unwind-info interface provided by
27d4e76214Sopenharmony_ci\Prog{libunwind} to supply the equivalent information.  This manual
28d4e76214Sopenharmony_cipage describes the format of this information in detail.
29d4e76214Sopenharmony_ci
30d4e76214Sopenharmony_ciFor the purpose of this discussion, a \emph{procedure} is defined to
31d4e76214Sopenharmony_cibe an arbitrary piece of \emph{contiguous} code.  Normally, each
32d4e76214Sopenharmony_ciprocedure directly corresponds to a function in the source-language
33d4e76214Sopenharmony_cibut this is not strictly required.  For example, a runtime
34d4e76214Sopenharmony_cicode-generator could translate a given function into two separate
35d4e76214Sopenharmony_ci(discontiguous) procedures: one for frequently-executed (hot) code and
36d4e76214Sopenharmony_cione for rarely-executed (cold) code.  Similarly, simple
37d4e76214Sopenharmony_cisource-language functions (usually leaf functions) may get translated
38d4e76214Sopenharmony_ciinto code for which the default unwind-conventions apply and for such
39d4e76214Sopenharmony_cicode, it is not strictly necessary to register dynamic unwind-info.
40d4e76214Sopenharmony_ci
41d4e76214Sopenharmony_ciA procedure logically consists of a sequence of \emph{regions}.
42d4e76214Sopenharmony_ciRegions are nested in the sense that the frame state at the end of one
43d4e76214Sopenharmony_ciregion is, by default, assumed to be the frame state for the next
44d4e76214Sopenharmony_ciregion.  Each region is thought of as being divided into a
45d4e76214Sopenharmony_ci\emph{prologue}, a \emph{body}, and an \emph{epilogue}.  Each of them
46d4e76214Sopenharmony_cican be empty.  If non-empty, the prologue sets up the frame state for
47d4e76214Sopenharmony_cithe body.  For example, the prologue may need to allocate some space
48d4e76214Sopenharmony_cion the stack and save certain callee-saved registers.  The body
49d4e76214Sopenharmony_ciperforms the actual work of the procedure but does not change the
50d4e76214Sopenharmony_ciframe state in any way.  If non-empty, the epilogue restores the
51d4e76214Sopenharmony_ciprevious frame state and as such it undoes or cancels the effect of
52d4e76214Sopenharmony_cithe prologue.  In fact, a single epilogue may undo the effect of the
53d4e76214Sopenharmony_ciprologues of several (nested) regions.
54d4e76214Sopenharmony_ci
55d4e76214Sopenharmony_ciWe should point out that even though the prologue, body, and epilogue
56d4e76214Sopenharmony_ciare logically separate entities, optimizing code-generators will
57d4e76214Sopenharmony_cigenerally interleave instructions from all three entities.  For this
58d4e76214Sopenharmony_cireason, the dynamic unwind-info interface of \Prog{libunwind} makes no
59d4e76214Sopenharmony_cidistinction whatsoever between prologue and body.  Similarly, the
60d4e76214Sopenharmony_ciexact set of instructions that make up an epilogue is also irrelevant.
61d4e76214Sopenharmony_ciThe only point in the epilogue that needs to be described explicitly
62d4e76214Sopenharmony_ciby the dynamic unwind-info is the point at which the stack-pointer
63d4e76214Sopenharmony_cigets restored.  The reason this point needs to be described is that
64d4e76214Sopenharmony_cionce the stack-pointer is restored, all values saved in the
65d4e76214Sopenharmony_cideallocated portion of the stack frame become invalid and hence
66d4e76214Sopenharmony_ci\Prog{libunwind} needs to know about it.  The portion of the frame
67d4e76214Sopenharmony_cistate not saved on the stack is assume to remain valid through the end
68d4e76214Sopenharmony_ciof the region.  For this reason, there is usually no need to describe
69d4e76214Sopenharmony_ciinstructions which restore the contents of callee-saved registers.
70d4e76214Sopenharmony_ci
71d4e76214Sopenharmony_ciWithin a region, each instruction that affects the frame state in some
72d4e76214Sopenharmony_cifashion needs to be described with an operation descriptor.  For this
73d4e76214Sopenharmony_cipurpose, each instruction in the region is assigned a unique index.
74d4e76214Sopenharmony_ciExactly how this index is derived depends on the architecture.  For
75d4e76214Sopenharmony_ciexample, on RISC and EPIC-style architecture, instructions have a
76d4e76214Sopenharmony_cifixed size so it's possible to simply number the instructions.  In
77d4e76214Sopenharmony_cicontrast, most CISC use variable-length instruction encodings, so it
78d4e76214Sopenharmony_ciis usually necessary to use a byte-offset as the index.  Given the
79d4e76214Sopenharmony_ciinstruction index, the operation descriptor specifies the effect of
80d4e76214Sopenharmony_cithe instruction in an abstract manner.  For example, it might express
81d4e76214Sopenharmony_cithat the instruction stores calle-saved register \Var{r1} at offset 16
82d4e76214Sopenharmony_ciin the stack frame.
83d4e76214Sopenharmony_ci
84d4e76214Sopenharmony_ci\section{Procedures}
85d4e76214Sopenharmony_ci
86d4e76214Sopenharmony_ciA runtime code-generator registers the dynamic unwind-info of a
87d4e76214Sopenharmony_ciprocedure by setting up a structure of type \Type{unw\_dyn\_info\_t}
88d4e76214Sopenharmony_ciand calling \Func{\_U\_dyn\_register}(), passing the address of the
89d4e76214Sopenharmony_cistructure as the sole argument.  The members of the
90d4e76214Sopenharmony_ci\Type{unw\_dyn\_info\_t} structure are described below:
91d4e76214Sopenharmony_ci\begin{itemize}
92d4e76214Sopenharmony_ci\item[\Type{void~*}next] Private to \Prog{libunwind}.  Must not be used
93d4e76214Sopenharmony_ci  by the application.
94d4e76214Sopenharmony_ci\item[\Type{void~*}prev] Private to \Prog{libunwind}.  Must not be used
95d4e76214Sopenharmony_ci  by the application.
96d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{start\_ip}] The start-address of the
97d4e76214Sopenharmony_ci  instructions of the procedure (remember: procedure are defined to be
98d4e76214Sopenharmony_ci  contiguous pieces of code, so a single code-range is sufficient).
99d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{end\_ip}] The end-address of the
100d4e76214Sopenharmony_ci  instructions of the procedure (non-inclusive, that is,
101d4e76214Sopenharmony_ci  \Var{end\_ip}-\Var{start\_ip} is the size of the procedure in
102d4e76214Sopenharmony_ci  bytes).
103d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{gp}] The global-pointer value in use
104d4e76214Sopenharmony_ci  for this procedure.  The exact meaing of the global-pointer is
105d4e76214Sopenharmony_ci  architecture-specific and on some architecture, it is not used at
106d4e76214Sopenharmony_ci  all.
107d4e76214Sopenharmony_ci\item[\Type{int32\_t} \Var{format}] The format of the unwind-info.
108d4e76214Sopenharmony_ci  This member can be one of \Const{UNW\_INFO\_FORMAT\_DYNAMIC},
109d4e76214Sopenharmony_ci  \Const{UNW\_INFO\_FORMAT\_TABLE}, or
110d4e76214Sopenharmony_ci  \Const{UNW\_INFO\_FORMAT\_REMOTE\_TABLE}.
111d4e76214Sopenharmony_ci\item[\Type{union} \Var{u}] This union contains one sub-member
112d4e76214Sopenharmony_ci  structure for every possible unwind-info format:
113d4e76214Sopenharmony_ci  \begin{description}
114d4e76214Sopenharmony_ci  \item[\Type{unw\_dyn\_proc\_info\_t} \Var{pi}] This member is used
115d4e76214Sopenharmony_ci    for format \Const{UNW\_INFO\_FORMAT\_DYNAMIC}.
116d4e76214Sopenharmony_ci  \item[\Type{unw\_dyn\_table\_info\_t} \Var{ti}] This member is used
117d4e76214Sopenharmony_ci    for format \Const{UNW\_INFO\_FORMAT\_TABLE}.
118d4e76214Sopenharmony_ci  \item[\Type{unw\_dyn\_remote\_table\_info\_t} \Var{rti}] This member
119d4e76214Sopenharmony_ci    is used for format \Const{UNW\_INFO\_FORMAT\_REMOTE\_TABLE}.
120d4e76214Sopenharmony_ci  \end{description}\
121d4e76214Sopenharmony_ci  The format of these sub-members is described in detail below.
122d4e76214Sopenharmony_ci\end{itemize}
123d4e76214Sopenharmony_ci
124d4e76214Sopenharmony_ci\subsection{Proc-info format}
125d4e76214Sopenharmony_ci
126d4e76214Sopenharmony_ciThis is the preferred dynamic unwind-info format and it is generally
127d4e76214Sopenharmony_cithe one used by full-blown runtime code-generators.  In this format,
128d4e76214Sopenharmony_cithe details of a procedure are described by a structure of type
129d4e76214Sopenharmony_ci\Type{unw\_dyn\_proc\_info\_t}.  This structure contains the following
130d4e76214Sopenharmony_cimembers:
131d4e76214Sopenharmony_ci\begin{description}
132d4e76214Sopenharmony_ci
133d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{name\_ptr}] The address of a
134d4e76214Sopenharmony_ci  (human-readable) name of the procedure or 0 if no such name is
135d4e76214Sopenharmony_ci  available.  If non-zero, The string stored at this address must be
136d4e76214Sopenharmony_ci  ASCII NUL terminated.  For source languages that use name-mangling
137d4e76214Sopenharmony_ci  (such as C++ or Java) the string stored at this address should be
138d4e76214Sopenharmony_ci  the \emph{demangled} version of the name.
139d4e76214Sopenharmony_ci
140d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{handler}] The address of the
141d4e76214Sopenharmony_ci  personality-routine for this procedure.  Personality-routines are
142d4e76214Sopenharmony_ci  used in conjunction with exception handling.  See the C++ ABI draft
143d4e76214Sopenharmony_ci  (http://www.codesourcery.com/cxx-abi/) for an overview and a
144d4e76214Sopenharmony_ci  description of the personality routine.  If the procedure has no
145d4e76214Sopenharmony_ci  personality routine, \Var{handler} must be set to 0.
146d4e76214Sopenharmony_ci
147d4e76214Sopenharmony_ci\item[\Type{uint32\_t} \Var{flags}] A bitmask of flags.  At the
148d4e76214Sopenharmony_ci  moment, no flags have been defined and this member must be
149d4e76214Sopenharmony_ci  set to 0.
150d4e76214Sopenharmony_ci
151d4e76214Sopenharmony_ci\item[\Type{unw\_dyn\_region\_info\_t~*}\Var{regions}] A NULL-terminated
152d4e76214Sopenharmony_ci  linked list of region-descriptors.  See section ``Region
153d4e76214Sopenharmony_ci  descriptors'' below for more details.
154d4e76214Sopenharmony_ci
155d4e76214Sopenharmony_ci\end{description}
156d4e76214Sopenharmony_ci
157d4e76214Sopenharmony_ci\subsection{Table-info format}
158d4e76214Sopenharmony_ci
159d4e76214Sopenharmony_ciThis format is generally used when the dynamically generated code was
160d4e76214Sopenharmony_ciderived from static code and the unwind-info for the dynamic and the
161d4e76214Sopenharmony_cistatic versions is identical.  For example, this format can be useful
162d4e76214Sopenharmony_ciwhen loading statically-generated code into an address-space in a
163d4e76214Sopenharmony_cinon-standard fashion (i.e., through some means other than
164d4e76214Sopenharmony_ci\Func{dlopen}()).  In this format, the details of a group of procedures
165d4e76214Sopenharmony_ciis described by a structure of type \Type{unw\_dyn\_table\_info}.
166d4e76214Sopenharmony_ciThis structure contains the following members:
167d4e76214Sopenharmony_ci\begin{description}
168d4e76214Sopenharmony_ci
169d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{name\_ptr}] The address of a
170d4e76214Sopenharmony_ci  (human-readable) name of the procedure or 0 if no such name is
171d4e76214Sopenharmony_ci  available.  If non-zero, The string stored at this address must be
172d4e76214Sopenharmony_ci  ASCII NUL terminated.  For source languages that use name-mangling
173d4e76214Sopenharmony_ci  (such as C++ or Java) the string stored at this address should be
174d4e76214Sopenharmony_ci  the \emph{demangled} version of the name.
175d4e76214Sopenharmony_ci
176d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{segbase}] The segment-base value
177d4e76214Sopenharmony_ci  that needs to be added to the segment-relative values stored in the
178d4e76214Sopenharmony_ci  unwind-info.  The exact meaning of this value is
179d4e76214Sopenharmony_ci  architecture-specific.
180d4e76214Sopenharmony_ci
181d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{table\_len}] The length of the
182d4e76214Sopenharmony_ci  unwind-info (\Var{table\_data}) counted in units of words
183d4e76214Sopenharmony_ci  (\Type{unw\_word\_t}).
184d4e76214Sopenharmony_ci
185d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{table\_data}] A pointer to the actual
186d4e76214Sopenharmony_ci  data encoding the unwind-info.  The exact format is
187d4e76214Sopenharmony_ci  architecture-specific (see architecture-specific sections below).
188d4e76214Sopenharmony_ci
189d4e76214Sopenharmony_ci\end{description}
190d4e76214Sopenharmony_ci
191d4e76214Sopenharmony_ci\subsection{Remote table-info format}
192d4e76214Sopenharmony_ci
193d4e76214Sopenharmony_ciThe remote table-info format has the same basic purpose as the regular
194d4e76214Sopenharmony_citable-info format.  The only difference is that when \Prog{libunwind}
195d4e76214Sopenharmony_ciuses the unwind-info, it will keep the table data in the target
196d4e76214Sopenharmony_ciaddress-space (which may be remote).  Consequently, the type of the
197d4e76214Sopenharmony_ci\Var{table\_data} member is \Type{unw\_word\_t} rather than a pointer.
198d4e76214Sopenharmony_ciThis implies that \Prog{libunwind} will have to access the table-data
199d4e76214Sopenharmony_civia the address-space's \Func{access\_mem}() call-back, rather than
200d4e76214Sopenharmony_cithrough a direct memory reference.
201d4e76214Sopenharmony_ci
202d4e76214Sopenharmony_ciFrom the point of view of a runtime-code generator, the remote
203d4e76214Sopenharmony_citable-info format offers no advantage and it is expected that such
204d4e76214Sopenharmony_cigenerators will describe their procedures either with the proc-info
205d4e76214Sopenharmony_ciformat or the normal table-info format.  The main reason that the
206d4e76214Sopenharmony_ciremote table-info format exists is to enable the
207d4e76214Sopenharmony_ciaddress-space-specific \Func{find\_proc\_info}() callback (see
208d4e76214Sopenharmony_ci\SeeAlso{unw\_create\_addr\_space}(3)) to return unwind tables whose
209d4e76214Sopenharmony_cidata remains in remote memory.  This can speed up unwinding (e.g., for
210d4e76214Sopenharmony_cia debugger) because it reduces the amount of data that needs to be
211d4e76214Sopenharmony_ciloaded from remote memory.
212d4e76214Sopenharmony_ci
213d4e76214Sopenharmony_ci\section{Regions descriptors}
214d4e76214Sopenharmony_ci
215d4e76214Sopenharmony_ciA region descriptor is a variable length structure that describes how
216d4e76214Sopenharmony_cieach instruction in the region affects the frame state.  Of course,
217d4e76214Sopenharmony_cimost instructions in a region usualy do not change the frame state and
218d4e76214Sopenharmony_cifor those, nothing needs to be recorded in the region descriptor.  A
219d4e76214Sopenharmony_ciregion descriptor is a structure of type
220d4e76214Sopenharmony_ci\Type{unw\_dyn\_region\_info\_t} and has the following members:
221d4e76214Sopenharmony_ci\begin{description}
222d4e76214Sopenharmony_ci\item[\Type{unw\_dyn\_region\_info\_t~*}\Var{next}] A pointer to the
223d4e76214Sopenharmony_ci  next region.  If this is the last region, \Var{next} is \Const{NULL}.
224d4e76214Sopenharmony_ci\item[\Type{int32\_t} \Var{insn\_count}] The length of the region in
225d4e76214Sopenharmony_ci  instructions.  Each instruction is assumed to have a fixed size (see
226d4e76214Sopenharmony_ci  architecture-specific sections for details).  The value of
227d4e76214Sopenharmony_ci  \Var{insn\_count} may be negative in the last region of a procedure
228d4e76214Sopenharmony_ci  (i.e., it may be negative only if \Var{next} is \Const{NULL}).  A
229d4e76214Sopenharmony_ci  negative value indicates that the region covers the last \emph{N}
230d4e76214Sopenharmony_ci  instructions of the procedure, where \emph{N} is the absolute value
231d4e76214Sopenharmony_ci  of \Var{insn\_count}.
232d4e76214Sopenharmony_ci\item[\Type{uint32\_t} \Var{op\_count}] The (allocated) length of
233d4e76214Sopenharmony_ci  the \Var{op\_count} array.
234d4e76214Sopenharmony_ci\item[\Type{unw\_dyn\_op\_t} \Var{op}] An array of dynamic unwind
235d4e76214Sopenharmony_ci  directives.  See Section ``Dynamic unwind directives'' for a
236d4e76214Sopenharmony_ci  description of the directives.
237d4e76214Sopenharmony_ci\end{description}
238d4e76214Sopenharmony_ciA region descriptor with an \Var{insn\_count} of zero is an
239d4e76214Sopenharmony_ci\emph{empty region} and such regions are perfectly legal.  In fact,
240d4e76214Sopenharmony_ciempty regions can be useful to establish a particular frame state
241d4e76214Sopenharmony_cibefore the start of another region.
242d4e76214Sopenharmony_ci
243d4e76214Sopenharmony_ciA single region list can be shared across multiple procedures provided
244d4e76214Sopenharmony_cithose procedures share a common prologue and epilogue (their bodies
245d4e76214Sopenharmony_cimay differ, of course).  Normally, such procedures consist of a canned
246d4e76214Sopenharmony_ciprologue, the body, and a canned epilogue.  This could be described by
247d4e76214Sopenharmony_citwo regions: one covering the prologue and one covering the epilogue.
248d4e76214Sopenharmony_ciSince the body length is variable, the latter region would need to
249d4e76214Sopenharmony_cispecify a negative value in \Var{insn\_count} such that
250d4e76214Sopenharmony_ci\Prog{libunwind} knows that the region covers the end of the procedure
251d4e76214Sopenharmony_ci(up to the address specified by \Var{end\_ip}).
252d4e76214Sopenharmony_ci
253d4e76214Sopenharmony_ciThe region descriptor is a variable length structure to make it
254d4e76214Sopenharmony_cipossible to allocate all the necessary memory with a single
255d4e76214Sopenharmony_cimemory-allocation request.  To facilitate the allocation of a region
256d4e76214Sopenharmony_cidescriptors \Prog{libunwind} provides a helper routine with the
257d4e76214Sopenharmony_cifollowing synopsis:
258d4e76214Sopenharmony_ci
259d4e76214Sopenharmony_ci\noindent
260d4e76214Sopenharmony_ci\Type{size\_t} \Func{\_U\_dyn\_region\_size}(\Type{int} \Var{op\_count});
261d4e76214Sopenharmony_ci
262d4e76214Sopenharmony_ciThis routine returns the number of bytes needed to hold a region
263d4e76214Sopenharmony_cidescriptor with space for \Var{op\_count} unwind directives.  Note
264d4e76214Sopenharmony_cithat the length of the \Var{op} array does not have to match exactly
265d4e76214Sopenharmony_ciwith the number of directives in a region.  Instead, it is sufficient
266d4e76214Sopenharmony_ciif the \Var{op} array contains at least as many entries as there are
267d4e76214Sopenharmony_cidirectives, since the end of the directives can always be indicated
268d4e76214Sopenharmony_ciwith the \Const{UNW\_DYN\_STOP} directive.
269d4e76214Sopenharmony_ci
270d4e76214Sopenharmony_ci\section{Dynamic unwind directives}
271d4e76214Sopenharmony_ci
272d4e76214Sopenharmony_ciA dynamic unwind directive describes how the frame state changes
273d4e76214Sopenharmony_ciat a particular point within a region.  The description is in
274d4e76214Sopenharmony_cithe form of a structure of type \Type{unw\_dyn\_op\_t}.  This
275d4e76214Sopenharmony_cistructure has the following members:
276d4e76214Sopenharmony_ci\begin{description}
277d4e76214Sopenharmony_ci\item[\Type{int8\_t} \Var{tag}] The operation tag.  Must be one
278d4e76214Sopenharmony_ci  of the \Type{unw\_dyn\_operation\_t} values described below.
279d4e76214Sopenharmony_ci\item[\Type{int8\_t} \Var{qp}] The qualifying predicate that controls
280d4e76214Sopenharmony_ci  whether or not this directive is active.  This is useful for
281d4e76214Sopenharmony_ci  predicated architecturs such as IA-64 or ARM, where the contents of
282d4e76214Sopenharmony_ci  another (callee-saved) register determines whether or not an
283d4e76214Sopenharmony_ci  instruction is executed (takes effect).  If the directive is always
284d4e76214Sopenharmony_ci  active, this member should be set to the manifest constant
285d4e76214Sopenharmony_ci  \Const{\_U\_QP\_TRUE} (this constant is defined for all
286d4e76214Sopenharmony_ci  architectures, predicated or not).
287d4e76214Sopenharmony_ci\item[\Type{int16\_t} \Var{reg}] The number of the register affected
288d4e76214Sopenharmony_ci  by the instruction.
289d4e76214Sopenharmony_ci\item[\Type{int32\_t} \Var{when}] The region-relative number of
290d4e76214Sopenharmony_ci  the instruction to which this directive applies.  For example,
291d4e76214Sopenharmony_ci  a value of 0 means that the effect described by this directive
292d4e76214Sopenharmony_ci  has taken place once the first instruction in the region has
293d4e76214Sopenharmony_ci  executed.
294d4e76214Sopenharmony_ci\item[\Type{unw\_word\_t} \Var{val}] The value to be applied by the
295d4e76214Sopenharmony_ci  operation tag.  The exact meaning of this value varies by tag.  See
296d4e76214Sopenharmony_ci  Section ``Operation tags'' below.
297d4e76214Sopenharmony_ci\end{description}
298d4e76214Sopenharmony_ciIt is perfectly legitimate to specify multiple dynamic unwind
299d4e76214Sopenharmony_cidirectives with the same \Var{when} value, if a particular instruction
300d4e76214Sopenharmony_cihas a complex effect on the frame state.
301d4e76214Sopenharmony_ci
302d4e76214Sopenharmony_ciEmpty regions by definition contain no actual instructions and as such
303d4e76214Sopenharmony_cithe directives are not tied to a particular instruction.  By
304d4e76214Sopenharmony_ciconvention, the \Var{when} member should be set to 0, however.
305d4e76214Sopenharmony_ci
306d4e76214Sopenharmony_ciThere is no need for the dynamic unwind directives to appear
307d4e76214Sopenharmony_ciin order of increasing \Var{when} values.  If the directives happen to
308d4e76214Sopenharmony_cibe sorted in that order, it may result in slightly faster execution,
309d4e76214Sopenharmony_cibut a runtime code-generator should not go to extra lengths just to
310d4e76214Sopenharmony_ciensure that the directives are sorted.
311d4e76214Sopenharmony_ci
312d4e76214Sopenharmony_ciIMPLEMENTATION NOTE: should \Prog{libunwind} implementations for
313d4e76214Sopenharmony_cicertain architectures prefer the list of unwind directives to be
314d4e76214Sopenharmony_cisorted, it is recommended that such implementations first check
315d4e76214Sopenharmony_ciwhether the list happens to be sorted already and, if not, sort the
316d4e76214Sopenharmony_cidirectives explicitly before the first use.  With this approach, the
317d4e76214Sopenharmony_cioverhead of explicit sorting is only paid when there is a real benefit
318d4e76214Sopenharmony_ciand if the runtime code-generator happens to generated sorted lists
319d4e76214Sopenharmony_cinaturally, the performance penalty is limited to a simple O(N) check.
320d4e76214Sopenharmony_ci
321d4e76214Sopenharmony_ci\subsection{Operations tags}
322d4e76214Sopenharmony_ci
323d4e76214Sopenharmony_ciThe possible operation tags are defined by enumeration type
324d4e76214Sopenharmony_ci\Type{unw\_dyn\_operation\_t} which defines the following
325d4e76214Sopenharmony_civalues:
326d4e76214Sopenharmony_ci\begin{description}
327d4e76214Sopenharmony_ci
328d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_STOP}] Marks the end of the dynamic unwind
329d4e76214Sopenharmony_ci  directive list.  All remaining entries in the \Var{op} array of the
330d4e76214Sopenharmony_ci  region-descriptor are ignored.  This tag is guaranteed to have a
331d4e76214Sopenharmony_ci  value of 0.
332d4e76214Sopenharmony_ci
333d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_SAVE\_REG}] Marks an instruction which saves
334d4e76214Sopenharmony_ci  register \Var{reg} to register \Var{val}.
335d4e76214Sopenharmony_ci
336d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_SPILL\_FP\_REL}] Marks an instruction which
337d4e76214Sopenharmony_ci  spills register \Var{reg} to a frame-pointer-relative location.  The
338d4e76214Sopenharmony_ci  frame-pointer-relative offset is given by the value stored in member
339d4e76214Sopenharmony_ci  \Var{val}.  See the architecture-specific sections for a description
340d4e76214Sopenharmony_ci  of the stack frame layout.
341d4e76214Sopenharmony_ci
342d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_SPILL\_SP\_REL}] Marks an instruction which
343d4e76214Sopenharmony_ci  spills register \Var{reg} to a stack-pointer-relative location.  The
344d4e76214Sopenharmony_ci  stack-pointer-relative offset is given by the value stored in member
345d4e76214Sopenharmony_ci  \Var{val}.  See the architecture-specific sections for a description
346d4e76214Sopenharmony_ci  of the stack frame layout.
347d4e76214Sopenharmony_ci
348d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_ADD}] Marks an instruction which adds
349d4e76214Sopenharmony_ci  the constant value \Var{val} to register \Var{reg}.  To add subtract
350d4e76214Sopenharmony_ci  a constant value, store the two's-complement of the value in
351d4e76214Sopenharmony_ci  \Var{val}.  The set of registers that can be specified for this tag
352d4e76214Sopenharmony_ci  is described in the architecture-specific sections below.
353d4e76214Sopenharmony_ci
354d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_POP\_FRAMES}]
355d4e76214Sopenharmony_ci
356d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_LABEL\_STATE}]
357d4e76214Sopenharmony_ci
358d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_COPY\_STATE}]
359d4e76214Sopenharmony_ci
360d4e76214Sopenharmony_ci\item[\Const{UNW\_DYN\_ALIAS}]
361d4e76214Sopenharmony_ci
362d4e76214Sopenharmony_ci\end{description}
363d4e76214Sopenharmony_ci
364d4e76214Sopenharmony_ciunw\_dyn\_op\_t
365d4e76214Sopenharmony_ci
366d4e76214Sopenharmony_ci\_U\_dyn\_op\_save\_reg();
367d4e76214Sopenharmony_ci\_U\_dyn\_op\_spill\_fp\_rel();
368d4e76214Sopenharmony_ci\_U\_dyn\_op\_spill\_sp\_rel();
369d4e76214Sopenharmony_ci\_U\_dyn\_op\_add();
370d4e76214Sopenharmony_ci\_U\_dyn\_op\_pop\_frames();
371d4e76214Sopenharmony_ci\_U\_dyn\_op\_label\_state();
372d4e76214Sopenharmony_ci\_U\_dyn\_op\_copy\_state();
373d4e76214Sopenharmony_ci\_U\_dyn\_op\_alias();
374d4e76214Sopenharmony_ci\_U\_dyn\_op\_stop();
375d4e76214Sopenharmony_ci
376d4e76214Sopenharmony_ci\section{IA-64 specifics}
377d4e76214Sopenharmony_ci
378d4e76214Sopenharmony_ci- meaning of segbase member in table-info/table-remote-info format
379d4e76214Sopenharmony_ci- format of table\_data in table-info/table-remote-info format
380d4e76214Sopenharmony_ci- instruction size: each bundle is counted as 3 instructions, regardless
381d4e76214Sopenharmony_ci  of template (MLX)
382d4e76214Sopenharmony_ci- describe stack-frame layout, especially with regards to sp-relative
383d4e76214Sopenharmony_ci  and fp-relative addressing
384d4e76214Sopenharmony_ci- UNW\_DYN\_ADD can only add to ``sp'' (always a negative value); use
385d4e76214Sopenharmony_ci  POP\_FRAMES otherwise
386d4e76214Sopenharmony_ci
387d4e76214Sopenharmony_ci\section{See Also}
388d4e76214Sopenharmony_ci
389d4e76214Sopenharmony_ci\SeeAlso{libunwind(3)},
390d4e76214Sopenharmony_ci\SeeAlso{\_U\_dyn\_register(3)},
391d4e76214Sopenharmony_ci\SeeAlso{\_U\_dyn\_cancel(3)}
392d4e76214Sopenharmony_ci
393d4e76214Sopenharmony_ci\section{Author}
394d4e76214Sopenharmony_ci
395d4e76214Sopenharmony_ci\noindent
396d4e76214Sopenharmony_ciDavid Mosberger-Tang\\
397d4e76214Sopenharmony_ciEmail: \Email{dmosberger@gmail.com}\\
398d4e76214Sopenharmony_ciWWW: \URL{http://www.nongnu.org/libunwind/}.
399d4e76214Sopenharmony_ci\LatexManEnd
400d4e76214Sopenharmony_ci
401d4e76214Sopenharmony_ci\end{document}
402