blob: b12d9e37c192791cfa59463c720474c2eeae3319 [file] [log] [blame]
mostang.com!davidmdc1aade2003-03-13 02:15:01 +00001\documentclass{article}
2\usepackage[fancyhdr,pdf]{latex2man}
3
4\input{common.tex}
5
6\begin{document}
7
8\begin{Name}{3}{unw\_create\_addr\_space}{David Mosberger-Tang}{Programming Library}{unw\_create\_addr\_space}
9
10 unw\_create\_addr\_space -- create address space for remote unwinding
11\end{Name}
12
13\section{Synopsis}
14
15\File{\#include $<$libunwind.h$>$}\\
16
17\Type{int} \Func{unw\_create\_addr\_space}(\Type{unw\_accessors\_t~*}\Var{ap}, \Type{int} \Var{byteorder});\\
18
19\section{Description}
20
21The \Func{unw\_create\_addr\_space}() routine creates a new unwind
22address-space and initializes it based on the call-back routines
23passed via the \Var{ap} pointer and the specified \Var{byteorder}.
24The call-back routines are described in detail below. The
25\Var{byteorder} can be set to 0 to request the default byte-order of
26the unwind target. To request a particular byte-order,
27\Var{byteorder} can be set to any constant defined by
28\File{$<$endian.h$>$}. In particular, \Const{\_\_LITTLE_ENDIAN} would
29request little-endian byte-order and \Const{\_\_BIG\_ENDIAN} would
30request big-endian byte-order. Whether or not a particular byte-order
31is supported depends on the target platform.
32
33\section{Call-back Routines}
34
35\Prog{Libunwind} uses a set of call-back routines to access the
36information it needs to unwind a chain of stack-frames. These
37routines are specified via the \Var{ap} argument, which points to a
38variable of type \Type{unw\_accessors\_t}. The contents of this
39variable is copied into the newly-created address space, so the
40variable must remain valid only for the duration of the call to
41\Func{unw\_create\_addr\_space}().
42
43The first argument to every call-back routine is an address-space
44identifier (\Var{as}) and the last argument is an arbitrary,
45application-specified void-pointer (\Var{arg}). When invoking a
46call-back routine, \Prog{libunwind} sets the \Var{as} argument to the
47address-space on whose behalf the invocation is made and the \Var{arg}
48argument to the value that was specified when
49\Func{unw\_init\_remote}(3) was called.
50
51The synopsis and a detailed description of every call-back routine
52follows below.
53
54\subsection{Call-back Routine Synopsis}
55
56\Type{int} \Func{find\_proc\_info}(\Type{unw\_addr\_space\_t} \Var{as},\\
57\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_word\_t} \Var{ip}, \Type{unw\_proc\_info\_t~*}\Var{pip},\\
58\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{int} \Var{need\_unwind\_info}, \Type{void~*}arg);\\
59\Type{void} \Func{put\_unwind\_info}(\Type{unw\_addr\_space\_t} \Var{as},\\
60\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_proc\_info\_t~*}pip, \Type{void~*}\Var{arg});\\
61\Type{int} \Func{get\_dyn\_info\_list\_addr}(\Type{unw\_addr\_space\_t} \Var{as},\\
62\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_word\_t~*}\Var{dilap}, \Type{void~*}\Var{arg});\\
63\Type{int} \Func{access\_mem}(\Var{unw\_addr\_space\_t} \Var{as},\\
64\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_word\_t} \Var{addr}, \Type{unw\_word\_t~*}\Var{valp},\\
65\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{int} \Var{write}, \Type{void~*}\Var{arg});\\
66\Type{int} \Func{access\_reg}(\Var{unw\_addr\_space\_t} \Var{as},\\
67\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_regnum\_t} \Var{regnum}, \Type{unw\_word\_t~*}\Var{valp},\\
68\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{int} \Var{write}, \Type{void~*}\Var{arg});\\
69\Type{int} \Func{access\_fpreg}(\Var{unw\_addr\_space\_t} \Var{as},\\
70\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_regnum\_t} \Var{regnum}, \Type{unw\_fpreg\_t~*}\Var{fpvalp},\\
71\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{int} \Var{write}, \Type{void~*}\Var{arg});\\
72\Type{int} \Func{resume}(\Var{unw\_addr\_space\_t} \Var{as},\\
73\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_cursor\_t~*}\Var{cp}, \Type{void~*}\Var{arg});\\
74\Type{int} \Func{get\_proc\_name}(\Type{unw\_addr\_space\_t} \Var{as},\\
75\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{unw\_word\_t} \Var{addr}, \Type{char~*}\Var{bufp},\\
76\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{size\_t} \Var{buf\_len}, \Type{unw\_word\_t~*}\Var{offp},\\
77\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{void~*}\Var{arg});\\
78
79\subsection{find\_proc\_info}
80
81\Prog{Libunwind} invokes the \Func{find\_proc\_info}() call-back to
82locate the information need to unwind a particular procedure. The
83\Var{ip} argument is an instruction-address inside the procedure whose
84information is needed. The \Var{pip} argument is a pointer to the
85variable used to return the desired information. The type of this
86variable is \Type{unw\_proc\_info\_t}. See
87\Func{unw\_get\_proc\_info(3)} for details. Argument
88\Var{need\_unwind\_info} is zero if the call-back does not need to
89provide values for the following members in the
90\Type{unw\_proc\_info\_t} structure: \Var{format},
91\Var{unwind\_info\_size}, and \Var{unwind\_info}. If
92\Var{need\_unwind\_info} is non-zero, valid values need to be returned
93in these members. Furthermore, the contents of the memory addressed
94by the \Var{unwind\_info} member must remain valid until the info is
95released via the \Func{put\_unwind\_info} call-back (see below).
96
97On successful completion, the \Func{find\_proc\_info}() call-back must
98return zero. Otherwise, the negative value of one of the
mostang.com!davidm87849a52003-03-20 07:51:37 +000099\Type{unw\_error\_t} error-codes may be returned. In particular, this
100call-back may return -\Const{UNW\_ESTOPUNWIND} to signal the end of
101the frame-chain.
mostang.com!davidmdc1aade2003-03-13 02:15:01 +0000102
103\subsection{put\_unwind\_info}
104
105\Prog{Libunwind} invokes the \Func{put\_unwind\_info}() call-back to
106release the resources (such as memory) allocated by a previous call to
107\Func{find\_proc\_info}() with the \Var{need\_unwind\_info} argument
108set to a non-zero value. The \Var{pip} argument has the same value as
109the argument of the same name in the previous matching call to
110\Func{find\_proc\_info}(). Note that \Prog{libunwind} does \emph{not}
111invoke \Func{put\_unwind\_info} for calls to \Func{find\_proc\_info}()
112with a zero \Var{need\_unwind\_info} argument.
113
114
115\subsection{get\_dyn\_info\_list\_addr}
116
117\Prog{Libunwind} invokes the \Func{get\_dyn\_info\_list\_addr}()
118call-back to obtain the address of the head of the dynamic unwind-info
119registration list. The variable stored at the returned address must
120have a type of \Type{unw\_dyn\_info\_list\_t} (see
121\Func{\_U\_dyn\_register}(3)). The \Var{dliap} argument is a pointer
122to a variable of type \Type{unw\_word\_t} which is used to return the
123address of the dynamic unwind-info registration list. If no dynamic
124unwind-info registration list exist, the value pointed to by
125\Var{dliap} must be cleared to zero. \Prog{Libunwind} will cache the
126value returned by \Func{get\_dyn\_info\_list\_addr}() if caching is
127enabled for the given address-space. The cache can be cleared with a
128call to \Func{unw\_flush\_cache}().
129
130On successful completion, the \Func{get\_dyn\_info\_list\_addr}()
131call-back must return zero. Otherwise, the negative value of one of
132the \Type{unw\_error\_t} error-codes may be returned.
133
134\subsection{access\_mem}
135
136\Prog{Libunwind} invokes the \Func{access\_mem}() call-back to read
137from or write to a word of memory in the target address-space. The
138address of the word to be accessed is passed in argument \Var{addr}.
139To read memory, \Prog{libunwind} sets argument \Var{write} to zero and
140\Var{valp} to point to the word that receives the read value. To
141write memory, \Prog{libunwind} sets argument \Var{write} to a non-zero
142value and \Var{valp} to point to the word that contains the value to
143be written. The word that \Var{valp} points to is always in the
144byte-order of the host-platform, regardless of the byte-order of the
145target. In other words, it is the responsibility of the call-back
146routine to convert between the target's and the host's byte-order, if
147necessary.
148
149On successful completion, the \Func{access\_mem}()
150call-back must return zero. Otherwise, the negative value of one of
151the \Type{unw\_error\_t} error-codes may be returned.
152
153\subsection{access\_reg}
154
155\Prog{Libunwind} invokes the \Func{access\_reg}() call-back to read
156from or write to a scalar (non-floating-point) CPU register. The
157index of the register to be accessed is passed in argument
158\Var{regnum}. To read a register, \Prog{libunwind} sets argument
159\Var{write} to zero and \Var{valp} to point to the word that receives
160the read value. To write a register, \Prog{libunwind} sets argument
161\Var{write} to a non-zero value and \Var{valp} to point to the word
162that contains the value to be written. The word that \Var{valp}
163points to is always in the byte-order of the host-platform, regardless
164of the byte-order of the target. In other words, it is the
165responsibility of the call-back routine to convert between the
166target's and the host's byte-order, if necessary.
167
168On successful completion, the \Func{access\_reg}() call-back must
169return zero. Otherwise, the negative value of one of the
170\Type{unw\_error\_t} error-codes may be returned.
171
172\subsection{access\_fpreg}
173
174\Prog{Libunwind} invokes the \Func{access\_fpreg}() call-back to read
175from or write to a floating-point CPU register. The index of the
176register to be accessed is passed in argument \Var{regnum}. To read a
177register, \Prog{libunwind} sets argument \Var{write} to zero and
178\Var{fpvalp} to point to a variable of type \Type{unw\_fpreg\_t} that
179receives the read value. To write a register, \Prog{libunwind} sets
180argument \Var{write} to a non-zero value and \Var{fpvalp} to point to
181the variable of type \Type{unw\_fpreg\_t} that contains the value to
182be written. The word that \Var{fpvalp} points to is always in the
183byte-order of the host-platform, regardless of the byte-order of the
184target. In other words, it is the responsibility of the call-back
185routine to convert between the target's and the host's byte-order, if
186necessary.
187
188On successful completion, the \Func{access\_fpreg}() call-back must
189return zero. Otherwise, the negative value of one of the
190\Type{unw\_error\_t} error-codes may be returned.
191
192\subsection{resume}
193
194\Prog{Libunwind} invokes the \Func{resume}() call-back to resume
195execution in the target address space. Argument \Var{cp} is the
196unwind-cursor that identifies the stack-frame in which execution
197should resume. By the time \Prog{libunwind} invokes the \Func{resume}
198call-back, it has already established the desired machine- and
199memory-state via calls to the \Func{access_reg}(),
200\Func{access\_fpreg}, and \Func{access\_mem}() call-backs. Thus, all
201the call-back needs to do is perform whatever action is needed to
202actually resume execution.
203
204The \Func{resume} call-back is invoked only in response to a call to
205\Func{unw\_resume}(3), so applications which never invoke
206\Func{unw\_resume}(3) need not define the \Func{resume} callback.
207
208On successful completion, the \Func{resume}() call-back must return
209zero. Otherwise, the negative value of one of the
210\Type{unw\_error\_t} error-codes may be returned. As a special case,
211when resuming execution in the local address space, the call-back will
212not return on success.
213
214\subsection{get\_proc\_name}
215
216\Prog{Libunwind} invokes the \Func{get\_proc\_name}() call-back to
217obtain the procedure-name of a static (not dynamically generated)
218procedure. Argument \Var{addr} is an instruction-address within the
219procedure whose name is to be obtained. The \Var{bufp} argument is a
220pointer to a character-buffer used to return the procedure name. The
221size of this buffer is specified in argument \Var{buf_len}. The
222returned name must be terminated by a NUL character. If the
223procedure's name is longer than \Var{buf_len} bytes, it must be
224truncated to \Var{buf\_len}\Prog{-1} bytes, with the last byte in the
225buffer set to the NUL character and -\Const{UNW\_ENOMEM} must be
226returned. Argument \Var{offp} is a pointer to a word which is used to
227return the byte-offset relative to the start of the procedure whose
228name is being returned. For example, if procedure \Func{foo}() starts
229at address 0x40003000, then invoking \Func{get\_proc\_name}() with
230\Var{addr} set to 0x40003080 should return a value of 0x80 in the word
231pointed to by \Var{offp} (assuming the procedure is at least 0x80
232bytes long).
233
234On successful completion, the \Func{get\_proc\_name}() call-back must
235return zero. Otherwise, the negative value of one of the
236\Type{unw\_error\_t} error-codes may be returned.
237
238
239\section{Return Value}
240
241On successful completion, \Func{unw\_create\_addr\_space}() returns a
242non-\Const{NULL} value that represents the newly created
243address-space. Otherwise, \Const{NULL} is returned.
244
245\section{Thread and Signal Safety}
246
247\Func{unw\_create\_addr\_space}() is thread-safe but \emph{not}
248safe to use from a signal handler.
249
250\end{Description}
251
252\section{See Also}
253
254\SeeAlso{\_U\_dyn\_register(3)},
255\SeeAlso{libunwind(3)},
256\SeeAlso{unw\_destroy\_addr\_space(3)},
257\SeeAlso{unw\_get\_proc\_info(3)},
258\SeeAlso{unw\_init\_remote(3)},
259\SeeAlso{unw\_resume(3)}
260
261\section{Author}
262
263\noindent
264David Mosberger-Tang\\
265Hewlett-Packard Labs\\
266Palo-Alto, CA 94304\\
267Email: \Email{davidm@hpl.hp.com}\\
268WWW: \URL{http://www.hpl.hp.com/research/linux/libunwind/}.
269\LatexManEnd
270
271\end{document}