Blame


1 bf8a59fa 2004-04-11 devnull .TH MACH-SYMBOL 3
2 bf8a59fa 2004-04-11 devnull .SH NAME
3 bf8a59fa 2004-04-11 devnull symopen, symclose, indexsym, lookupsym, findsym,
4 bf8a59fa 2004-04-11 devnull lookuplsym, indexlsym, findlsym,
5 bf8a59fa 2004-04-11 devnull symoff, pc2file, file2pc, line2pc, fnbound, fileline,
6 bf8a59fa 2004-04-11 devnull pc2line \- symbol table access functions
7 bf8a59fa 2004-04-11 devnull .SH SYNOPSIS
8 bf8a59fa 2004-04-11 devnull .B #include <u.h>
9 bf8a59fa 2004-04-11 devnull .br
10 bf8a59fa 2004-04-11 devnull .B #include <libc.h>
11 bf8a59fa 2004-04-11 devnull .br
12 bf8a59fa 2004-04-11 devnull .B #include <mach.h>
13 bf8a59fa 2004-04-11 devnull .PP
14 bf8a59fa 2004-04-11 devnull .ta \w'\fBxxxxxx'u +\w'\fBxxxxxx'u
15 bf8a59fa 2004-04-11 devnull .ft B
16 bf8a59fa 2004-04-11 devnull int symopen(Fhdr *hdr)
17 bf8a59fa 2004-04-11 devnull .br
18 bf8a59fa 2004-04-11 devnull void symclose(Fhdr *hdr)
19 bf8a59fa 2004-04-11 devnull .PP
20 bf8a59fa 2004-04-11 devnull .ft B
21 bf8a59fa 2004-04-11 devnull int indexsym(uint n, Symbol *s)
22 bf8a59fa 2004-04-11 devnull .br
23 bf8a59fa 2004-04-11 devnull int lookupsym(char *fn, char *var, Symbol *s)
24 bf8a59fa 2004-04-11 devnull .br
25 bf8a59fa 2004-04-11 devnull int findsym(Loc loc, uint class, Symbol *s)
26 bf8a59fa 2004-04-11 devnull .PP
27 bf8a59fa 2004-04-11 devnull .ft B
28 bf8a59fa 2004-04-11 devnull int indexlsym(Symbol *s1, uint n, Symbol *s2)
29 bf8a59fa 2004-04-11 devnull .br
30 bf8a59fa 2004-04-11 devnull int lookuplsym(Symbol *s1, char *name, Symbol *s2)
31 bf8a59fa 2004-04-11 devnull .br
32 bf8a59fa 2004-04-11 devnull int findlsym(Symbol *s1, Loc loc, Symbol *s2)
33 bf8a59fa 2004-04-11 devnull .PP
34 bf8a59fa 2004-04-11 devnull .ft B
35 bf8a59fa 2004-04-11 devnull int symoff(char *a, uint n, ulong addr, uint class)
36 bf8a59fa 2004-04-11 devnull .PP
37 bf8a59fa 2004-04-11 devnull .ft B
38 bf8a59fa 2004-04-11 devnull int pc2file(ulong pc, char *file, uint n, ulong *line)
39 bf8a59fa 2004-04-11 devnull .br
40 bf8a59fa 2004-04-11 devnull int pc2line(ulong pc, ulong *line)
41 bf8a59fa 2004-04-11 devnull .br
42 bf8a59fa 2004-04-11 devnull int fileline(ulong pc, char *buf, uint n)
43 bf8a59fa 2004-04-11 devnull .br
44 bf8a59fa 2004-04-11 devnull int file2pc(char *file, ulong line, ulong *pc)
45 bf8a59fa 2004-04-11 devnull .br
46 bf8a59fa 2004-04-11 devnull int line2pc(ulong basepc, ulong line, ulong *pc)
47 bf8a59fa 2004-04-11 devnull .br
48 bf8a59fa 2004-04-11 devnull int fnbound(ulong pc, ulong bounds[2])
49 bf8a59fa 2004-04-11 devnull .SH DESCRIPTION
50 bf8a59fa 2004-04-11 devnull These functions provide machine-independent access to the
51 bf8a59fa 2004-04-11 devnull symbol table of an executable file or executing process.
52 bf8a59fa 2004-04-11 devnull .IR Mach (3),
53 bf8a59fa 2004-04-11 devnull .IR mach-file (3),
54 bf8a59fa 2004-04-11 devnull and
55 bf8a59fa 2004-04-11 devnull .IR mach-map (3)
56 bf8a59fa 2004-04-11 devnull describe additional library functions for
57 bf8a59fa 2004-04-11 devnull accessing executable files and executing processes.
58 bf8a59fa 2004-04-11 devnull .PP
59 bf8a59fa 2004-04-11 devnull .IR Symopen
60 bf8a59fa 2004-04-11 devnull uses the data in the
61 bf8a59fa 2004-04-11 devnull .B Fhdr
62 bf8a59fa 2004-04-11 devnull structure filled by
63 bf8a59fa 2004-04-11 devnull .I crackhdr
64 bf8a59fa 2004-04-11 devnull (see
65 bf8a59fa 2004-04-11 devnull .IR mach-file (3))
66 bf8a59fa 2004-04-11 devnull to initialize in-memory structures used to access the symbol
67 bf8a59fa 2004-04-11 devnull tables contained in the file.
68 bf8a59fa 2004-04-11 devnull .IR Symclose
69 bf8a59fa 2004-04-11 devnull frees the structures.
70 bf8a59fa 2004-04-11 devnull The rest of the functions described here access a composite
71 bf8a59fa 2004-04-11 devnull symbol table made up of all currently open tables.
72 bf8a59fa 2004-04-11 devnull .PP
73 bf8a59fa 2004-04-11 devnull The
74 bf8a59fa 2004-04-11 devnull .B Symbol
75 bf8a59fa 2004-04-11 devnull data structure:
76 bf8a59fa 2004-04-11 devnull .IP
77 bf8a59fa 2004-04-11 devnull .RS
78 bf8a59fa 2004-04-11 devnull .ft B
79 bf8a59fa 2004-04-11 devnull .nf
80 bf8a59fa 2004-04-11 devnull typedef struct Symbol Symbol;
81 bf8a59fa 2004-04-11 devnull struct Symbol
82 bf8a59fa 2004-04-11 devnull {
83 bf8a59fa 2004-04-11 devnull char *name;
84 bf8a59fa 2004-04-11 devnull Loc loc;
85 bf8a59fa 2004-04-11 devnull Loc hiloc;
86 bf8a59fa 2004-04-11 devnull char class;
87 bf8a59fa 2004-04-11 devnull char type;
88 bf8a59fa 2004-04-11 devnull \fI...\fP
89 bf8a59fa 2004-04-11 devnull };
90 bf8a59fa 2004-04-11 devnull .fi
91 bf8a59fa 2004-04-11 devnull .RE
92 bf8a59fa 2004-04-11 devnull .LP
93 bf8a59fa 2004-04-11 devnull describes a symbol table entry.
94 bf8a59fa 2004-04-11 devnull The
95 bf8a59fa 2004-04-11 devnull .B value
96 bf8a59fa 2004-04-11 devnull field contains the offset of the symbol within its
97 bf8a59fa 2004-04-11 devnull address space: global variables relative to the beginning
98 bf8a59fa 2004-04-11 devnull of the data segment, text beyond the start of the text
99 bf8a59fa 2004-04-11 devnull segment, and automatic variables and parameters relative
100 bf8a59fa 2004-04-11 devnull to the stack frame. The
101 bf8a59fa 2004-04-11 devnull .B type
102 bf8a59fa 2004-04-11 devnull field contains the type of the symbol:
103 bf8a59fa 2004-04-11 devnull .RS
104 bf8a59fa 2004-04-11 devnull .TP
105 bf8a59fa 2004-04-11 devnull .B T
106 bf8a59fa 2004-04-11 devnull text segment symbol
107 bf8a59fa 2004-04-11 devnull .TP
108 bf8a59fa 2004-04-11 devnull .B t
109 bf8a59fa 2004-04-11 devnull static text segment symbol
110 bf8a59fa 2004-04-11 devnull .TP
111 bf8a59fa 2004-04-11 devnull .B D
112 bf8a59fa 2004-04-11 devnull data segment symbol
113 bf8a59fa 2004-04-11 devnull .TP
114 bf8a59fa 2004-04-11 devnull .B d
115 bf8a59fa 2004-04-11 devnull static data segment symbol
116 bf8a59fa 2004-04-11 devnull .TP
117 bf8a59fa 2004-04-11 devnull .B B
118 bf8a59fa 2004-04-11 devnull bss segment symbol
119 bf8a59fa 2004-04-11 devnull .TP
120 bf8a59fa 2004-04-11 devnull .B b
121 bf8a59fa 2004-04-11 devnull static bss segment symbol
122 bf8a59fa 2004-04-11 devnull .TP
123 bf8a59fa 2004-04-11 devnull .B a
124 bf8a59fa 2004-04-11 devnull automatic (local) variable symbol
125 bf8a59fa 2004-04-11 devnull .TP
126 bf8a59fa 2004-04-11 devnull .B p
127 bf8a59fa 2004-04-11 devnull function parameter symbol
128 bf8a59fa 2004-04-11 devnull .RE
129 bf8a59fa 2004-04-11 devnull .PD
130 bf8a59fa 2004-04-11 devnull .LP
131 bf8a59fa 2004-04-11 devnull The
132 bf8a59fa 2004-04-11 devnull .B class
133 bf8a59fa 2004-04-11 devnull field assigns the symbol to a general class;
134 bf8a59fa 2004-04-11 devnull .BR CTEXT ,
135 bf8a59fa 2004-04-11 devnull .BR CDATA ,
136 bf8a59fa 2004-04-11 devnull .BR CAUTO ,
137 bf8a59fa 2004-04-11 devnull and
138 bf8a59fa 2004-04-11 devnull .B CPARAM
139 bf8a59fa 2004-04-11 devnull are the most popular.
140 bf8a59fa 2004-04-11 devnull .PP
141 bf8a59fa 2004-04-11 devnull .I Indexsym
142 bf8a59fa 2004-04-11 devnull stores information for the
143 bf8a59fa 2004-04-11 devnull .I n th
144 bf8a59fa 2004-04-11 devnull symbol into
145 bf8a59fa 2004-04-11 devnull .IR s .
146 bf8a59fa 2004-04-11 devnull The symbols are ordered by increasing address.
147 bf8a59fa 2004-04-11 devnull .PP
148 bf8a59fa 2004-04-11 devnull .I Lookupsym
149 bf8a59fa 2004-04-11 devnull fills a
150 bf8a59fa 2004-04-11 devnull .B Symbol
151 bf8a59fa 2004-04-11 devnull structure with symbol table information. Global variables
152 bf8a59fa 2004-04-11 devnull and functions are represented by a single name; local variables
153 bf8a59fa 2004-04-11 devnull and parameters are uniquely specified by a function and
154 bf8a59fa 2004-04-11 devnull variable name pair. Arguments
155 bf8a59fa 2004-04-11 devnull .I fn
156 bf8a59fa 2004-04-11 devnull and
157 bf8a59fa 2004-04-11 devnull .I var
158 bf8a59fa 2004-04-11 devnull contain the
159 bf8a59fa 2004-04-11 devnull name of a function and variable, respectively.
160 bf8a59fa 2004-04-11 devnull If both
161 bf8a59fa 2004-04-11 devnull are non-zero, the symbol table is searched for a parameter
162 bf8a59fa 2004-04-11 devnull or automatic variable. If only
163 bf8a59fa 2004-04-11 devnull .I var
164 bf8a59fa 2004-04-11 devnull is
165 bf8a59fa 2004-04-11 devnull zero, the text symbol table is searched for function
166 bf8a59fa 2004-04-11 devnull .IR fn .
167 bf8a59fa 2004-04-11 devnull If only
168 bf8a59fa 2004-04-11 devnull .I fn
169 bf8a59fa 2004-04-11 devnull is zero, the global variable table
170 bf8a59fa 2004-04-11 devnull is searched for
171 bf8a59fa 2004-04-11 devnull .IR var .
172 bf8a59fa 2004-04-11 devnull .PP
173 bf8a59fa 2004-04-11 devnull .I Findsym
174 bf8a59fa 2004-04-11 devnull returns the symbol table entry of type
175 bf8a59fa 2004-04-11 devnull .I class
176 bf8a59fa 2004-04-11 devnull stored near
177 bf8a59fa 2004-04-11 devnull .IR addr .
178 bf8a59fa 2004-04-11 devnull The selected symbol is a global variable or function with
179 bf8a59fa 2004-04-11 devnull address nearest to and less than or equal to
180 bf8a59fa 2004-04-11 devnull .IR addr .
181 bf8a59fa 2004-04-11 devnull Class specification
182 bf8a59fa 2004-04-11 devnull .B CDATA
183 bf8a59fa 2004-04-11 devnull searches only the global variable symbol table; class
184 bf8a59fa 2004-04-11 devnull .B CTEXT
185 bf8a59fa 2004-04-11 devnull limits the search to the text symbol table.
186 bf8a59fa 2004-04-11 devnull Class specification
187 bf8a59fa 2004-04-11 devnull .B CANY
188 bf8a59fa 2004-04-11 devnull searches the text table first, then the global table.
189 bf8a59fa 2004-04-11 devnull .PP
190 bf8a59fa 2004-04-11 devnull .IR Indexlsym ,
191 bf8a59fa 2004-04-11 devnull .IR lookuplsym ,
192 bf8a59fa 2004-04-11 devnull and
193 bf8a59fa 2004-04-11 devnull .IR findlsym
194 bf8a59fa 2004-04-11 devnull are similar to
195 bf8a59fa 2004-04-11 devnull .IR indexsym ,
196 bf8a59fa 2004-04-11 devnull .IR lookupsym ,
197 bf8a59fa 2004-04-11 devnull and
198 bf8a59fa 2004-04-11 devnull .IR findsym ,
199 bf8a59fa 2004-04-11 devnull but operate on the smaller symbol table of parameters and
200 bf8a59fa 2004-04-11 devnull variables local to the function represented by symbol
201 bf8a59fa 2004-04-11 devnull .IR s1 .
202 bf8a59fa 2004-04-11 devnull .PP
203 bf8a59fa 2004-04-11 devnull .I Indexlsym
204 bf8a59fa 2004-04-11 devnull writes symbol information for the
205 bf8a59fa 2004-04-11 devnull .IR n th
206 bf8a59fa 2004-04-11 devnull local symbol of function
207 bf8a59fa 2004-04-11 devnull .I s1
208 bf8a59fa 2004-04-11 devnull to
209 bf8a59fa 2004-04-11 devnull .IR s2 .
210 bf8a59fa 2004-04-11 devnull Function parameters appear first in the ordering, followed by local symbols.
211 bf8a59fa 2004-04-11 devnull .PP
212 bf8a59fa 2004-04-11 devnull .I Lookuplsym
213 bf8a59fa 2004-04-11 devnull writes symbol information for the symbol named
214 bf8a59fa 2004-04-11 devnull .I name
215 bf8a59fa 2004-04-11 devnull in function
216 bf8a59fa 2004-04-11 devnull .I s1
217 bf8a59fa 2004-04-11 devnull to
218 bf8a59fa 2004-04-11 devnull .IR s2 .
219 bf8a59fa 2004-04-11 devnull .PP
220 bf8a59fa 2004-04-11 devnull .I Findlsym
221 bf8a59fa 2004-04-11 devnull searches for a symbol local to the function
222 bf8a59fa 2004-04-11 devnull .I s1
223 bf8a59fa 2004-04-11 devnull whose location is exactly
224 bf8a59fa 2004-04-11 devnull .IR loc ,
225 bf8a59fa 2004-04-11 devnull writing its symbol information to
226 bf8a59fa 2004-04-11 devnull .IR s2 .
227 bf8a59fa 2004-04-11 devnull .I Loc
228 bf8a59fa 2004-04-11 devnull is almost always an indirection through a frame pointer register;
229 bf8a59fa 2004-04-11 devnull the details vary from architecture to architecture.
230 bf8a59fa 2004-04-11 devnull .PP
231 bf8a59fa 2004-04-11 devnull .I Symoff
232 bf8a59fa 2004-04-11 devnull converts a location to a symbol reference.
233 bf8a59fa 2004-04-11 devnull The string containing that reference is of the form
234 bf8a59fa 2004-04-11 devnull `name+offset', where `name' is the name of the
235 bf8a59fa 2004-04-11 devnull nearest symbol with an address less than or equal to the
236 bf8a59fa 2004-04-11 devnull target address, and `offset' is the hexadecimal offset beyond
237 bf8a59fa 2004-04-11 devnull that symbol. If `offset' is zero, only the name of the
238 bf8a59fa 2004-04-11 devnull symbol is printed.
239 bf8a59fa 2004-04-11 devnull If no symbol is found within 4096 bytes of the address, the address
240 bf8a59fa 2004-04-11 devnull is formatted as a hexadecimal address.
241 bf8a59fa 2004-04-11 devnull .I Buf
242 bf8a59fa 2004-04-11 devnull is the address of a buffer of
243 bf8a59fa 2004-04-11 devnull .I n
244 bf8a59fa 2004-04-11 devnull bytes to receive the formatted string.
245 bf8a59fa 2004-04-11 devnull .I Addr
246 bf8a59fa 2004-04-11 devnull is the address to be converted.
247 bf8a59fa 2004-04-11 devnull .I Type
248 bf8a59fa 2004-04-11 devnull is the type code of the search space:
249 bf8a59fa 2004-04-11 devnull .BR CTEXT ,
250 bf8a59fa 2004-04-11 devnull .BR CDATA ,
251 bf8a59fa 2004-04-11 devnull or
252 bf8a59fa 2004-04-11 devnull .BR CANY .
253 bf8a59fa 2004-04-11 devnull .I Symoff
254 bf8a59fa 2004-04-11 devnull returns the length of the formatted string contained in
255 bf8a59fa 2004-04-11 devnull .IR buf .
256 bf8a59fa 2004-04-11 devnull .PP
257 bf8a59fa 2004-04-11 devnull .I Pc2file
258 bf8a59fa 2004-04-11 devnull searches the symbol table to find the file and line number
259 bf8a59fa 2004-04-11 devnull corresponding to the instruction at program counter
260 bf8a59fa 2004-04-11 devnull .IR pc .
261 bf8a59fa 2004-04-11 devnull .I File
262 bf8a59fa 2004-04-11 devnull is the address of a buffer of
263 bf8a59fa 2004-04-11 devnull .I n
264 bf8a59fa 2004-04-11 devnull bytes to receive the file name.
265 bf8a59fa 2004-04-11 devnull .I Line
266 bf8a59fa 2004-04-11 devnull receives the line number.
267 bf8a59fa 2004-04-11 devnull .PP
268 bf8a59fa 2004-04-11 devnull .I Pc2line
269 bf8a59fa 2004-04-11 devnull is like
270 bf8a59fa 2004-04-11 devnull .I pc2file
271 bf8a59fa 2004-04-11 devnull but neglects to return information about the source file.
272 bf8a59fa 2004-04-11 devnull .PP
273 bf8a59fa 2004-04-11 devnull .I Fileline
274 bf8a59fa 2004-04-11 devnull is also like
275 bf8a59fa 2004-04-11 devnull .IR pc2file ,
276 bf8a59fa 2004-04-11 devnull but returns the file and line number in the
277 bf8a59fa 2004-04-11 devnull .IR n -byte
278 bf8a59fa 2004-04-11 devnull text buffer
279 bf8a59fa 2004-04-11 devnull .IR buf ,
280 bf8a59fa 2004-04-11 devnull formatted as
281 bf8a59fa 2004-04-11 devnull `file:line'.
282 bf8a59fa 2004-04-11 devnull .PP
283 bf8a59fa 2004-04-11 devnull .I File2pc
284 bf8a59fa 2004-04-11 devnull performs the opposite mapping:
285 bf8a59fa 2004-04-11 devnull it stores in
286 bf8a59fa 2004-04-11 devnull .I pc
287 bf8a59fa 2004-04-11 devnull a text address associated with
288 bf8a59fa 2004-04-11 devnull line
289 bf8a59fa 2004-04-11 devnull .I line
290 bf8a59fa 2004-04-11 devnull in file
291 bf8a59fa 2004-04-11 devnull .IR file .
292 bf8a59fa 2004-04-11 devnull .PP
293 bf8a59fa 2004-04-11 devnull .I Line2pc
294 bf8a59fa 2004-04-11 devnull is similar: it converts a line number to an
295 bf8a59fa 2004-04-11 devnull instruction address, storing it in
296 bf8a59fa 2004-04-11 devnull .IR pc .
297 bf8a59fa 2004-04-11 devnull Since a line number does not uniquely identify an
298 bf8a59fa 2004-04-11 devnull instruction (e.g., every source file has line 1),
299 bf8a59fa 2004-04-11 devnull .I basepc
300 bf8a59fa 2004-04-11 devnull specifies a text address from which
301 bf8a59fa 2004-04-11 devnull the search begins.
302 bf8a59fa 2004-04-11 devnull Usually this is the address of the first function in the
303 bf8a59fa 2004-04-11 devnull file of interest.
304 bf8a59fa 2004-04-11 devnull .PP
305 bf8a59fa 2004-04-11 devnull .I Fnbound
306 bf8a59fa 2004-04-11 devnull returns the start and end addresses of the function containing
307 bf8a59fa 2004-04-11 devnull the text address supplied as the first argument.
308 bf8a59fa 2004-04-11 devnull The second argument is an array of two unsigned longs;
309 bf8a59fa 2004-04-11 devnull .I fnbound
310 bf8a59fa 2004-04-11 devnull places the bounding addresses of the function in the
311 bf8a59fa 2004-04-11 devnull first and second elements of this array.
312 bf8a59fa 2004-04-11 devnull The start address is the address of the first instruction of the function;
313 bf8a59fa 2004-04-11 devnull the end address is the first address beyond the end of the target function.
314 bf8a59fa 2004-04-11 devnull .PP
315 bf8a59fa 2004-04-11 devnull All functions return 0 on success and \-1 on error.
316 bf8a59fa 2004-04-11 devnull When an error occurs, a message describing it is stored
317 bf8a59fa 2004-04-11 devnull in the system error buffer where it is available via
318 bf8a59fa 2004-04-11 devnull .IR errstr .
319 bf8a59fa 2004-04-11 devnull .SH SOURCE
320 bf8a59fa 2004-04-11 devnull .B /sys/src/libmach
321 bf8a59fa 2004-04-11 devnull .SH "SEE ALSO"
322 bf8a59fa 2004-04-11 devnull .IR mach (3),
323 bf8a59fa 2004-04-11 devnull .IR mach-file (3),
324 bf8a59fa 2004-04-11 devnull .IR mach-map (3)