summaryrefslogtreecommitdiffstats
path: root/rtemstoolkit/elftoolchain/libdwarf/dwarf_object_init.3
blob: 2915669155e1c1da63ae376a0b166dd6618eb5e2 (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
.\" Copyright (c) 2011 Joseph Koshy
.\" 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_object_init.3 2074 2011-10-27 03:34:33Z jkoshy $
.\"
.Dd September 29, 2011
.Os
.Dt DWARF_OBJECT_INIT 3
.Sh NAME
.Nm dwarf_object_init
.Nd allocate a DWARF debug descriptor with application-specific file \
access methods
.Sh LIBRARY
.Lb libdwarf
.Sh SYNOPSIS
.In libdwarf.h
.Ft int
.Fo dwarf_object_init
.Fa "Dwarf_Obj_Access_Interface *iface"
.Fa "Dwarf_Handler errhand"
.Fa "Dwarf_Ptr errarg"
.Fa "Dwarf_Debug *dbg"
.Fa "Dwarf_Error *err"
.Fc
.Sh DESCRIPTION
.Pp
The
.Fn dwarf_object_init
function allocates and returns a
.Vt Dwarf_Debug
instance that uses application-supplied access methods to read file
content.
.Pp
The argument
.Ar iface
should point to a populated
.Vt Dwarf_Obj_Access_Interface
structure.
The contents of the
.Vt Dwarf_Obj_Access_Interface
structure are described in the section
.Sx "Object Access Functions"
below.
.Pp
The argument
.Ar errhand
should point to a function to be called in case of an error.
If this argument is
.Dv NULL
then a default error handling scheme is used.
See
.Xr dwarf 3
for a description of the error handling schemes available.
.Pp
The argument
.Ar errarg
will be passed to the error handler function pointed to by argument
.Ar errhand .
.Pp
The argument
.Ar dbg
should point to a memory location that will be set to a reference to
the returned
.Vt Dwarf_Debug
descriptor.
.Pp
The argument
.Ar err
will be used to return a
.Vt Dwarf_Error
descriptor in case of an error.
.Ss Object Access Functions
The data structures used to specify object access methods are defined
in
.In libdwarf.h .
.Bl -tag -width indent
.It Vt "Dwarf_Obj_Access_Interface"
This structure bundles together a set of file access methods along
with a pointer to application-private state.
.Bd -literal -offset indent
typedef struct {
	void *object;
	const Dwarf_Obj_Access_Methods *methods;
} Dwarf_Obj_Access_Interface;
.Ed
.Pp
.Bl -tag -width ".Ar methods" -compact
.It Ar object
This field points to application-specific state that will be passed as
the first parameter to the actual access object methods.
.It Ar methods
This structure contains pointers to the functions implementing the
access methods, as described below.
.El
.It Vt Dwarf_Obj_Access_Methods
This structure specifies the functions implementing low-level access.
.Bd -literal -offset indent
typedef struct {
	int (*get_section_info)(void *obj, Dwarf_Half index,
	    Dwarf_Obj_Access_Section *ret, int *error);
	Dwarf_Endianness (*get_byte_order)(void *obj);
	Dwarf_Small (*get_length_size)(void *obj);
	Dwarf_Small (*get_pointer_size)(void *obj);
	Dwarf_Unsigned (*get_section_count)(void *obj);
	int (*load_section)(void *obj, Dwarf_Half ndx,
	    Dwarf_Small **ret_data, int *error);
} Dwarf_Obj_Access_Methods;
.Ed
.Pp
.Bl -tag -width ".Ar get_section_count" -compact
.It Ar get_byte_order
This function should return the endianness of the DWARF object by
returning one of the constants
.Dv DW_OBJECT_MSB
or
.Dv DW_OBJECT_LSB .
.It Ar get_length_size
This function should return the number of bytes needed to represent a
DWARF offset in the object being debugged.
.It Ar get_pointer_size
This function should return the size in bytes, in the object being
debugged, of a memory address.
.It Ar get_section_count
This function should return the number of sections in the object being
debugged.
.It Ar get_section_info
This function should return information about the section at the
index
.Ar ndx
by filling in the structure of type
.Vt Dwarf_Obj_Access_Section
pointed to by argument
.Ar ret .
The
.Vt Dwarf_Obj_Access_Section
structure is described below.
.It Ar load_section
This function should load the section specified by argument
.Ar ndx
into memory and place a pointer to the section's data into
the location pointed to by argument
.Ar ret_data .
.El
.Pp
The argument
.Ar obj
passed to these functions will be set to the pointer value in the
.Ar object
field of the associated
.Vt Dwarf_Obj_Access_Interface
structure.
.Pp
The argument
.Ar error
is used to return an error code in case of an error.
.It Vt Dwarf_Obj_Access_Section
This structure describes the layout of a section in the DWARF object.
.Bd -literal -offset indent
typedef struct {
	Dwarf_Addr addr;
	Dwarf_Unsigned size;
	const char *name;
} Dwarf_Obj_Access_Section;
.Ed
.Pp
.Bl -tag -width ".Ar name" -compact
.It Ar addr
A pointer to the start of the section's data.
.It Ar size
The size of the section in bytes.
.It Ar name
A pointer to a NUL-terminated string containing the name of the
section.
.El
.El
.Sh RETURN VALUES
On success, the
.Fn dwarf_object_init
function returns
.Dv DW_DLV_OK .
In case of an error, the function returns
.Dv DW_DLV_ERROR
and sets the argument
.Ar err.
.Sh ERRORS
The
.Fn dwarf_object_init
function may fail with the following errors:
.Bl -tag -width ".Bq Er DW_DLE_DEBUG_INFO_NULL"
.It Bq Er DW_DLE_ARGUMENT
One of the arguments
.Ar iface
or
.Ar dbg
was NULL.
.It Bq Er DW_DLE_DEBUG_INFO_NULL
The underlying object did not contain debugging information.
.It Bq Er DW_DLE_MEMORY
An out of memory condition was encountered during the execution of the
function.
.El
.Sh SEE ALSO
.Xr dwarf 3 ,
.Xr dwarf_init 3 ,
.Xr dwarf_init_elf 3 ,
.Xr dwarf_object_finish 3