xref: /minix3/external/bsd/elftoolchain/dist/libdwarf/dwarf_producer_init.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: dwarf_producer_init.3,v 1.2 2014/03/09 16:58:04 christos Exp $
2*0a6a1f1dSLionel Sambuc.\"
3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2011 Kai Wang
4*0a6a1f1dSLionel Sambuc.\" All rights reserved.
5*0a6a1f1dSLionel Sambuc.\"
6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions
8*0a6a1f1dSLionel Sambuc.\" are met:
9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
10*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
12*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
13*0a6a1f1dSLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
14*0a6a1f1dSLionel Sambuc.\"
15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*0a6a1f1dSLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*0a6a1f1dSLionel Sambuc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*0a6a1f1dSLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*0a6a1f1dSLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*0a6a1f1dSLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*0a6a1f1dSLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*0a6a1f1dSLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*0a6a1f1dSLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE.
26*0a6a1f1dSLionel Sambuc.\"
27*0a6a1f1dSLionel Sambuc.\" Id: dwarf_producer_init.3 2074 2011-10-27 03:34:33Z jkoshy
28*0a6a1f1dSLionel Sambuc.\"
29*0a6a1f1dSLionel Sambuc.Dd August 20, 2011
30*0a6a1f1dSLionel Sambuc.Os
31*0a6a1f1dSLionel Sambuc.Dt DWARF_PRODUCER_INIT 3
32*0a6a1f1dSLionel Sambuc.Sh NAME
33*0a6a1f1dSLionel Sambuc.Nm dwarf_producer_init
34*0a6a1f1dSLionel Sambuc.Nm dwarf_producer_init_b
35*0a6a1f1dSLionel Sambuc.Nd allocate a DWARF producer descriptor
36*0a6a1f1dSLionel Sambuc.Sh LIBRARY
37*0a6a1f1dSLionel Sambuc.Lb libdwarf
38*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS
39*0a6a1f1dSLionel Sambuc.In libdwarf.h
40*0a6a1f1dSLionel Sambuc.Ft Dwarf_P_Debug
41*0a6a1f1dSLionel Sambuc.Fo dwarf_producer_init
42*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Unsigned flags"
43*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Callback_Func func"
44*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Handler errhand"
45*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ptr errarg"
46*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err"
47*0a6a1f1dSLionel Sambuc.Fc
48*0a6a1f1dSLionel Sambuc.Ft Dwarf_P_Debug
49*0a6a1f1dSLionel Sambuc.Fo dwarf_producer_init_b
50*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Unsigned flags"
51*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Callback_Func_b func"
52*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Handler errhand"
53*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ptr errarg"
54*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *error"
55*0a6a1f1dSLionel Sambuc.Fc
56*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION
57*0a6a1f1dSLionel SambucThese functions allocate and return a
58*0a6a1f1dSLionel Sambuc.Vt Dwarf_P_Debug
59*0a6a1f1dSLionel Sambucdescriptor representing a DWARF producer instance.
60*0a6a1f1dSLionel Sambuc.Pp
61*0a6a1f1dSLionel SambucThe argument
62*0a6a1f1dSLionel Sambuc.Ar errhand
63*0a6a1f1dSLionel Sambucshould contain the adddress of a function to be called in case of an
64*0a6a1f1dSLionel Sambucerror.
65*0a6a1f1dSLionel SambucIf this argument is
66*0a6a1f1dSLionel Sambuc.Dv NULL ,
67*0a6a1f1dSLionel Sambucthe default error handling scheme is used, see
68*0a6a1f1dSLionel Sambuc.Xr dwarf 3 .
69*0a6a1f1dSLionel Sambuc.Pp
70*0a6a1f1dSLionel SambucThe argument
71*0a6a1f1dSLionel Sambuc.Ar errarg
72*0a6a1f1dSLionel Sambucwill be passed to the error handler function when it is invoked.
73*0a6a1f1dSLionel Sambuc.Pp
74*0a6a1f1dSLionel SambucThe argument
75*0a6a1f1dSLionel Sambuc.Ar err
76*0a6a1f1dSLionel Sambucreferences a memory location that would hold a
77*0a6a1f1dSLionel Sambuc.Vt Dwarf_Error
78*0a6a1f1dSLionel Sambucdescriptor in case of an error.
79*0a6a1f1dSLionel Sambuc.Pp
80*0a6a1f1dSLionel SambucThe argument
81*0a6a1f1dSLionel Sambuc.Ar flags
82*0a6a1f1dSLionel Sambucspecifies additional characteristics of the DWARF producer instance.
83*0a6a1f1dSLionel SambucThe following flags are recognized:
84*0a6a1f1dSLionel Sambuc.Pp
85*0a6a1f1dSLionel Sambuc.Bl -tag -width "Dv DW_DLC_ISA_MIPS"
86*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_ISA_IA64
87*0a6a1f1dSLionel Sambuc.Pq Deprecated
88*0a6a1f1dSLionel SambucThe target instruction set architecture is IA64.
89*0a6a1f1dSLionel SambucThis flag is deprecated.
90*0a6a1f1dSLionel SambucApplication code should use the
91*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_set_isa 3
92*0a6a1f1dSLionel Sambucfunction to specify target instruction set architecture.
93*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_ISA_MIPS
94*0a6a1f1dSLionel Sambuc.Pq Deprecated
95*0a6a1f1dSLionel SambucThe target instruction set architecture is MIPS.
96*0a6a1f1dSLionel SambucThis flag is deprecated.
97*0a6a1f1dSLionel SambucApplication code should use the
98*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_set_isa 3
99*0a6a1f1dSLionel Sambucfunction to specify target instruction set architecture.
100*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_SIZE_32
101*0a6a1f1dSLionel Sambuc.Pq Default
102*0a6a1f1dSLionel SambucThe target address size is 32-bit.
103*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_SIZE_64
104*0a6a1f1dSLionel SambucThe target address size is 64-bit.
105*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_STREAM_RELOCATIONS
106*0a6a1f1dSLionel Sambuc.Pq Default
107*0a6a1f1dSLionel SambucGenerate stream relocations.
108*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_SYMBOLIC_RELOCATIONS
109*0a6a1f1dSLionel SambucGenerate symbolic relocations.
110*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_TARGET_BIGENDIAN
111*0a6a1f1dSLionel SambucThe target is big endian.
112*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_TARGET_LITTLEENDIAN
113*0a6a1f1dSLionel SambucThe target is little endian.
114*0a6a1f1dSLionel Sambuc.It Dv DW_DLC_WRITE
115*0a6a1f1dSLionel Sambuc.Pq Required
116*0a6a1f1dSLionel SambucPermit writing of DWARF information.
117*0a6a1f1dSLionel Sambuc.El
118*0a6a1f1dSLionel Sambuc.Pp
119*0a6a1f1dSLionel SambucThe following flags are mutually exclusive.
120*0a6a1f1dSLionel Sambuc.Bl -bullet -compact
121*0a6a1f1dSLionel Sambuc.It
122*0a6a1f1dSLionel SambucFlags
123*0a6a1f1dSLionel Sambuc.Dv DW_DLC_ISA_IA64
124*0a6a1f1dSLionel Sambucand
125*0a6a1f1dSLionel Sambuc.Dv DW_DLC_ISA_MIPS .
126*0a6a1f1dSLionel Sambuc.It
127*0a6a1f1dSLionel SambucFlags
128*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SIZE_32
129*0a6a1f1dSLionel Sambucand
130*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SIZE_64 .
131*0a6a1f1dSLionel Sambuc.It
132*0a6a1f1dSLionel SambucFlags
133*0a6a1f1dSLionel Sambuc.Dv DW_DLC_STREAM_RELOCATIONS
134*0a6a1f1dSLionel Sambucand
135*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SYMBOLIC_RELOCATIONS .
136*0a6a1f1dSLionel Sambuc.It
137*0a6a1f1dSLionel SambucFlags
138*0a6a1f1dSLionel Sambuc.Dv DW_DLC_TARGET_BIGENDIAN
139*0a6a1f1dSLionel Sambucand
140*0a6a1f1dSLionel Sambuc.Dv DW_DLC_TARGET_LITTLEENDIAN .
141*0a6a1f1dSLionel Sambuc.El
142*0a6a1f1dSLionel SambucIf neither of the flags
143*0a6a1f1dSLionel Sambuc.Dv DW_DLC_TARGET_BIGENDIAN
144*0a6a1f1dSLionel Sambucand
145*0a6a1f1dSLionel Sambuc.Dv DW_DLC_TARGET_LITTLEENDIAN
146*0a6a1f1dSLionel Sambucis set, the target's endianness is assumed to be the same as the host's
147*0a6a1f1dSLionel Sambucendianness.
148*0a6a1f1dSLionel Sambuc.Pp
149*0a6a1f1dSLionel SambucArgument
150*0a6a1f1dSLionel Sambuc.Ar func
151*0a6a1f1dSLionel Sambucshould point to an application-provided callback function of type
152*0a6a1f1dSLionel Sambuc.Vt Dwarf_Callback_Func_b .
153*0a6a1f1dSLionel SambucThe type
154*0a6a1f1dSLionel Sambuc.Vt Dwarf_Callback_Func_b
155*0a6a1f1dSLionel Sambucis defined in the header file
156*0a6a1f1dSLionel Sambuc.In libdwarf.h
157*0a6a1f1dSLionel Sambucas:
158*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent
159*0a6a1f1dSLionel Sambuctypedef int (*Dwarf_Callback_Func_b)(char *name, int size,
160*0a6a1f1dSLionel Sambuc    Dwarf_Unsigned type, Dwarf_Unsigned flags, Dwarf_Unsigned link,
161*0a6a1f1dSLionel Sambuc    Dwarf_Unsigned info, Dwarf_Unsigned *index, int *error);
162*0a6a1f1dSLionel Sambuc.Ed
163*0a6a1f1dSLionel Sambuc.Pp
164*0a6a1f1dSLionel SambucThis function is called by the
165*0a6a1f1dSLionel Sambuc.Lb libdwarf
166*0a6a1f1dSLionel Sambuconce for each section in the object file that the library needs to
167*0a6a1f1dSLionel Sambuccreate.
168*0a6a1f1dSLionel SambucThe arguments to this callback function specify the values in the ELF
169*0a6a1f1dSLionel Sambucsection header for the section being created:
170*0a6a1f1dSLionel Sambuc.Pp
171*0a6a1f1dSLionel Sambuc.Bl -tag -width indent -compact -offset indent
172*0a6a1f1dSLionel Sambuc.It Ar name
173*0a6a1f1dSLionel SambucThe name of the section being created.
174*0a6a1f1dSLionel Sambuc.It Ar size
175*0a6a1f1dSLionel SambucThe
176*0a6a1f1dSLionel Sambuc.Va sh_size
177*0a6a1f1dSLionel Sambucvalue in the section header.
178*0a6a1f1dSLionel Sambuc.It Ar type
179*0a6a1f1dSLionel SambucThe
180*0a6a1f1dSLionel Sambuc.Va sh_type
181*0a6a1f1dSLionel Sambucvalue in the section header.
182*0a6a1f1dSLionel Sambuc.It Ar flags
183*0a6a1f1dSLionel SambucThe
184*0a6a1f1dSLionel Sambuc.Va sh_flags
185*0a6a1f1dSLionel Sambucvalue in the section header.
186*0a6a1f1dSLionel Sambuc.It Ar link
187*0a6a1f1dSLionel SambucThe
188*0a6a1f1dSLionel Sambuc.Va sh_link
189*0a6a1f1dSLionel Sambucvalue in the section header.
190*0a6a1f1dSLionel Sambuc.It Ar info
191*0a6a1f1dSLionel SambucThe
192*0a6a1f1dSLionel Sambuc.Va sh_info
193*0a6a1f1dSLionel Sambucvalue in the section header.
194*0a6a1f1dSLionel Sambuc.El
195*0a6a1f1dSLionel Sambuc.Pp
196*0a6a1f1dSLionel SambucOn success, the callback function should return the section index
197*0a6a1f1dSLionel Sambucvalue of the created section, and set the location pointed to by
198*0a6a1f1dSLionel Sambucargument
199*0a6a1f1dSLionel Sambuc.Ar index
200*0a6a1f1dSLionel Sambucto the symbol table index of the symbol that associated with the newly
201*0a6a1f1dSLionel Sambuccreated section.
202*0a6a1f1dSLionel SambucThis symbol table index will be used in relocation entries
203*0a6a1f1dSLionel Sambucreferring to the created section.
204*0a6a1f1dSLionel Sambuc.Pp
205*0a6a1f1dSLionel SambucIn case of failure, the callback function should return -1 and set the
206*0a6a1f1dSLionel Sambuclocation pointed to by argument
207*0a6a1f1dSLionel Sambuc.Ar error
208*0a6a1f1dSLionel Sambucto an application-defined error code.
209*0a6a1f1dSLionel SambucThis application returned error code is currently ignored by the
210*0a6a1f1dSLionel Sambuclibrary.
211*0a6a1f1dSLionel Sambuc.Pp
212*0a6a1f1dSLionel SambucFunction
213*0a6a1f1dSLionel Sambuc.Fn dwarf_producer_init
214*0a6a1f1dSLionel Sambucis deprecated.
215*0a6a1f1dSLionel SambucFunction
216*0a6a1f1dSLionel Sambuc.Fn dwarf_producer_init
217*0a6a1f1dSLionel Sambucis identical to function
218*0a6a1f1dSLionel Sambuc.Fn dwarf_producer_init_b
219*0a6a1f1dSLionel Sambucexcept that the callback function it expects can not properly handle
220*0a6a1f1dSLionel Sambucarbitrary section symbol index values.
221*0a6a1f1dSLionel Sambuc.Ss Memory Management
222*0a6a1f1dSLionel SambucThe
223*0a6a1f1dSLionel Sambuc.Vt Dwarf_P_Debug
224*0a6a1f1dSLionel Sambucinstance returned by these functions should be freed using the
225*0a6a1f1dSLionel Sambucfunction
226*0a6a1f1dSLionel Sambuc.Fn dwarf_producer_finish .
227*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES
228*0a6a1f1dSLionel SambucOn success, these functions return the created DWARF producer
229*0a6a1f1dSLionel Sambucdescriptor.
230*0a6a1f1dSLionel SambucIn case of an error, they return
231*0a6a1f1dSLionel Sambuc.Dv DW_DLV_BADADDR
232*0a6a1f1dSLionel Sambucand set the argument
233*0a6a1f1dSLionel Sambuc.Ar err .
234*0a6a1f1dSLionel Sambuc.Sh ERRORS
235*0a6a1f1dSLionel SambucThese functions can fail with:
236*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
237*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
238*0a6a1f1dSLionel SambucArgument
239*0a6a1f1dSLionel Sambuc.Ar func
240*0a6a1f1dSLionel Sambucwas NULL.
241*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
242*0a6a1f1dSLionel SambucThe flag
243*0a6a1f1dSLionel Sambuc.Dv DW_DLC_WRITE
244*0a6a1f1dSLionel Sambucwas not set in argument
245*0a6a1f1dSLionel Sambuc.Ar flags .
246*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
247*0a6a1f1dSLionel SambucThe flags
248*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SIZE_32
249*0a6a1f1dSLionel Sambucand
250*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SIZE_64
251*0a6a1f1dSLionel Sambucwere both set in argument
252*0a6a1f1dSLionel Sambuc.Ar flags .
253*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
254*0a6a1f1dSLionel SambucThe flags
255*0a6a1f1dSLionel Sambuc.Dv DW_DLC_ISA_IA64
256*0a6a1f1dSLionel Sambucand
257*0a6a1f1dSLionel Sambuc.Dv DW_DLC_ISA_MIPS
258*0a6a1f1dSLionel Sambucwere both set in argument
259*0a6a1f1dSLionel Sambuc.Ar flags .
260*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
261*0a6a1f1dSLionel SambucThe flags
262*0a6a1f1dSLionel Sambuc.Dv DW_DLC_TARGET_BIGENDIAN
263*0a6a1f1dSLionel Sambucand
264*0a6a1f1dSLionel Sambuc.Dv DW_DLC_TARGET_LITTLEENDIAN
265*0a6a1f1dSLionel Sambucwere both set in argument
266*0a6a1f1dSLionel Sambuc.Ar flags .
267*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
268*0a6a1f1dSLionel SambucThe flags
269*0a6a1f1dSLionel Sambuc.Dv DW_DLC_STREAM_RELOCATIONS
270*0a6a1f1dSLionel Sambucand
271*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SYMBOLIC_RELOCATIONS
272*0a6a1f1dSLionel Sambucwere both set in argument
273*0a6a1f1dSLionel Sambuc.Ar flags .
274*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_MEMORY
275*0a6a1f1dSLionel SambucAn out of memory condition was encountered.
276*0a6a1f1dSLionel Sambuc.El
277*0a6a1f1dSLionel Sambuc.Sh EXAMPLES
278*0a6a1f1dSLionel SambucTo initialize a
279*0a6a1f1dSLionel Sambuc.Vt Dwarf_P_Debug
280*0a6a1f1dSLionel Sambucinstance for a MIPS32 big endian object, use:
281*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent
282*0a6a1f1dSLionel SambucDwarf_P_Debug dbg;
283*0a6a1f1dSLionel SambucDwarf_Unsigned flags;
284*0a6a1f1dSLionel SambucDwarf_Error de;
285*0a6a1f1dSLionel Sambuc
286*0a6a1f1dSLionel Sambuc/* ... assume cb_func points to the callback function ... */
287*0a6a1f1dSLionel Sambuc
288*0a6a1f1dSLionel Sambucflags = DW_DLC_WRITE | DW_DLC_SIZE_32 | DW_DLC_ISA_MIPS |
289*0a6a1f1dSLionel Sambuc    DW_DLC_STREAM_RELOCATIONS | DW_DLC_TARGET_BIGENDIAN;
290*0a6a1f1dSLionel Sambucif ((dbg = dwarf_producer_init(flags, cb_func, NULL, NULL, &de)) ==
291*0a6a1f1dSLionel Sambuc    DW_DLV_BADADDR)
292*0a6a1f1dSLionel Sambuc	warnx("dwarf_producer_init failed: %s", dwarf_errmsg(-1));
293*0a6a1f1dSLionel Sambuc.Ed
294*0a6a1f1dSLionel Sambuc.Sh SEE ALSO
295*0a6a1f1dSLionel Sambuc.Xr dwarf 3 ,
296*0a6a1f1dSLionel Sambuc.Xr dwarf_errmsg 3 ,
297*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_finish 3 ,
298*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_set_isa 3 ,
299*0a6a1f1dSLionel Sambuc.Xr dwarf_transform_to_disk_form 3
300