xref: /illumos-gate/usr/src/lib/libdtrace/common/dt_ident.h (revision 08855964b9970604433f7b19dcd71cf5af5e5f14)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DT_IDENT_H
28 #define	_DT_IDENT_H
29 
30 #include <libctf.h>
31 #include <dtrace.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #include <dt_list.h>
38 
39 struct dt_node;
40 struct dt_ident;
41 struct dt_idhash;
42 struct dt_irlist;
43 struct dt_regset;
44 
45 typedef struct dt_idsig {
46 	int dis_varargs;	/* argument index of start of varargs (or -1) */
47 	int dis_optargs;	/* argument index of start of optargs (or -1) */
48 	int dis_argc;		/* number of types in this signature */
49 	struct dt_node *dis_args; /* array of nodes representing formal types */
50 	uint64_t dis_auxinfo;	/* auxiliary signature information, if any */
51 } dt_idsig_t;
52 
53 typedef struct dt_idnode {
54 	struct dt_node *din_list; /* allocation list for parse tree nodes */
55 	struct dt_node *din_root; /* root of this identifier's parse tree */
56 	struct dt_idhash *din_hash; /* identifiers private to this subtree */
57 	struct dt_ident **din_argv; /* identifiers in din_hash for arguments */
58 	int din_argc;		  /* length of din_argv[] array */
59 } dt_idnode_t;
60 
61 typedef struct dt_idops {
62 	void (*di_cook)(struct dt_node *, struct dt_ident *,
63 	    int, struct dt_node *);
64 	void (*di_dtor)(struct dt_ident *);
65 	size_t (*di_size)(struct dt_ident *);
66 } dt_idops_t;
67 
68 typedef struct dt_ident {
69 	char *di_name;		/* identifier name */
70 	ushort_t di_kind;	/* identifier kind (see below) */
71 	ushort_t di_flags;	/* identifier flags (see below) */
72 	uint_t di_id;		/* variable or subr id (see <sys/dtrace.h>) */
73 	dtrace_attribute_t di_attr; /* identifier stability attributes */
74 	uint_t di_vers;		/* identifier version number (dt_version_t) */
75 	const dt_idops_t *di_ops; /* identifier's class-specific ops vector */
76 	void *di_iarg;		/* initial argument pointer for ops vector */
77 	void *di_data;		/* private data pointer for ops vector */
78 	ctf_file_t *di_ctfp;	/* CTF container for the variable data type */
79 	ctf_id_t di_type;	/* CTF identifier for the variable data type */
80 	struct dt_ident *di_next; /* pointer to next ident in hash chain */
81 	ulong_t di_gen;		/* generation number (pass that created me) */
82 	int di_lineno;		/* line number that defined this identifier */
83 } dt_ident_t;
84 
85 #define	DT_IDENT_ARRAY	0	/* identifier is an array variable */
86 #define	DT_IDENT_SCALAR	1	/* identifier is a scalar variable */
87 #define	DT_IDENT_PTR	2	/* identifier is a magic pointer */
88 #define	DT_IDENT_FUNC	3	/* identifier is a built-in function */
89 #define	DT_IDENT_AGG	4	/* identifier is an aggregation */
90 #define	DT_IDENT_AGGFUNC 5	/* identifier is an aggregating function */
91 #define	DT_IDENT_ACTFUNC 6	/* identifier is an action function */
92 #define	DT_IDENT_XLSOU	7	/* identifier is a translated struct or union */
93 #define	DT_IDENT_XLPTR	8	/* identifier is a translated pointer */
94 #define	DT_IDENT_SYMBOL	9	/* identifier is an external symbol */
95 #define	DT_IDENT_ENUM	10	/* identifier is an enumerator */
96 #define	DT_IDENT_PRAGAT	11	/* identifier is #pragma attributes */
97 #define	DT_IDENT_PRAGBN	12	/* identifier is #pragma binding */
98 #define	DT_IDENT_PROBE	13	/* identifier is a probe definition */
99 
100 #define	DT_IDFLG_TLS	0x0001	/* variable is thread-local storage */
101 #define	DT_IDFLG_LOCAL	0x0002	/* variable is local storage */
102 #define	DT_IDFLG_WRITE	0x0004	/* variable is writable (can be modified) */
103 #define	DT_IDFLG_INLINE	0x0008	/* variable is an inline definition */
104 #define	DT_IDFLG_REF	0x0010	/* variable is referenced by this program */
105 #define	DT_IDFLG_MOD	0x0020	/* variable is modified by this program */
106 #define	DT_IDFLG_DIFR	0x0040	/* variable is referenced by current DIFO */
107 #define	DT_IDFLG_DIFW	0x0080	/* variable is modified by current DIFO */
108 #define	DT_IDFLG_CGREG	0x0100	/* variable is inlined by code generator */
109 #define	DT_IDFLG_USER	0x0200	/* variable is associated with userland */
110 #define	DT_IDFLG_PRIM	0x0400	/* variable is associated with primary object */
111 #define	DT_IDFLG_DECL	0x0800	/* variable is associated with explicit decl */
112 #define	DT_IDFLG_ORPHAN	0x1000	/* variable is in a dt_node and not dt_idhash */
113 
114 typedef struct dt_idhash {
115 	dt_list_t dh_list;	/* list prev/next pointers for dt_idstack */
116 	const char *dh_name;	/* name of this hash table */
117 	void (*dh_defer)(struct dt_idhash *, dt_ident_t *); /* defer callback */
118 	const dt_ident_t *dh_tmpl; /* template for initial ident population */
119 	uint_t dh_nextid;	/* next id to be returned by idhash_nextid() */
120 	uint_t dh_minid;	/* min id to be returned by idhash_nextid() */
121 	uint_t dh_maxid;	/* max id to be returned by idhash_nextid() */
122 	ulong_t dh_nelems;	/* number of identifiers in hash table */
123 	ulong_t dh_hashsz;	/* number of entries in dh_buckets array */
124 	dt_ident_t *dh_hash[1];	/* array of hash table bucket pointers */
125 } dt_idhash_t;
126 
127 typedef struct dt_idstack {
128 	dt_list_t dids_list;	/* list meta-data for dt_idhash_t stack */
129 } dt_idstack_t;
130 
131 extern const dt_idops_t dt_idops_assc;	/* associative array or aggregation */
132 extern const dt_idops_t dt_idops_func;	/* function call built-in */
133 extern const dt_idops_t dt_idops_args;	/* args[] built-in */
134 extern const dt_idops_t dt_idops_regs;	/* regs[]/uregs[] built-in */
135 extern const dt_idops_t dt_idops_type;	/* predefined type name string */
136 extern const dt_idops_t dt_idops_thaw;	/* prefrozen type identifier */
137 extern const dt_idops_t dt_idops_inline; /* inline variable */
138 extern const dt_idops_t dt_idops_probe;	/* probe definition */
139 
140 extern dt_idhash_t *dt_idhash_create(const char *, const dt_ident_t *,
141     uint_t, uint_t);
142 extern void dt_idhash_destroy(dt_idhash_t *);
143 extern void dt_idhash_update(dt_idhash_t *);
144 extern dt_ident_t *dt_idhash_lookup(dt_idhash_t *, const char *);
145 extern int dt_idhash_nextid(dt_idhash_t *, uint_t *);
146 extern ulong_t dt_idhash_size(const dt_idhash_t *);
147 extern const char *dt_idhash_name(const dt_idhash_t *);
148 
149 extern dt_ident_t *dt_idhash_insert(dt_idhash_t *, const char *, ushort_t,
150     ushort_t, uint_t, dtrace_attribute_t, uint_t,
151     const dt_idops_t *, void *, ulong_t);
152 
153 extern void dt_idhash_xinsert(dt_idhash_t *, dt_ident_t *);
154 extern void dt_idhash_delete(dt_idhash_t *, dt_ident_t *);
155 
156 typedef int dt_idhash_f(dt_idhash_t *, dt_ident_t *, void *);
157 extern int dt_idhash_iter(dt_idhash_t *, dt_idhash_f *, void *);
158 
159 extern dt_ident_t *dt_idstack_lookup(dt_idstack_t *, const char *);
160 extern void dt_idstack_push(dt_idstack_t *, dt_idhash_t *);
161 extern void dt_idstack_pop(dt_idstack_t *, dt_idhash_t *);
162 
163 extern dt_ident_t *dt_ident_create(const char *, ushort_t, ushort_t, uint_t,
164     dtrace_attribute_t, uint_t, const dt_idops_t *, void *, ulong_t);
165 extern void dt_ident_destroy(dt_ident_t *);
166 extern void dt_ident_morph(dt_ident_t *, ushort_t, const dt_idops_t *, void *);
167 extern dtrace_attribute_t dt_ident_cook(struct dt_node *,
168     dt_ident_t *, struct dt_node **);
169 
170 extern void dt_ident_type_assign(dt_ident_t *, ctf_file_t *, ctf_id_t);
171 extern dt_ident_t *dt_ident_resolve(dt_ident_t *);
172 extern size_t dt_ident_size(dt_ident_t *);
173 extern int dt_ident_unref(const dt_ident_t *);
174 
175 extern const char *dt_idkind_name(uint_t);
176 
177 #ifdef	__cplusplus
178 }
179 #endif
180 
181 #endif	/* _DT_IDENT_H */
182