xref: /titanic_52/usr/src/lib/libdtrace/sparc/dt_isadep.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
30*7c478bd9Sstevel@tonic-gate #include <assert.h>
31*7c478bd9Sstevel@tonic-gate #include <errno.h>
32*7c478bd9Sstevel@tonic-gate #include <string.h>
33*7c478bd9Sstevel@tonic-gate #include <libgen.h>
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #include <dt_impl.h>
36*7c478bd9Sstevel@tonic-gate #include <dt_pid.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #define	OP(x)		((x) >> 30)
39*7c478bd9Sstevel@tonic-gate #define	OP2(x)		(((x) >> 22) & 0x07)
40*7c478bd9Sstevel@tonic-gate #define	COND(x)		(((x) >> 25) & 0x0f)
41*7c478bd9Sstevel@tonic-gate #define	A(x)		(((x) >> 29) & 0x01)
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #define	OP_BRANCH	0
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #define	OP2_BPcc	0x1
46*7c478bd9Sstevel@tonic-gate #define	OP2_Bicc	0x2
47*7c478bd9Sstevel@tonic-gate #define	OP2_BPr		0x3
48*7c478bd9Sstevel@tonic-gate #define	OP2_FBPfcc	0x5
49*7c478bd9Sstevel@tonic-gate #define	OP2_FBfcc	0x6
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
52*7c478bd9Sstevel@tonic-gate int
53*7c478bd9Sstevel@tonic-gate dt_pid_create_entry_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
54*7c478bd9Sstevel@tonic-gate     fasttrap_probe_spec_t *ftp, const GElf_Sym *symp)
55*7c478bd9Sstevel@tonic-gate {
56*7c478bd9Sstevel@tonic-gate 	ftp->ftps_type = DTFTP_ENTRY;
57*7c478bd9Sstevel@tonic-gate 	ftp->ftps_pc = (uintptr_t)symp->st_value;
58*7c478bd9Sstevel@tonic-gate 	ftp->ftps_size = (size_t)symp->st_size;
59*7c478bd9Sstevel@tonic-gate 	ftp->ftps_noffs = 1;
60*7c478bd9Sstevel@tonic-gate 	ftp->ftps_offs[0] = 0;
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate 	if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
63*7c478bd9Sstevel@tonic-gate 		dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
64*7c478bd9Sstevel@tonic-gate 		    strerror(errno));
65*7c478bd9Sstevel@tonic-gate 		return (dt_set_errno(dtp, errno));
66*7c478bd9Sstevel@tonic-gate 	}
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	return (1);
69*7c478bd9Sstevel@tonic-gate }
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate int
72*7c478bd9Sstevel@tonic-gate dt_pid_create_return_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
73*7c478bd9Sstevel@tonic-gate     fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, uint64_t *stret)
74*7c478bd9Sstevel@tonic-gate {
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	uint32_t *text;
77*7c478bd9Sstevel@tonic-gate 	int i;
78*7c478bd9Sstevel@tonic-gate 	int srdepth = 0;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	if ((text = malloc(symp->st_size + 4)) == NULL) {
81*7c478bd9Sstevel@tonic-gate 		dt_dprintf("mr sparkle: malloc() failed\n");
82*7c478bd9Sstevel@tonic-gate 		return (DT_PROC_ERR);
83*7c478bd9Sstevel@tonic-gate 	}
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 	if (Pread(P, text, symp->st_size, symp->st_value) != symp->st_size) {
86*7c478bd9Sstevel@tonic-gate 		dt_dprintf("mr sparkle: Pread() failed\n");
87*7c478bd9Sstevel@tonic-gate 		free(text);
88*7c478bd9Sstevel@tonic-gate 		return (DT_PROC_ERR);
89*7c478bd9Sstevel@tonic-gate 	}
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 	/*
92*7c478bd9Sstevel@tonic-gate 	 * Leave a dummy instruction in the last slot to simplify edge
93*7c478bd9Sstevel@tonic-gate 	 * conditions.
94*7c478bd9Sstevel@tonic-gate 	 */
95*7c478bd9Sstevel@tonic-gate 	text[symp->st_size / 4] = 0;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	ftp->ftps_type = DTFTP_RETURN;
98*7c478bd9Sstevel@tonic-gate 	ftp->ftps_pc = symp->st_value;
99*7c478bd9Sstevel@tonic-gate 	ftp->ftps_size = symp->st_size;
100*7c478bd9Sstevel@tonic-gate 	ftp->ftps_noffs = 0;
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < symp->st_size / 4; i++) {
103*7c478bd9Sstevel@tonic-gate 		/*
104*7c478bd9Sstevel@tonic-gate 		 * If we encounter an existing tracepoint, query the
105*7c478bd9Sstevel@tonic-gate 		 * kernel to find out the instruction that was
106*7c478bd9Sstevel@tonic-gate 		 * replaced at this spot.
107*7c478bd9Sstevel@tonic-gate 		 */
108*7c478bd9Sstevel@tonic-gate 		while (text[i] == FASTTRAP_INSTR) {
109*7c478bd9Sstevel@tonic-gate 			fasttrap_instr_query_t instr;
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 			instr.ftiq_pid = Pstatus(P)->pr_pid;
112*7c478bd9Sstevel@tonic-gate 			instr.ftiq_pc = symp->st_value + i * 4;
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 			if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_GETINSTR,
115*7c478bd9Sstevel@tonic-gate 			    &instr) != 0) {
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 				if (errno == ESRCH || errno == ENOENT) {
118*7c478bd9Sstevel@tonic-gate 					if (Pread(P, &text[i], 4,
119*7c478bd9Sstevel@tonic-gate 					    instr.ftiq_pc) != 4) {
120*7c478bd9Sstevel@tonic-gate 						dt_dprintf("mr sparkle: "
121*7c478bd9Sstevel@tonic-gate 						    "Pread() failed\n");
122*7c478bd9Sstevel@tonic-gate 						free(text);
123*7c478bd9Sstevel@tonic-gate 						return (DT_PROC_ERR);
124*7c478bd9Sstevel@tonic-gate 					}
125*7c478bd9Sstevel@tonic-gate 					continue;
126*7c478bd9Sstevel@tonic-gate 				}
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 				free(text);
129*7c478bd9Sstevel@tonic-gate 				dt_dprintf("mr sparkle: getinstr query "
130*7c478bd9Sstevel@tonic-gate 				    "failed: %s\n", strerror(errno));
131*7c478bd9Sstevel@tonic-gate 				return (DT_PROC_ERR);
132*7c478bd9Sstevel@tonic-gate 			}
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 			text[i] = instr.ftiq_instr;
135*7c478bd9Sstevel@tonic-gate 			break;
136*7c478bd9Sstevel@tonic-gate 		}
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 		/* save */
139*7c478bd9Sstevel@tonic-gate 		if ((text[i] & 0xc1f80000) == 0x81e00000) {
140*7c478bd9Sstevel@tonic-gate 			srdepth++;
141*7c478bd9Sstevel@tonic-gate 			continue;
142*7c478bd9Sstevel@tonic-gate 		}
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 		/* restore */
145*7c478bd9Sstevel@tonic-gate 		if ((text[i] & 0xc1f80000) == 0x81e80000) {
146*7c478bd9Sstevel@tonic-gate 			srdepth--;
147*7c478bd9Sstevel@tonic-gate 			continue;
148*7c478bd9Sstevel@tonic-gate 		}
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 		if (srdepth > 0) {
151*7c478bd9Sstevel@tonic-gate 			/* ret */
152*7c478bd9Sstevel@tonic-gate 			if (text[i] == 0x81c7e008)
153*7c478bd9Sstevel@tonic-gate 				goto is_ret;
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 			/* return */
156*7c478bd9Sstevel@tonic-gate 			if (text[i] == 0x81cfe008)
157*7c478bd9Sstevel@tonic-gate 				goto is_ret;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 			/* call or jmpl w/ restore in the slot */
160*7c478bd9Sstevel@tonic-gate 			if (((text[i] & 0xc0000000) == 0x40000000 ||
161*7c478bd9Sstevel@tonic-gate 			    (text[i] & 0xc1f80000) == 0x81c00000) &&
162*7c478bd9Sstevel@tonic-gate 			    (text[i + 1] & 0xc1f80000) == 0x81e80000)
163*7c478bd9Sstevel@tonic-gate 				goto is_ret;
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 			/* call to one of the stret routines */
166*7c478bd9Sstevel@tonic-gate 			if ((text[i] & 0xc0000000) == 0x40000000) {
167*7c478bd9Sstevel@tonic-gate 				int32_t	disp = text[i] << 2;
168*7c478bd9Sstevel@tonic-gate 				uint64_t dest = ftp->ftps_pc + i * 4 + disp;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 				dt_dprintf("dest = %llx\n", (u_longlong_t)dest);
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 				if (dest == stret[0] || dest == stret[1] ||
173*7c478bd9Sstevel@tonic-gate 				    dest == stret[2] || dest == stret[3])
174*7c478bd9Sstevel@tonic-gate 					goto is_ret;
175*7c478bd9Sstevel@tonic-gate 			}
176*7c478bd9Sstevel@tonic-gate 		} else {
177*7c478bd9Sstevel@tonic-gate 			/* external call */
178*7c478bd9Sstevel@tonic-gate 			if ((text[i] & 0xc0000000) == 0x40000000) {
179*7c478bd9Sstevel@tonic-gate 				int32_t dst = text[i] << 2;
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 				dst += i * 4;
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 				if ((uintptr_t)dst >= (uintptr_t)symp->st_size)
184*7c478bd9Sstevel@tonic-gate 					goto is_ret;
185*7c478bd9Sstevel@tonic-gate 			}
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 			/* jmpl into %g0 -- this includes the retl pseudo op */
188*7c478bd9Sstevel@tonic-gate 			if ((text[i] & 0xfff80000) == 0x81c00000)
189*7c478bd9Sstevel@tonic-gate 				goto is_ret;
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 			/* external branch -- possible return site */
192*7c478bd9Sstevel@tonic-gate 			if (OP(text[i]) == OP_BRANCH) {
193*7c478bd9Sstevel@tonic-gate 				int32_t dst;
194*7c478bd9Sstevel@tonic-gate 				int baa;
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 				switch (OP2(text[i])) {
197*7c478bd9Sstevel@tonic-gate 				case OP2_BPcc:
198*7c478bd9Sstevel@tonic-gate 					dst = text[i] & 0x7ffff;
199*7c478bd9Sstevel@tonic-gate 					dst <<= 13;
200*7c478bd9Sstevel@tonic-gate 					dst >>= 11;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate 					baa = COND(text[i]) == 8 && A(text[i]);
203*7c478bd9Sstevel@tonic-gate 					break;
204*7c478bd9Sstevel@tonic-gate 				case OP2_Bicc:
205*7c478bd9Sstevel@tonic-gate 					dst = text[i] & 0x3fffff;
206*7c478bd9Sstevel@tonic-gate 					dst <<= 10;
207*7c478bd9Sstevel@tonic-gate 					dst >>= 8;
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 					baa = COND(text[i]) == 8 && A(text[i]);
210*7c478bd9Sstevel@tonic-gate 					break;
211*7c478bd9Sstevel@tonic-gate 				case OP2_BPr:
212*7c478bd9Sstevel@tonic-gate 					dst = (((text[i]) >> 6) & 0xc000) |
213*7c478bd9Sstevel@tonic-gate 					    ((text[i]) & 0x3fff);
214*7c478bd9Sstevel@tonic-gate 					dst <<= 16;
215*7c478bd9Sstevel@tonic-gate 					dst >>= 14;
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 					baa = 0;
218*7c478bd9Sstevel@tonic-gate 					break;
219*7c478bd9Sstevel@tonic-gate 				case OP2_FBPfcc:
220*7c478bd9Sstevel@tonic-gate 					dst = text[i] & 0x7ffff;
221*7c478bd9Sstevel@tonic-gate 					dst <<= 13;
222*7c478bd9Sstevel@tonic-gate 					dst >>= 11;
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 					baa = COND(text[i]) == 8 && A(text[i]);
225*7c478bd9Sstevel@tonic-gate 					break;
226*7c478bd9Sstevel@tonic-gate 				case OP2_FBfcc:
227*7c478bd9Sstevel@tonic-gate 					dst = text[i] & 0x3fffff;
228*7c478bd9Sstevel@tonic-gate 					dst <<= 10;
229*7c478bd9Sstevel@tonic-gate 					dst >>= 8;
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate 					baa = COND(text[i]) == 8 && A(text[i]);
232*7c478bd9Sstevel@tonic-gate 					break;
233*7c478bd9Sstevel@tonic-gate 				default:
234*7c478bd9Sstevel@tonic-gate 					continue;
235*7c478bd9Sstevel@tonic-gate 				}
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 				dst += i * 4;
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate 				/*
240*7c478bd9Sstevel@tonic-gate 				 * Interpret branches outside of the function's
241*7c478bd9Sstevel@tonic-gate 				 * bounds as potential return sites. If the
242*7c478bd9Sstevel@tonic-gate 				 * branch is a ba,a don't skip the instruction
243*7c478bd9Sstevel@tonic-gate 				 * in the delay slot.
244*7c478bd9Sstevel@tonic-gate 				 */
245*7c478bd9Sstevel@tonic-gate 				if ((uintptr_t)dst >=
246*7c478bd9Sstevel@tonic-gate 				    (uintptr_t)symp->st_size) {
247*7c478bd9Sstevel@tonic-gate 					if (baa)
248*7c478bd9Sstevel@tonic-gate 						goto is_ret_baa;
249*7c478bd9Sstevel@tonic-gate 					else
250*7c478bd9Sstevel@tonic-gate 						goto is_ret;
251*7c478bd9Sstevel@tonic-gate 				}
252*7c478bd9Sstevel@tonic-gate 			}
253*7c478bd9Sstevel@tonic-gate 		}
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 		continue;
256*7c478bd9Sstevel@tonic-gate is_ret:
257*7c478bd9Sstevel@tonic-gate 		i++;
258*7c478bd9Sstevel@tonic-gate is_ret_baa:
259*7c478bd9Sstevel@tonic-gate 		dt_dprintf("return at offset %x\n", i * 4);
260*7c478bd9Sstevel@tonic-gate 		ftp->ftps_offs[ftp->ftps_noffs++] = i * 4;
261*7c478bd9Sstevel@tonic-gate 	}
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	free(text);
264*7c478bd9Sstevel@tonic-gate 	if (ftp->ftps_noffs > 0) {
265*7c478bd9Sstevel@tonic-gate 		if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
266*7c478bd9Sstevel@tonic-gate 			dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
267*7c478bd9Sstevel@tonic-gate 			    strerror(errno));
268*7c478bd9Sstevel@tonic-gate 			return (dt_set_errno(dtp, errno));
269*7c478bd9Sstevel@tonic-gate 		}
270*7c478bd9Sstevel@tonic-gate 	}
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	return (ftp->ftps_noffs);
274*7c478bd9Sstevel@tonic-gate }
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
277*7c478bd9Sstevel@tonic-gate int
278*7c478bd9Sstevel@tonic-gate dt_pid_create_offset_probe(struct ps_prochandle *P, dtrace_hdl_t *dtp,
279*7c478bd9Sstevel@tonic-gate     fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, ulong_t off)
280*7c478bd9Sstevel@tonic-gate {
281*7c478bd9Sstevel@tonic-gate 	if (off & 0x3)
282*7c478bd9Sstevel@tonic-gate 		return (DT_PROC_ALIGN);
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate 	ftp->ftps_type = DTFTP_OFFSETS;
285*7c478bd9Sstevel@tonic-gate 	ftp->ftps_pc = (uintptr_t)symp->st_value;
286*7c478bd9Sstevel@tonic-gate 	ftp->ftps_size = (size_t)symp->st_size;
287*7c478bd9Sstevel@tonic-gate 	ftp->ftps_noffs = 1;
288*7c478bd9Sstevel@tonic-gate 	ftp->ftps_offs[0] = off;
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate 	if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
291*7c478bd9Sstevel@tonic-gate 		dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
292*7c478bd9Sstevel@tonic-gate 		    strerror(errno));
293*7c478bd9Sstevel@tonic-gate 		return (dt_set_errno(dtp, errno));
294*7c478bd9Sstevel@tonic-gate 	}
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	return (1);
297*7c478bd9Sstevel@tonic-gate }
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
300*7c478bd9Sstevel@tonic-gate int
301*7c478bd9Sstevel@tonic-gate dt_pid_create_glob_offset_probes(struct ps_prochandle *P, dtrace_hdl_t *dtp,
302*7c478bd9Sstevel@tonic-gate     fasttrap_probe_spec_t *ftp, const GElf_Sym *symp, const char *pattern)
303*7c478bd9Sstevel@tonic-gate {
304*7c478bd9Sstevel@tonic-gate 	ulong_t i;
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 	ftp->ftps_type = DTFTP_OFFSETS;
307*7c478bd9Sstevel@tonic-gate 	ftp->ftps_pc = (uintptr_t)symp->st_value;
308*7c478bd9Sstevel@tonic-gate 	ftp->ftps_size = (size_t)symp->st_size;
309*7c478bd9Sstevel@tonic-gate 	ftp->ftps_noffs = 0;
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate 	/*
312*7c478bd9Sstevel@tonic-gate 	 * If we're matching against everything, just iterate through each
313*7c478bd9Sstevel@tonic-gate 	 * instruction in the function, otherwise look for matching offset
314*7c478bd9Sstevel@tonic-gate 	 * names by constructing the string and comparing it against the
315*7c478bd9Sstevel@tonic-gate 	 * pattern.
316*7c478bd9Sstevel@tonic-gate 	 */
317*7c478bd9Sstevel@tonic-gate 	if (strcmp("*", pattern) == 0) {
318*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < symp->st_size; i += 4) {
319*7c478bd9Sstevel@tonic-gate 			ftp->ftps_offs[ftp->ftps_noffs++] = i;
320*7c478bd9Sstevel@tonic-gate 		}
321*7c478bd9Sstevel@tonic-gate 	} else {
322*7c478bd9Sstevel@tonic-gate 		char name[sizeof (i) * 2 + 1];
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < symp->st_size; i += 4) {
325*7c478bd9Sstevel@tonic-gate 			(void) sprintf(name, "%lx", i);
326*7c478bd9Sstevel@tonic-gate 			if (gmatch(name, pattern))
327*7c478bd9Sstevel@tonic-gate 				ftp->ftps_offs[ftp->ftps_noffs++] = i;
328*7c478bd9Sstevel@tonic-gate 		}
329*7c478bd9Sstevel@tonic-gate 	}
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 	if (ioctl(dtp->dt_ftfd, FASTTRAPIOC_MAKEPROBE, ftp) != 0) {
332*7c478bd9Sstevel@tonic-gate 		dt_dprintf("fasttrap probe creation ioctl failed: %s\n",
333*7c478bd9Sstevel@tonic-gate 		    strerror(errno));
334*7c478bd9Sstevel@tonic-gate 		return (dt_set_errno(dtp, errno));
335*7c478bd9Sstevel@tonic-gate 	}
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	return (ftp->ftps_noffs);
338*7c478bd9Sstevel@tonic-gate }
339