blob: ebe06f7454d75bdc83f3fd0eb984a7323b1c7409 [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
99\Type{unw\_error\_t} error-codes may be returned.
100
101\subsection{put\_unwind\_info}
102
103\Prog{Libunwind} invokes the \Func{put\_unwind\_info}() call-back to
104release the resources (such as memory) allocated by a previous call to
105\Func{find\_proc\_info}() with the \Var{need\_unwind\_info} argument
106set to a non-zero value. The \Var{pip} argument has the same value as
107the argument of the same name in the previous matching call to
108\Func{find\_proc\_info}(). Note that \Prog{libunwind} does \emph{not}
109invoke \Func{put\_unwind\_info} for calls to \Func{find\_proc\_info}()
110with a zero \Var{need\_unwind\_info} argument.
111
112
113\subsection{get\_dyn\_info\_list\_addr}
114
115\Prog{Libunwind} invokes the \Func{get\_dyn\_info\_list\_addr}()
116call-back to obtain the address of the head of the dynamic unwind-info
117registration list. The variable stored at the returned address must
118have a type of \Type{unw\_dyn\_info\_list\_t} (see
119\Func{\_U\_dyn\_register}(3)). The \Var{dliap} argument is a pointer
120to a variable of type \Type{unw\_word\_t} which is used to return the
121address of the dynamic unwind-info registration list. If no dynamic
122unwind-info registration list exist, the value pointed to by
123\Var{dliap} must be cleared to zero. \Prog{Libunwind} will cache the
124value returned by \Func{get\_dyn\_info\_list\_addr}() if caching is
125enabled for the given address-space. The cache can be cleared with a
126call to \Func{unw\_flush\_cache}().
127
128On successful completion, the \Func{get\_dyn\_info\_list\_addr}()
129call-back must return zero. Otherwise, the negative value of one of
130the \Type{unw\_error\_t} error-codes may be returned.
131
132\subsection{access\_mem}
133
134\Prog{Libunwind} invokes the \Func{access\_mem}() call-back to read
135from or write to a word of memory in the target address-space. The
136address of the word to be accessed is passed in argument \Var{addr}.
137To read memory, \Prog{libunwind} sets argument \Var{write} to zero and
138\Var{valp} to point to the word that receives the read value. To
139write memory, \Prog{libunwind} sets argument \Var{write} to a non-zero
140value and \Var{valp} to point to the word that contains the value to
141be written. The word that \Var{valp} points to is always in the
142byte-order of the host-platform, regardless of the byte-order of the
143target. In other words, it is the responsibility of the call-back
144routine to convert between the target's and the host's byte-order, if
145necessary.
146
147On successful completion, the \Func{access\_mem}()
148call-back must return zero. Otherwise, the negative value of one of
149the \Type{unw\_error\_t} error-codes may be returned.
150
151\subsection{access\_reg}
152
153\Prog{Libunwind} invokes the \Func{access\_reg}() call-back to read
154from or write to a scalar (non-floating-point) CPU register. The
155index of the register to be accessed is passed in argument
156\Var{regnum}. To read a register, \Prog{libunwind} sets argument
157\Var{write} to zero and \Var{valp} to point to the word that receives
158the read value. To write a register, \Prog{libunwind} sets argument
159\Var{write} to a non-zero value and \Var{valp} to point to the word
160that contains the value to be written. The word that \Var{valp}
161points to is always in the byte-order of the host-platform, regardless
162of the byte-order of the target. In other words, it is the
163responsibility of the call-back routine to convert between the
164target's and the host's byte-order, if necessary.
165
166On successful completion, the \Func{access\_reg}() call-back must
167return zero. Otherwise, the negative value of one of the
168\Type{unw\_error\_t} error-codes may be returned.
169
170\subsection{access\_fpreg}
171
172\Prog{Libunwind} invokes the \Func{access\_fpreg}() call-back to read
173from or write to a floating-point CPU register. The index of the
174register to be accessed is passed in argument \Var{regnum}. To read a
175register, \Prog{libunwind} sets argument \Var{write} to zero and
176\Var{fpvalp} to point to a variable of type \Type{unw\_fpreg\_t} that
177receives the read value. To write a register, \Prog{libunwind} sets
178argument \Var{write} to a non-zero value and \Var{fpvalp} to point to
179the variable of type \Type{unw\_fpreg\_t} that contains the value to
180be written. The word that \Var{fpvalp} points to is always in the
181byte-order of the host-platform, regardless of the byte-order of the
182target. In other words, it is the responsibility of the call-back
183routine to convert between the target's and the host's byte-order, if
184necessary.
185
186On successful completion, the \Func{access\_fpreg}() call-back must
187return zero. Otherwise, the negative value of one of the
188\Type{unw\_error\_t} error-codes may be returned.
189
190\subsection{resume}
191
192\Prog{Libunwind} invokes the \Func{resume}() call-back to resume
193execution in the target address space. Argument \Var{cp} is the
194unwind-cursor that identifies the stack-frame in which execution
195should resume. By the time \Prog{libunwind} invokes the \Func{resume}
196call-back, it has already established the desired machine- and
197memory-state via calls to the \Func{access_reg}(),
198\Func{access\_fpreg}, and \Func{access\_mem}() call-backs. Thus, all
199the call-back needs to do is perform whatever action is needed to
200actually resume execution.
201
202The \Func{resume} call-back is invoked only in response to a call to
203\Func{unw\_resume}(3), so applications which never invoke
204\Func{unw\_resume}(3) need not define the \Func{resume} callback.
205
206On successful completion, the \Func{resume}() call-back must return
207zero. Otherwise, the negative value of one of the
208\Type{unw\_error\_t} error-codes may be returned. As a special case,
209when resuming execution in the local address space, the call-back will
210not return on success.
211
212\subsection{get\_proc\_name}
213
214\Prog{Libunwind} invokes the \Func{get\_proc\_name}() call-back to
215obtain the procedure-name of a static (not dynamically generated)
216procedure. Argument \Var{addr} is an instruction-address within the
217procedure whose name is to be obtained. The \Var{bufp} argument is a
218pointer to a character-buffer used to return the procedure name. The
219size of this buffer is specified in argument \Var{buf_len}. The
220returned name must be terminated by a NUL character. If the
221procedure's name is longer than \Var{buf_len} bytes, it must be
222truncated to \Var{buf\_len}\Prog{-1} bytes, with the last byte in the
223buffer set to the NUL character and -\Const{UNW\_ENOMEM} must be
224returned. Argument \Var{offp} is a pointer to a word which is used to
225return the byte-offset relative to the start of the procedure whose
226name is being returned. For example, if procedure \Func{foo}() starts
227at address 0x40003000, then invoking \Func{get\_proc\_name}() with
228\Var{addr} set to 0x40003080 should return a value of 0x80 in the word
229pointed to by \Var{offp} (assuming the procedure is at least 0x80
230bytes long).
231
232On successful completion, the \Func{get\_proc\_name}() call-back must
233return zero. Otherwise, the negative value of one of the
234\Type{unw\_error\_t} error-codes may be returned.
235
236
237\section{Return Value}
238
239On successful completion, \Func{unw\_create\_addr\_space}() returns a
240non-\Const{NULL} value that represents the newly created
241address-space. Otherwise, \Const{NULL} is returned.
242
243\section{Thread and Signal Safety}
244
245\Func{unw\_create\_addr\_space}() is thread-safe but \emph{not}
246safe to use from a signal handler.
247
248\end{Description}
249
250\section{See Also}
251
252\SeeAlso{\_U\_dyn\_register(3)},
253\SeeAlso{libunwind(3)},
254\SeeAlso{unw\_destroy\_addr\_space(3)},
255\SeeAlso{unw\_get\_proc\_info(3)},
256\SeeAlso{unw\_init\_remote(3)},
257\SeeAlso{unw\_resume(3)}
258
259\section{Author}
260
261\noindent
262David Mosberger-Tang\\
263Hewlett-Packard Labs\\
264Palo-Alto, CA 94304\\
265Email: \Email{davidm@hpl.hp.com}\\
266WWW: \URL{http://www.hpl.hp.com/research/linux/libunwind/}.
267\LatexManEnd
268
269\end{document}