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

/* ... assume cb_func points to the callback function ... */

flags = DW_DLC_WRITE | DW_DLC_SIZE_32 | DW_DLC_ISA_MIPS |
    DW_DLC_STREAM_RELOCATIONS | DW_DLC_TARGET_BIGENDIAN;
if ((dbg = dwarf_producer_init(flags, cb_func, NULL, NULL, &de)) ==
    DW_DLV_BADADDR)
	warnx("dwarf_producer_init failed: %s", dwarf_errmsg(-1));
.Ed
.Sh SEE ALSO
.Xr dwarf 3 ,
.Xr dwarf_errmsg 3 ,
.Xr dwarf_producer_finish 3 ,
.Xr dwarf_producer_set_isa 3 ,
.Xr dwarf_transform_to_disk_form 3