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
|
.\"
.\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0.
.\" You may only use this file in accordance with the terms of version
.\" 1.0 of the CDDL.
.\"
.\" A full copy of the text of the CDDL should have accompanied this
.\" source. A copy of the CDDL is also available via the Internet at
.\" http://www.illumos.org/license/CDDL.
.\"
.\"
.\" Copyright 2015 Joyent, Inc.
.\"
.Dd May 11, 2016
.Dt PSYMBOL_ITER 3PROC
.Os
.Sh NAME
.Nm Psymbol_iter ,
.Nm Psymbol_iter_by_addr ,
.Nm Psymbol_iter_by_lmid ,
.Nm Psymbol_iter_by_name ,
.Nm Pxsymbol_iter
.Nd iterate symbols in a process
.Sh LIBRARY
.Lb libproc
.Sh SYNOPSIS
.In libproc.h
.Ft int
.Fo Psymbol_iter
.Fa "struct ps_prochandle *P"
.Fa "const char *object_name"
.Fa "int which"
.Fa "int mask"
.Fa "proc_sym_f *func"
.Fa "void *data"
.Fc
.Ft int
.Fo Psymbol_iter_by_addr
.Fa "struct ps_prochandle *P"
.Fa "const char *object_name"
.Fa "int which"
.Fa "int mask"
.Fa "proc_sym_f *func"
.Fa "void *data"
.Fc
.Ft int
.Fo Psymbol_iter_by_lmid
.Fa "struct ps_prochandle *P"
.Fa "Lmid_t lmid"
.Fa "const char *object_name"
.Fa "int which"
.Fa "int mask"
.Fa "proc_sym_f *func"
.Fa "void *data"
.Fc
.Ft int
.Fo Psymbol_iter_by_name
.Fa "struct ps_prochandle *P"
.Fa "const char *object_name"
.Fa "int which"
.Fa "int mask"
.Fa "proc_sym_f *func"
.Fa "void *data"
.Fc
.Ft int
.Fo Pxsymbol_iter
.Fa "struct ps_prochandle *P"
.Fa "Lmid_t lmid"
.Fa "const char *object_name"
.Fa "int which"
.Fa "int mask"
.Fa "proc_xsym_f *func"
.Fa "void *data"
.Fc
.Sh DESCRIPTION
The
.Fn Psymbol_iter ,
.Fn Psymbol_iter_by_addr ,
.Fn Psymbol_iter_by_lmid ,
.Fn Psymbol_iter_by_name ,
and
.Fn Pxsymbol_iter
functions are used to iterate over the symbols present in the process
referred to by the handle
.Fa P .
For each symbol found, the callback function
.Fa func
will be called once and the argument
.Fa data
will be passed to it along with an ELF symbol entry in the form of the
.Sy GElf_Sym
along with the name of the symbol, if known.
In the case of the
.Fn Pxsymbol_iter
function an additional
.Sy prsyminfo_t
argument will be provided to the callback.
The definitions of
.Sy proc_sym_f ,
.Sy proc_xsym_f ,
and
.Sy prsyminfo_t
are found in
.Xr libproc 3LIB .
.Pp
The
.Fa object_name
argument names the object that is a part of the controlled process which
will be searched for symbols.
Only one object may be searched at any given time.
Valid object names may be obtained through the
.Xr Pobjname 3PROC
and
.Xr Pobject_iter 3PROC
functions, among others.
The system also has two special object names that may be passed in to refer to
the objects of the executable file and for ld.so.1.
The symbol
.Dv PR_OBJ_EXEC
refers to the executables object and the symbol
.Dv PR_OBJ_LDSO
refers to the object ld.so.1.
.Pp
The
.Fa which
argument controls which of two possible symbol tables will be searched.
If the argument is
.Dv PR_SYMTAB
then the ELF symbol table will be searched.
Otherwise, if it is
.Dv PR_DYNSYM
then the symbol table associated with the dynamic section will be
searched instead.
If any other value is specified for
.Fa which ,
then an error will be returned.
.Pp
The
.Fa mask
argument controls which symbols will be included.
The
.Fa mask
argument allows for control over both the symbol's binding and the
symbol's type.
These flags logically correspond to the various ELF symbol bindings and types.
The following values may be passed as a bitwise-inclusive-OR into the
.Fa flags
argument:
.Bl -tag -width Dv -offset indent
.It Dv BIND_LOCAL
The symbol is a local symbol.
Local symbols are not visible outside of their object file.
.It Dv BIND_GLOBAL
The symbol is a global symbol.
Global symbols are visible outside of their object file and may be referred to
by other ELF objects.
.It Dv BIND_WEAK
The symbol is a weak symbol.
Weak symbols are visible outside of their object file, but another definition of
the symbol may be used instead.
.It Dv BIND_ANY
This is a combination of
.Dv BIND_LOCAL ,
.Dv BIND_GLOBAL ,
and
.Dv BIND_WEAK .
Every symbol's binding will match this value.
.It Dv TYPE_NOTYPE
The symbol's type is not specified.
.It Dv TYPE_OBJECT
The symbol refers to a data object.
For example, variables.
.It Dv TYPE_FUNC
The symbol refers to a function.
.It Dv TYPE_SECTION
The symbol refers to an ELF section.
.It Dv TYPE_FILE
The symbol refers to the name of a source file associated with an object
file.
.It Dv TYPE_ANY
This is a combination of
.Dv TYPE_NOTYPE ,
.Dv TYPE_OBJECT ,
.Dv TYPE_FUNC ,
.Dv TYPE_SECTION ,
and
.Dv TYPE_FILE .
Every symbol's type will match this value.
.El
.Pp
To obtain all of the symbols in an object, the caller would pass the
expression
.Dv BIND_ANY |
.Dv TYPE_ANY
in as the value of
.Fa mask.
.Pp
The
.Fn Psymbol_iter_by_lmid
and
.Fn Pxsymbol_iter
functions allow for a link-map identifier to be specified in the
.Fa lmid
argument.
This will restrict the search for the object specified in
.Fa object_name
to the specified link-map.
There are three special link-map identifiers that may be passed in.
The symbol
.Dv PR_LMID_EVERY
indicates that every link-map should be searched.
The symbol
.Dv LM_ID_BASE
indicates that the base link-map, the one that is used for the
executable should be searched.
Finally, the symbol
.Dv LM_ID_LDSO
refers to the link-map that is used by the run-time link editor, ld.so.1.
The functions which do not allow a link-map identifier to be specified always
search every link-map.
.Pp
By default, symbols are iterated based on the order of the symbol
table being searched.
However, it is also possible to iterate based on the name of the symbol and
based on the address of the symbol.
To iterate by name use the
.Fn Psymbol_iter_by_name
function.
To iterate by address use the
.Fn Psymbol_iter_by_addr
function.
The
.Fn Psymbol_iter ,
.Fn Psymbol_iter_by_lmid ,
and
.Fn Pxsymbol_iter
functions all sort based on the order of the symbol table.
.Pp
The return value of the callback function
.Fa func
determines whether or not iteration continues.
If
.Fa func
returns
.Sy 0,
then iteration will continue.
However, if
.Fa func
returns non-zero, then iteration will halt and that value will be used
as the return value of the
.Fn Psymbol_iter ,
.Fn Psymbol_iter_by_addr ,
.Fn Psymbol_iter_by_lmid ,
.Fn Psymbol_iter_by_name ,
and
.Fn Pxsymbol_iter
functions.
Because these functions return
.Sy -1
on internal failure, it is recommended that the callback function not return
.Sy -1
to indicate an error so that the caller may distinguish between the
failure of the callback function and the failure of these functions.
.Sh RETURN VALUES
Upon successful completion, the
.Fn Psymbol_iter ,
.Fn Psymbol_iter_by_addr ,
.Fn Psymbol_iter_by_lmid ,
.Fn Psymbol_iter_by_name ,
and
.Fn Pxsymbol_iter
functions return
.Sy 0 .
If there was an internal error then
.Sy -1
is returned.
Otherwise, if the callback function
.Fa func
returns non-zero, then its return value will be returned instead.
.Sh INTERFACE STABILITY
.Sy Uncommitted
.Sh MT-LEVEL
See
.Sy LOCKING
in
.Xr libproc 3LIB .
.Sh SEE ALSO
.Xr elf 3ELF ,
.Xr gelf 3ELF ,
.Xr libproc 3LIB ,
.Xr proc 5
|