blob: 3aeb5b8583e7eb79b674473f066b7c5a62ac4b72 [file] [log] [blame]
mostang.com!davidmf18f14e2003-12-10 07:14:38 +00001'\" t
mostang.com!davidmf6158812003-12-21 07:21:28 +00002.\" Manual page created with latex2man on Sat Dec 20 22:00:11 PST 2003
mostang.com!davidmf18f14e2003-12-10 07:14:38 +00003.\" NOTE: This file is generated, DO NOT EDIT.
4.de Vb
5.ft CW
6.nf
7..
8.de Ve
9.ft R
10
11.fi
12..
mostang.com!davidmf6158812003-12-21 07:21:28 +000013.TH "LIBUNWIND\-DYNAMIC" "3" "20 December 2003" "Programming Library " "Programming Library "
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000014.SH NAME
15libunwind\-dynamic
16\-\- libunwind\-support for runtime\-generated code
17.PP
18.SH INTRODUCTION
19
20.PP
21For libunwind
mostang.com!davidmf6158812003-12-21 07:21:28 +000022to do its job, it needs to be able to reconstruct
23the \fIframe state\fP
24of each frame in a call\-chain. The frame state
25describes the subset of the machine\-state that consists of the
26\fIframe registers\fP
27(typically the instruction\-pointer and the
28stack\-pointer) and all callee\-saved registers (preserved registers).
29The frame state describes each register either by providing its
30current value (for frame registers) or by providing the location at
31which the current value is stored (callee\-saved registers).
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000032.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +000033For statically generated code, the compiler normally takes care of
34emitting \fIunwind\-info\fP
35which provides the minimum amount of
36information needed to reconstruct the frame\-state for each instruction
37in a procedure. For dynamically generated code, the runtime code
38generator must use the dynamic unwind\-info interface provided by
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000039libunwind
mostang.com!davidmf6158812003-12-21 07:21:28 +000040to supply the equivalent information. This manual
41page describes the format of this information in detail.
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000042.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +000043For the purpose of this discussion, a \fIprocedure\fP
44is defined to
45be an arbitrary piece of \fIcontiguous\fP
46code. Normally, each
47procedure directly corresponds to a function in the source\-language
48but this is not strictly required. For example, a runtime
49code\-generator could translate a given function into two separate
50(discontiguous) procedures: one for frequently\-executed (hot) code and
51one for rarely\-executed (cold) code. Similarly, simple
52source\-language functions (usually leaf functions) may get translated
53into code for which the default unwind\-conventions apply and for such
54code, it is not strictly necessary to register dynamic unwind\-info.
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000055.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +000056A procedure logically consists of a sequence of \fIregions\fP\&.
57Regions are nested in the sense that the frame state at the end of one
58region is, by default, assumed to be the frame state for the next
59region. Each region is thought of as being divided into a
60\fIprologue\fP,
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000061a \fIbody\fP,
mostang.com!davidmf6158812003-12-21 07:21:28 +000062and an \fIepilogue\fP\&.
63Each of them
64can be empty. If non\-empty, the prologue sets up the frame state for
65the body. For example, the prologue may need to allocate some space
66on the stack and save certain callee\-saved registers. The body
67performs the actual work of the procedure but does not change the
68frame state in any way. If non\-empty, the epilogue restores the
69previous frame state and as such it undoes or cancels the effect of
70the prologue. In fact, a single epilogue may undo the effect of the
71prologues of several (nested) regions.
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000072.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +000073We should point out that even though the prologue, body, and epilogue
74are logically separate entities, optimizing code\-generators will
75generally interleave instructions from all three entities. For this
76reason, the dynamic unwind\-info interface of libunwind
77makes no
78distinction whatsoever between prologue and body. Similarly, the
79exact set of instructions that make up an epilogue is also irrelevant.
80The only point in the epilogue that needs to be described explicitly
81by the dynamic unwind\-info is the point at which the stack\-pointer
82gets restored. The reason this point needs to be described is that
83once the stack\-pointer is restored, all values saved in the
84deallocated portion of the stack frame become invalid and hence
85libunwind
86needs to know about it. The portion of the frame
87state not saved on the stack is assume to remain valid through the end
88of the region. For this reason, there is usually no need to describe
89instructions which restore the contents of callee\-saved registers.
mostang.com!davidmf18f14e2003-12-10 07:14:38 +000090.PP
91Within a region, each instruction that affects the frame state in some
92fashion needs to be described with an operation descriptor. For this
93purpose, each instruction in the region is assigned a unique index.
94Exactly how this index is derived depends on the architecture. For
95example, on RISC and EPIC\-style architecture, instructions have a
96fixed size so it\&'s possible to simply number the instructions. In
97contrast, most CISC use variable\-length instruction encodings, so it
98is usually necessary to use a byte\-offset as the index. Given the
99instruction index, the operation descriptor specifies the effect of
100the instruction in an abstract manner. For example, it might express
101that the instruction stores calle\-saved register r1
102at offset 16
103in the stack frame.
104.PP
105.SH PROCEDURES
106
107.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +0000108A runtime code\-generator registers the dynamic unwind\-info of a
109procedure by setting up a structure of type unw_dyn_info_t
110and calling _U_dyn_register(),
111passing the address of the
112structure as the sole argument. The members of the
113unw_dyn_info_t
114structure are described below:
115.TP
116void *next
117 Private to libunwind\&.
118Must not be used
119by the application.
120.TP
121void *prev
122 Private to libunwind\&.
123Must not be used
124by the application.
125.TP
126unw_word_t start_ip
127 The start\-address of the
128instructions of the procedure (remember: procedure are defined to be
129contiguous pieces of code, so a single code\-range is sufficient).
130.TP
131unw_word_t end_ip
132 The end\-address of the
133instructions of the procedure (non\-inclusive, that is,
134end_ip\-start_ip
135is the size of the procedure in
136bytes).
137.TP
138unw_word_t gp
139 The global\-pointer value in use
140for this procedure. The exact meaing of the global\-pointer is
141architecture\-specific and on some architecture, it is not used at
142all.
143.TP
144int32_t format
145 The format of the unwind\-info.
146This member can be one of UNW_INFO_FORMAT_DYNAMIC,
147UNW_INFO_FORMAT_TABLE,
148or
149UNW_INFO_FORMAT_REMOTE_TABLE\&.
150.TP
151union u
152 This union contains one sub\-member
153structure for every possible unwind\-info format:
154.RS
155.TP
156unw_dyn_proc_info_t pi
157 This member is used
158for format UNW_INFO_FORMAT_DYNAMIC\&.
159.TP
160unw_dyn_table_info_t ti
161 This member is used
162for format UNW_INFO_FORMAT_TABLE\&.
163.TP
164unw_dyn_remote_table_info_t rti
165 This member
166is used for format UNW_INFO_FORMAT_REMOTE_TABLE\&.
167.RE
168.RS
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000169.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +0000170The format of these sub\-members is described in detail below.
171.RE
172.PP
173.SS PROC\-INFO FORMAT
174.PP
175This is the preferred dynamic unwind\-info format and it is generally
176the one used by full\-blown runtime code\-generators. In this format,
177the details of a procedure are described by a structure of type
178unw_dyn_proc_info_t\&.
179This structure contains the following
180members:
181.PP
182.RE
183.TP
184unw_word_t name_ptr
185 The address of a
186(human\-readable) name of the procedure or 0 if no such name is
187available. If non\-zero, The string stored at this address must be
188ASCII NUL terminated. For source languages that use name\-mangling
189(such as C++ or Java) the string stored at this address should be
190the \fIdemangled\fP
191version of the name.
192.PP
193.TP
194unw_word_t handler
195 The address of the
196personality\-routine for this procedure. Personality\-routines are
197used in conjunction with exception handling. See the C++ ABI draft
198(http://www.codesourcery.com/cxx\-abi/) for an overview and a
199description of the personality routine. If the procedure has no
200personality routine, handler
201must be set to 0.
202.PP
203.TP
204uint32_t flags
205 A bitmask of flags. At the
206moment, no flags have been defined and this member must be
207set to 0.
208.PP
209.TP
210unw_dyn_region_info_t *regions
211 A NULL\-terminated
212linked list of region\-descriptors. See section ``Region
213descriptors\&'' below for more details.
214.PP
215.SS TABLE\-INFO FORMAT
216.PP
217This format is generally used when the dynamically generated code was
218derived from static code and the unwind\-info for the dynamic and the
219static versions is identical. For example, this format can be useful
220when loading statically\-generated code into an address\-space in a
221non\-standard fashion (i.e., through some means other than
222dlopen()).
223In this format, the details of a group of procedures
224is described by a structure of type unw_dyn_table_info\&.
225This structure contains the following members:
226.PP
227.TP
228unw_word_t name_ptr
229 The address of a
230(human\-readable) name of the procedure or 0 if no such name is
231available. If non\-zero, The string stored at this address must be
232ASCII NUL terminated. For source languages that use name\-mangling
233(such as C++ or Java) the string stored at this address should be
234the \fIdemangled\fP
235version of the name.
236.PP
237.TP
238unw_word_t segbase
239 The segment\-base value
240that needs to be added to the segment\-relative values stored in the
241unwind\-info. The exact meaning of this value is
242architecture\-specific.
243.PP
244.TP
245unw_word_t table_len
246 The length of the
247unwind\-info (table_data)
248counted in units of words
249(unw_word_t).
250.PP
251.TP
252unw_word_t table_data
253 A pointer to the actual
254data encoding the unwind\-info. The exact format is
255architecture\-specific (see architecture\-specific sections below).
256.PP
257.SS REMOTE TABLE\-INFO FORMAT
258.PP
259The remote table\-info format has the same basic purpose as the regular
260table\-info format. The only difference is that when libunwind
261uses the unwind\-info, it will keep the table data in the target
262address\-space (which may be remote). Consequently, the type of the
263table_data
264member is unw_word_t
265rather than a pointer.
266This implies that libunwind
267will have to access the table\-data
268via the address\-space\&'s access_mem()
269call\-back, rather than
270through a direct memory reference.
271.PP
272From the point of view of a runtime\-code generator, the remote
273table\-info format offers no advantage and it is expected that such
274generators will describe their procedures either with the proc\-info
275format or the normal table\-info format. The main reason that the
276remote table\-info format exists is to enable the
277address\-space\-specific find_proc_info()
278callback (see
279unw_create_addr_space(3))
280to return unwind tables whose
281data remains in remote memory. This can speed up unwinding (e.g., for
282a debugger) because it reduces the amount of data that needs to be
283loaded from remote memory.
284.PP
285.SH REGIONS DESCRIPTORS
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000286
287.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +0000288A region descriptor is a variable length structure that describes how
289each instruction in the region affects the frame state. Of course,
290most instructions in a region usualy do not change the frame state and
291for those, nothing needs to be recorded in the region descriptor. A
292region descriptor is a structure of type
293unw_dyn_region_info_t
294and has the following members:
295.TP
296unw_dyn_region_info_t *next
297 A pointer to the
298next region. If this is the last region, next
299is NULL\&.
300.TP
301int32_t insn_count
302 The length of the region in
303instructions. Each instruction is assumed to have a fixed size (see
304architecture\-specific sections for details). The value of
305insn_count
306may be negative in the last region of a procedure
307(i.e., it may be negative only if next
308is NULL).
309A
310negative value indicates that the region covers the last \fIN\fP
311instructions of the procedure, where \fIN\fP
312is the absolute value
313of insn_count\&.
314.TP
315uint32_t op_count
316 The (allocated) length of
317the op_count
318array.
319.TP
320unw_dyn_op_t op
321 An array of dynamic unwind
322directives. See Section ``Dynamic unwind directives\&'' for a
323description of the directives.
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000324.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +0000325A region descriptor with an insn_count
326of zero is an
327\fIempty region\fP
328and such regions are perfectly legal. In fact,
329empty regions can be useful to establish a particular frame state
330before the start of another region.
331.PP
332A single region list can be shared across multiple procedures provided
333those procedures share a common prologue and epilogue (their bodies
334may differ, of course). Normally, such procedures consist of a canned
335prologue, the body, and a canned epilogue. This could be described by
336two regions: one covering the prologue and one covering the epilogue.
337Since the body length is variable, the latter region would need to
338specify a negative value in insn_count
339such that
340libunwind
341knows that the region covers the end of the procedure
342(up to the address specified by end_ip).
343.PP
344The region descriptor is a variable length structure to make it
345possible to allocate all the necessary memory with a single
346memory\-allocation request. To facilitate the allocation of a region
347descriptors libunwind
348provides a helper routine with the
349following synopsis:
350.PP
351size_t
352_U_dyn_region_size(int
353op_count);
354.PP
355This routine returns the number of bytes needed to hold a region
356descriptor with space for op_count
357unwind directives. Note
358that the length of the op
359array does not have to match exactly
360with the number of directives in a region. Instead, it is sufficient
361if the op
362array contains at least as many entries as there are
363directives, since the end of the directives can always be indicated
364with the UNW_DYN_STOP
365directive.
366.PP
367.SH DYNAMIC UNWIND DIRECTIVES
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000368
369.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +0000370A dynamic unwind directive describes how the frame state changes
371at a particular point within a region. The description is in
372the form of a structure of type unw_dyn_op_t\&.
373This
374structure has the following members:
375.TP
376int8_t tag
377 The operation tag. Must be one
378of the unw_dyn_operation_t
379values described below.
380.TP
381int8_t qp
382 The qualifying predicate that controls
383whether or not this directive is active. This is useful for
384predicated architecturs such as IA\-64 or ARM, where the contents of
385another (callee\-saved) register determines whether or not an
386instruction is executed (takes effect). If the directive is always
387active, this member should be set to the manifest constant
388_U_QP_TRUE
389(this constant is defined for all
390architectures, predicated or not).
391.TP
392int16_t reg
393 The number of the register affected
394by the instruction.
395.TP
396int32_t when
397 The region\-relative number of
398the instruction to which this directive applies. For example,
399a value of 0 means that the effect described by this directive
400has taken place once the first instruction in the region has
401executed.
402.TP
403unw_word_t val
404 The value to be applied by the
405operation tag. The exact meaning of this value varies by tag. See
406Section ``Operation tags\&'' below.
407.PP
408It is perfectly legitimate to specify multiple dynamic unwind
409directives with the same when
410value, if a particular instruction
411has a complex effect on the frame state.
412.PP
413Empty regions by definition contain no actual instructions and as such
414the directives are not tied to a particular instruction. By
415convention, the when
416member should be set to 0, however.
417.PP
418There is no need for the dynamic unwind directives to appear
419in order of increasing when
420values. If the directives happen to
421be sorted in that order, it may result in slightly faster execution,
422but a runtime code\-generator should not go to extra lengths just to
423ensure that the directives are sorted.
424.PP
425IMPLEMENTATION NOTE: should libunwind
426implementations for
427certain architectures prefer the list of unwind directives to be
428sorted, it is recommended that such implementations first check
429whether the list happens to be sorted already and, if not, sort the
430directives explicitly before the first use. With this approach, the
431overhead of explicit sorting is only paid when there is a real benefit
432and if the runtime code\-generator happens to generated sorted lists
433naturally, the performance penalty is limited to a simple O(N) check.
434.PP
435.SS OPERATIONS TAGS
436.PP
437The possible operation tags are defined by enumeration type
438unw_dyn_operation_t
439which defines the following
440values:
441.PP
442.TP
443UNW_DYN_STOP
444 Marks the end of the dynamic unwind
445directive list. All remaining entries in the op
446array of the
447region\-descriptor are ignored. This tag is guaranteed to have a
448value of 0.
449.PP
450.TP
451UNW_DYN_SAVE_REG
452 Marks an instruction which saves
453register reg
454to register val\&.
455.PP
456.TP
457UNW_DYN_SPILL_FP_REL
458 Marks an instruction which
459spills register reg
460to a frame\-pointer\-relative location. The
461frame\-pointer\-relative offset is given by the value stored in member
462val\&.
463See the architecture\-specific sections for a description
464of the stack frame layout.
465.PP
466.TP
467UNW_DYN_SPILL_SP_REL
468 Marks an instruction which
469spills register reg
470to a stack\-pointer\-relative location. The
471stack\-pointer\-relative offset is given by the value stored in member
472val\&.
473See the architecture\-specific sections for a description
474of the stack frame layout.
475.PP
476.TP
477UNW_DYN_ADD
478 Marks an instruction which adds
479the constant value val
480to register reg\&.
481To add subtract
482a constant value, store the two\&'s\-complement of the value in
483val\&.
484The set of registers that can be specified for this tag
485is described in the architecture\-specific sections below.
486.PP
487.TP
488UNW_DYN_POP_FRAMES
489 .PP
490.TP
491UNW_DYN_LABEL_STATE
492 .PP
493.TP
494UNW_DYN_COPY_STATE
495 .PP
496.TP
497UNW_DYN_ALIAS
498 .PP
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000499unw_dyn_op_t
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000500.PP
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000501_U_dyn_op_save_reg();
502_U_dyn_op_spill_fp_rel();
503_U_dyn_op_spill_sp_rel();
504_U_dyn_op_add();
505_U_dyn_op_pop_frames();
506_U_dyn_op_label_state();
507_U_dyn_op_copy_state();
508_U_dyn_op_alias();
509_U_dyn_op_stop();
510.PP
mostang.com!davidmf6158812003-12-21 07:21:28 +0000511.SH IA\-64 SPECIFICS
512
513.PP
514\- meaning of segbase member in table\-info/table\-remote\-info format
515\- format of table_data in table\-info/table\-remote\-info format
516\- instruction size: each bundle is counted as 3 instructions, regardless
517of template (MLX)
518\- describe stack\-frame layout, especially with regards to sp\-relative
519and fp\-relative addressing
520\- UNW_DYN_ADD can only add to ``sp\&'' (always a negative value); use
521POP_FRAMES otherwise
522.PP
mostang.com!davidmf18f14e2003-12-10 07:14:38 +0000523.SH SEE ALSO
524
525.PP
526libunwind(3),
527_U_dyn_register(3),
528_U_dyn_cancel(3)
529.PP
530.SH AUTHOR
531
532.PP
533David Mosberger\-Tang
534.br
535Hewlett\-Packard Labs
536.br
537Palo\-Alto, CA 94304
538.br
539Email: \fBdavidm@hpl.hp.com\fP
540.br
541WWW: \fBhttp://www.hpl.hp.com/research/linux/libunwind/\fP\&.
542.\" NOTE: This file is generated, DO NOT EDIT.