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 (c) 1994, by Sun Microsytems, Inc.
24*7c478bd9Sstevel@tonic-gate */
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate * Includes
30*7c478bd9Sstevel@tonic-gate */
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
33*7c478bd9Sstevel@tonic-gate #include <string.h>
34*7c478bd9Sstevel@tonic-gate #include <libintl.h>
35*7c478bd9Sstevel@tonic-gate #include "queue.h"
36*7c478bd9Sstevel@tonic-gate #include "set.h"
37*7c478bd9Sstevel@tonic-gate #include "fcn.h"
38*7c478bd9Sstevel@tonic-gate #include "new.h"
39*7c478bd9Sstevel@tonic-gate #include "source.h"
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate * Globals
44*7c478bd9Sstevel@tonic-gate */
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate static queue_node_t g_fcnlist = {
47*7c478bd9Sstevel@tonic-gate &g_fcnlist,
48*7c478bd9Sstevel@tonic-gate &g_fcnlist};
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate * Forward Declarations
52*7c478bd9Sstevel@tonic-gate */
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate static void fcn_destroy(fcn_t * fcn_p);
55*7c478bd9Sstevel@tonic-gate static void fcn_print(FILE * stream, fcn_t * fcn_p);
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate /*
59*7c478bd9Sstevel@tonic-gate * fcn() - builds a function block and inserts it on the global list.
60*7c478bd9Sstevel@tonic-gate */
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate #define NSYMS 1
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate void
fcn(char * name_p,char * entry_name_p)65*7c478bd9Sstevel@tonic-gate fcn(char *name_p, char *entry_name_p)
66*7c478bd9Sstevel@tonic-gate {
67*7c478bd9Sstevel@tonic-gate fcn_t *new_p;
68*7c478bd9Sstevel@tonic-gate fcn_t *old_p;
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate /* does this setname exist already? */
71*7c478bd9Sstevel@tonic-gate old_p = fcn_find(name_p);
72*7c478bd9Sstevel@tonic-gate if (old_p)
73*7c478bd9Sstevel@tonic-gate fcn_destroy(old_p);
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate /* create a new set */
76*7c478bd9Sstevel@tonic-gate new_p = new(fcn_t);
77*7c478bd9Sstevel@tonic-gate queue_init(&new_p->qn);
78*7c478bd9Sstevel@tonic-gate new_p->name_p = name_p;
79*7c478bd9Sstevel@tonic-gate new_p->entry_name_p = entry_name_p;
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate #ifdef OLD
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate * allocate a target function block, and stuff the init and fini
84*7c478bd9Sstevel@tonic-gate * addrs
85*7c478bd9Sstevel@tonic-gate */
86*7c478bd9Sstevel@tonic-gate prbstat = prb_targmem_alloc(g_procfd, sizeof (probe_funcs_t),
87*7c478bd9Sstevel@tonic-gate &new_p->funcs_p);
88*7c478bd9Sstevel@tonic-gate if (prbstat) {
89*7c478bd9Sstevel@tonic-gate semantic_err(gettext("problem allocating target memory"));
90*7c478bd9Sstevel@tonic-gate goto Error;
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate prbstat = prb_proc_write(g_procfd, new_p->funcs_p,
93*7c478bd9Sstevel@tonic-gate &new_p->funcs, sizeof (probe_funcs_t));
94*7c478bd9Sstevel@tonic-gate if (prbstat) {
95*7c478bd9Sstevel@tonic-gate semantic_err(gettext(
96*7c478bd9Sstevel@tonic-gate "setup problem, initial/final "
97*7c478bd9Sstevel@tonic-gate "funcs in target memory"));
98*7c478bd9Sstevel@tonic-gate goto Error;
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate #endif
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate /* append the new set to the global list */
103*7c478bd9Sstevel@tonic-gate (void) queue_append(&g_fcnlist, &new_p->qn);
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gate return;
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gate Error:
108*7c478bd9Sstevel@tonic-gate if (new_p)
109*7c478bd9Sstevel@tonic-gate free(new_p);
110*7c478bd9Sstevel@tonic-gate return;
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate } /* end fcn */
113*7c478bd9Sstevel@tonic-gate
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate /*
116*7c478bd9Sstevel@tonic-gate * fcn_destroy() - destroys a fcn and related resources
117*7c478bd9Sstevel@tonic-gate */
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate static void
fcn_destroy(fcn_t * fcn_p)120*7c478bd9Sstevel@tonic-gate fcn_destroy(fcn_t * fcn_p)
121*7c478bd9Sstevel@tonic-gate {
122*7c478bd9Sstevel@tonic-gate if (!fcn_p)
123*7c478bd9Sstevel@tonic-gate return;
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate /* remove ourselves from any list */
126*7c478bd9Sstevel@tonic-gate if (!queue_isempty(&fcn_p->qn))
127*7c478bd9Sstevel@tonic-gate (void) queue_remove(&fcn_p->qn);
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate if (fcn_p->name_p)
130*7c478bd9Sstevel@tonic-gate free(fcn_p->name_p);
131*7c478bd9Sstevel@tonic-gate if (fcn_p->entry_name_p)
132*7c478bd9Sstevel@tonic-gate free(fcn_p->entry_name_p);
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gate free(fcn_p);
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate } /* end fcn_destroy */
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate /*
140*7c478bd9Sstevel@tonic-gate * fcn_list() - pretty prints the global fcnlist
141*7c478bd9Sstevel@tonic-gate */
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gate void
fcn_list(void)144*7c478bd9Sstevel@tonic-gate fcn_list(void)
145*7c478bd9Sstevel@tonic-gate {
146*7c478bd9Sstevel@tonic-gate fcn_t *fcn_p;
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate fcn_p = (fcn_t *) & g_fcnlist;
149*7c478bd9Sstevel@tonic-gate while ((fcn_p = (fcn_t *) queue_next(&g_fcnlist, &fcn_p->qn))) {
150*7c478bd9Sstevel@tonic-gate fcn_print(stdout, fcn_p);
151*7c478bd9Sstevel@tonic-gate }
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate } /* end fcn_list */
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gate /*
157*7c478bd9Sstevel@tonic-gate * fcn_print() - pretty prints a fcn
158*7c478bd9Sstevel@tonic-gate */
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate static void
fcn_print(FILE * stream,fcn_t * fcn_p)161*7c478bd9Sstevel@tonic-gate fcn_print(FILE * stream, fcn_t * fcn_p)
162*7c478bd9Sstevel@tonic-gate {
163*7c478bd9Sstevel@tonic-gate if (!fcn_p)
164*7c478bd9Sstevel@tonic-gate return;
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate (void) fprintf(stream, "&%-8s %-24s\n",
167*7c478bd9Sstevel@tonic-gate fcn_p->name_p, fcn_p->entry_name_p);
168*7c478bd9Sstevel@tonic-gate
169*7c478bd9Sstevel@tonic-gate } /* end fcn_print */
170*7c478bd9Sstevel@tonic-gate
171*7c478bd9Sstevel@tonic-gate
172*7c478bd9Sstevel@tonic-gate /*
173*7c478bd9Sstevel@tonic-gate * fcn_findname() - find the created name, given an entry name
174*7c478bd9Sstevel@tonic-gate */
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate char *
fcn_findname(const char * const entry_p)177*7c478bd9Sstevel@tonic-gate fcn_findname(const char * const entry_p)
178*7c478bd9Sstevel@tonic-gate {
179*7c478bd9Sstevel@tonic-gate fcn_t *fcn_p;
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gate if (!entry_p)
182*7c478bd9Sstevel@tonic-gate return (NULL);
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gate fcn_p = (fcn_t *) & g_fcnlist;
185*7c478bd9Sstevel@tonic-gate while ((fcn_p = (fcn_t *) queue_next(&g_fcnlist, &fcn_p->qn)))
186*7c478bd9Sstevel@tonic-gate if (strcmp(entry_p, fcn_p->entry_name_p) == 0)
187*7c478bd9Sstevel@tonic-gate return (fcn_p->name_p);
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate return (NULL);
190*7c478bd9Sstevel@tonic-gate
191*7c478bd9Sstevel@tonic-gate } /* end fcn_findname */
192*7c478bd9Sstevel@tonic-gate
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate * fcn_find() - finds a fcn by name
196*7c478bd9Sstevel@tonic-gate */
197*7c478bd9Sstevel@tonic-gate
198*7c478bd9Sstevel@tonic-gate fcn_t *
fcn_find(char * fcnname_p)199*7c478bd9Sstevel@tonic-gate fcn_find(char *fcnname_p)
200*7c478bd9Sstevel@tonic-gate {
201*7c478bd9Sstevel@tonic-gate fcn_t *fcn_p;
202*7c478bd9Sstevel@tonic-gate
203*7c478bd9Sstevel@tonic-gate if (!fcnname_p)
204*7c478bd9Sstevel@tonic-gate return (NULL);
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate fcn_p = (fcn_t *) & g_fcnlist;
207*7c478bd9Sstevel@tonic-gate while ((fcn_p = (fcn_t *) queue_next(&g_fcnlist, &fcn_p->qn)))
208*7c478bd9Sstevel@tonic-gate if (strcmp(fcnname_p, fcn_p->name_p) == 0)
209*7c478bd9Sstevel@tonic-gate return (fcn_p);
210*7c478bd9Sstevel@tonic-gate
211*7c478bd9Sstevel@tonic-gate return (NULL);
212*7c478bd9Sstevel@tonic-gate
213*7c478bd9Sstevel@tonic-gate } /* end set_find */
214