summaryrefslogtreecommitdiffstats
path: root/rtemstoolkit/elftoolchain/libdwarf/dwarf_loclist.3
blob: 2e95d74405ae1438fae20d1043d5d9360861e3dc (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
.\" 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_loclist.3 2122 2011-11-09 15:35:14Z jkoshy $
.\"
.Dd November 9, 2011
.Os
.Dt DWARF_LOCLIST 3
.Sh NAME
.Nm dwarf_loclist ,
.Nm dwarf_loclist_n
.Nd retrieve DWARF location expression information
.Sh LIBRARY
.Lb libdwarf
.Sh SYNOPSIS
.In libdwarf.h
.Ft int
.Fo dwarf_loclist
.Fa "Dwarf_Attribute at"
.Fa "Dwarf_Locdesc **llbuf"
.Fa "Dwarf_Signed *listlen"
.Fa "Dwarf_Error *error"
.Fc
.Ft int
.Fo dwarf_loclist_n
.Fa "Dwarf_Attribute at"
.Fa "Dwarf_Locdesc ***llbuf"
.Fa "Dwarf_Signed *listlen"
.Fa "Dwarf_Error *error"
.Fc
.Sh DESCRIPTION
These functions retrieve the location expressions
associated with a DWARF attribute.
.Pp
Note: function
.Fn dwarf_loclist
is deprecated.
New application code should instead use function
.Fn dwarf_loclist_n
.Pp
Function
.Fn dwarf_loclist_n
retrieves the list of location expressions associated with a DWARF
attribute.
Argument
.Ar at
should reference a valid DWARF attribute.
Argument
.Ar llbuf
should point to a location which will hold a returned array of
pointers to
.Vt Dwarf_Locdesc
descriptors.
Argument
.Ar listlen
should point to a location which will be set to the number of
elements contained in the returned array.
If argument
.Ar err
is not NULL, it will be used to store error information in case
of an error.
.Pp
Function
.Fn dwarf_loclist
retrieves the first location expression associated with an attribute.
Argument
.Ar at
should reference a valid DWARF attribute.
Argument
.Ar llbuf
should point to a location which will hold the returned pointer
to a
.Vt Dwarf_Locdesc
descriptor.
Argument
.Ar listlen
should point to a location which will be always set to 1.
If argument
.Ar err
is not NULL, it will be used to store error information in case
of an error.
.Pp
.Vt Dwarf_Locdesc
descriptors are defined in the header file
.In libdwarf.h ,
and consist of following fields:
.Pp
.Bl -tag -width ".Va ld_cents" -compact
.It Va ld_lopc
The lowest program counter address covered by the descriptor.
This field will be set to 0 if the descriptor is not associated with
an address range.
.It Va ld_hipc
The highest program counter address covered by the descriptor.
This field will be set to 0 if the descriptor is not associated with
an address range.
.It Va ld_cents
The number of entries returned in
.Va ld_s
field.
.It Va ld_s
Pointer to an array of
.Vt Dwarf_Loc
descriptors.
.El
.Pp
Each
.Vt Dwarf_Loc
descriptor represents one operation of a location expression.
These descriptors are defined in the header file
.In libdwarf.h ,
and consist of following fields:
.Pp
.Bl -tag -width ".Va lr_number2" -compact
.It Va lr_atom
The operator name, one of the
.Dv DW_OP_*
constants defined in the header file
.In dwarf.h .
.It Va lr_number
The first operand of this operation.
.It Va lr_number2
The second operand of this operation.
.It Va lr_offset
The byte offset of this operation within the containing location
expression.
.El
.Ss Memory Management
The memory area used for the descriptor array returned in argument
.Ar llbuf
is allocated by the
.Lb libdwarf .
When the descriptor array is no longer needed, application code should
use function
.Xr dwarf_dealloc 3
to free the memory area in the following manner:
.Bl -enum
.It
First, the
.Ar ld_s
field of each
.Vt Dwarf_Locdesc
descriptor should be deallocated using the allocation type
.Dv DW_DLA_LOC_BLOCK .
.It
Then, the application should free each
.Vt Dwarf_Locdesc
descriptor using the allocation type
.Dv DW_DLA_LOCDESC .
.It
Finally, the
.Va llbuf
pointer should be deallocated using the allocation type
.Dv DW_DLA_LIST .
.El
.Sh RETURN VALUES
On success, these functions returns
.Dv DW_DLV_OK .
In case of an error, they return
.Dv DW_DLV_ERROR
and set the argument
.Ar err .
.Sh ERRORS
These functions can fail with:
.Bl -tag -width ".Bq Er DW_DLE_ARGUMENT"
.It Bq Er DW_DLE_ARGUMENT
One of the arguments
.Ar at ,
.Ar llbuf
or
.Ar listlen
was NULL.
.It Bq Er DW_DLE_ARGUMENT
The attribute provided by argument
.Ar at
does not contain a location expression or is not associated with a
location expression list.
.El
.Sh EXAMPLE
To retrieve the location list associated with an attribute, use:
.Bd -literal -offset indent
Dwarf_Attribute at;
Dwarf_Locdesc **llbuf;
Dwarf_Signed lcnt;
Dwarf_Loc *lr;
Dwarf_Error de;
int i;

if (dwarf_loclist_n(at, &llbuf, &lcnt, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_loclist_n failed: %s",
	    dwarf_errmsg(de));

for (i = 0; i < lcnt; i++) {
	/* ... Use llbuf[i] ... */
	for (j = 0; (Dwarf_Half) j < llbuf[i]->ld_cents; j++) {
		lr = &llbuf[i]->ld_s[j];
		/* ... Use each Dwarf_Loc descriptor ... */
	}
	dwarf_dealloc(dbg, llbuf[i]->ld_s, DW_DLA_LOC_BLOCK);
	dwarf_dealloc(dbg, llbuf[i], DW_DLA_LOCDESC);
}
dwarf_dealloc(dbg, llbuf, DW_DLA_LIST);
.Ed
.Sh SEE ALSO
.Xr dwarf 3 ,
.Xr dwarf_dealloc 3 ,
.Xr dwarf_loclist_from_expr 3 ,
.Xr dwarf_loclist_from_expr_a 3 ,
.Xr dwarf_get_loclist_entry 3