blob: 5b1bd0f1f5062da00ba7df4192314417da030908 [file] [log] [blame]
mostang.com!davidme91ef292003-12-10 07:14:38 +00001\documentclass{article}
2\usepackage[fancyhdr,pdf]{latex2man}
mostang.com!davidm34340902003-02-22 08:19:43 +00003
mostang.com!davidme91ef292003-12-10 07:14:38 +00004\input{common.tex}
5
6\begin{document}
7
8\begin{Name}{3}{libunwind-dynamic}{David Mosberger-Tang}{Programming Library}{Introduction to dynamic unwind-info}libunwind-dynamic -- libunwind-support for runtime-generated code
9\end{Name}
10
11\section{Introduction}
12
13For \Prog{libunwind} to do its work, it needs to be able to
14reconstruct the \emph{frame state} of each frame in a call-chain. The
15frame state consists of some frame registers (such as the
16instruction-pointer and the stack-pointer) and the locations at which
17the current values of every callee-saved (``preserved'') resides.
18
19The purpose of the dynamic unwind-info is therefore to provide
20\Prog{libunwind} the minimal information it needs about each
21dynamically generated procedure such that it can reconstruct the
22procedure's frame state.
23
24For the purpose of the following discussion, a \emph{procedure} is any
25contiguous piece of code. Normally, each procedure directly
26corresponds to a function in the source-language but this is not
27strictly required. For example, a runtime code-generator could
28translate a given function into two separate (discontiguous)
29procedures: one for frequently-executed (hot) code and one for
30rarely-executed (cold) code. Similarly, simple source-language
31functions (usually leaf functions) may get translated into code for
32which the default unwind-conventions apply and for such code, no
33dynamic unwind info needs to be registered.
34
35Within a procedure, the code can be thought of as being divided into a
36sequence of \emph{regions}. Each region logically consists of an
37optional \emph{prologue}, a \emph{body}, and an optional
38\emph{epilogue}. If present, the prologue sets up the frame state for
39the body, which does the actual work of the procedure. For example,
40the prologue may need to allocate a stack-frame and save some
41callee-saved registers before the body can start executing.
42Correspondingly, the epilogue, if present, restores the previous frame
43state and thereby undoes the effect of the prologue. Regions are
44nested in the sense that the frame state at the end of a region serves
45as the entry-state of the next region. At the end of several nested
46regions, there may be a single epilogue which undoes the effect of all
47the prologues in the nested regions.
48
49Even though logically we think of the prologue, body, and epilogue as
50separate entities, optimizing code-generators will generally
51interleave instructions from all three entities to achieve higher
52performance. In fact, as far as the dynamic unwind-info is concerned,
53there is no distinction at all between prologue and body. Similarly,
54the exact set of instructions that make up an epilogue is also
55irrelevant. The only point in the epilogue that needs to be described
56explicitly is the point at which the stack-pointer gets restored. The
57reason this point needs to be described is that once the stack-pointer
58is restored, all values saved in the deallocated portion of the stack
59become invalid. All other locations that store the values of
60callee-saved register are assumed to remain valid throughout the end
61of the region.
62
63Within a region, each instruction that affects the frame state in some
64fashion needs to be described with an operation descriptor. For this
65purpose, each instruction in the region is assigned a unique index.
66Exactly how this index is derived depends on the architecture. For
67example, on RISC and EPIC-style architecture, instructions have a
68fixed size so it's possible to simply number the instructions. In
69contrast, most CISC use variable-length instruction encodings, so it
70is usually necessary to use a byte-offset as the index. Given the
71instruction index, the operation descriptor specifies the effect of
72the instruction in an abstract manner. For example, it might express
73that the instruction stores calle-saved register \Var{r1} at offset 16
74in the stack frame.
75
76\section{Procedures}
77
78unw\_dyn\_info\_t
79unw\_dyn\_proc\_info\_t
80unw\_dyn\_table\_info\_t
81unw\_dyn\_remote\_table\_info\_t
82
83\section{Regions}
84
85unw\_dyn\_region\_info\_t:
mostang.com!davidm34340902003-02-22 08:19:43 +000086 - insn_count can be negative to indicate that the region is
87 at the end of the procedure; in such a case, the negated
88 insn_count value specifies the length of the final region
89 in number of instructions. There must be at most one region
90 with a negative insn_count and only the last region in a
91 procedure's region list may be negative. Furthermore, both
92 di->start\_ip and di->end\_ip must be valid.
mostang.com!davidme91ef292003-12-10 07:14:38 +000093
94\section{Operations}
95
96unw\_dyn\_operation\_t
97unw\_dyn\_op\_t
98 \_U\_QP\_TRUE
99
100unw\_dyn\_info\_format\_t
101
102- instructions don't have to be sorted in increasing order of ``when''
103 values: In general, if you can generate the sorted order easily
104 (e.g., without an explicit sorting step), I'd recommend doing so
105 because in that case, should some version of libunwind ever require
106 sorted order, libunwind can verify in O(N) that the list is sorted
107 already. In the particular case of the ia64-version of libunwind, a
108 sorted order won't help, since it always scans the instructions up
109 to UNW_DYN_STOP.
110
111\_U\_dyn\_region\_info\_size(opcount);
112\_U\_dyn\_op\_save\_reg();
113\_U\_dyn\_op\_spill\_fp\_rel();
114\_U\_dyn\_op\_spill\_sp\_rel();
115\_U\_dyn\_op\_add();
116\_U\_dyn\_op\_pop\_frames();
117\_U\_dyn\_op\_label\_state();
118\_U\_dyn\_op\_copy\_state();
119\_U\_dyn\_op\_alias();
120\_U\_dyn\_op\_stop();
121
122\section{See Also}
123
124\SeeAlso{libunwind(3)},
125\SeeAlso{\_U\_dyn\_register(3)},
126\SeeAlso{\_U\_dyn\_cancel(3)}
127
128\section{Author}
129
130\noindent
131David Mosberger-Tang\\
132Hewlett-Packard Labs\\
133Palo-Alto, CA 94304\\
134Email: \Email{davidm@hpl.hp.com}\\
135WWW: \URL{http://www.hpl.hp.com/research/linux/libunwind/}.
136\LatexManEnd
137
138\end{document}