10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25 /*
26 * Copyright (c) 2013 by Delphix. All rights reserved.
27 * Copyright (c) 2013 Joyent, Inc. All rights reserved.
28 */
29
30 #ifndef _DT_PARSER_H
31 #define _DT_PARSER_H
32
33 #include <sys/types.h>
34 #include <sys/dtrace.h>
35
36 #include <libctf.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #include <dt_errtags.h>
45 #include <dt_ident.h>
46 #include <dt_decl.h>
47 #include <dt_xlator.h>
48 #include <dt_list.h>
49
88
89 struct {
90 char *_name; /* string name of member */
91 struct dt_node *_expr; /* expression node pointer */
92 dt_xlator_t *_xlator; /* translator reference */
93 uint_t _id; /* member identifier */
94 } _member;
95
96 struct {
97 dt_xlator_t *_xlator; /* translator reference */
98 struct dt_node *_xmemb; /* individual xlator member */
99 struct dt_node *_membs; /* list of member nodes */
100 } _xlator;
101
102 struct {
103 char *_name; /* string name of provider */
104 struct dt_provider *_pvp; /* provider references */
105 struct dt_node *_probes; /* list of probe nodes */
106 int _redecl; /* provider redeclared */
107 } _provider;
108 } dn_u;
109
110 struct dt_node *dn_list; /* parse tree list link */
111 struct dt_node *dn_link; /* allocation list link */
112 } dt_node_t;
113
114 #define dn_value dn_u._const._value /* DT_NODE_INT */
115 #define dn_string dn_u._const._string /* STRING, IDENT, TYPE */
116 #define dn_ident dn_u._nodes._ident /* VAR,SYM,FUN,AGG,INL,PROBE */
117 #define dn_args dn_u._nodes._links[0] /* DT_NODE_VAR, FUNC */
118 #define dn_child dn_u._nodes._links[0] /* DT_NODE_OP1 */
119 #define dn_left dn_u._nodes._links[0] /* DT_NODE_OP2, OP3 */
120 #define dn_right dn_u._nodes._links[1] /* DT_NODE_OP2, OP3 */
121 #define dn_expr dn_u._nodes._links[2] /* DT_NODE_OP3, DEXPR */
122 #define dn_aggfun dn_u._nodes._links[0] /* DT_NODE_AGG */
123 #define dn_aggtup dn_u._nodes._links[1] /* DT_NODE_AGG */
124 #define dn_pdescs dn_u._clause._descs /* DT_NODE_CLAUSE */
125 #define dn_pred dn_u._clause._pred /* DT_NODE_CLAUSE */
126 #define dn_acts dn_u._clause._acts /* DT_NODE_CLAUSE */
127 #define dn_locals dn_u._clause._locals /* DT_NODE_CLAUSE */
128 #define dn_ctxattr dn_u._clause._attr /* DT_NODE_CLAUSE */
129 #define dn_spec dn_u._pdesc._spec /* DT_NODE_PDESC */
130 #define dn_desc dn_u._pdesc._desc /* DT_NODE_PDESC */
131 #define dn_membname dn_u._member._name /* DT_NODE_MEMBER */
132 #define dn_membexpr dn_u._member._expr /* DT_NODE_MEMBER */
133 #define dn_membxlator dn_u._member._xlator /* DT_NODE_MEMBER */
134 #define dn_membid dn_u._member._id /* DT_NODE_MEMBER */
135 #define dn_xlator dn_u._xlator._xlator /* DT_NODE_XLATOR */
136 #define dn_xmember dn_u._xlator._xmemb /* DT_NODE_XLATOR */
137 #define dn_members dn_u._xlator._membs /* DT_NODE_XLATOR */
138 #define dn_provname dn_u._provider._name /* DT_NODE_PROVIDER */
139 #define dn_provider dn_u._provider._pvp /* DT_NODE_PROVIDER */
140 #define dn_provred dn_u._provider._redecl /* DT_NODE_PROVIDER */
141 #define dn_probes dn_u._provider._probes /* DT_NODE_PROVIDER */
142
143 #define DT_NODE_FREE 0 /* unused node (waiting to be freed) */
144 #define DT_NODE_INT 1 /* integer value */
145 #define DT_NODE_STRING 2 /* string value */
146 #define DT_NODE_IDENT 3 /* identifier */
147 #define DT_NODE_VAR 4 /* variable reference */
148 #define DT_NODE_SYM 5 /* symbol reference */
149 #define DT_NODE_TYPE 6 /* type reference or formal parameter */
150 #define DT_NODE_FUNC 7 /* function call */
151 #define DT_NODE_OP1 8 /* unary operator */
152 #define DT_NODE_OP2 9 /* binary operator */
153 #define DT_NODE_OP3 10 /* ternary operator */
154 #define DT_NODE_DEXPR 11 /* D expression action */
155 #define DT_NODE_DFUNC 12 /* D function action */
156 #define DT_NODE_AGG 13 /* aggregation */
157 #define DT_NODE_PDESC 14 /* probe description */
158 #define DT_NODE_CLAUSE 15 /* clause definition */
159 #define DT_NODE_INLINE 16 /* inline definition */
160 #define DT_NODE_MEMBER 17 /* member definition */
161 #define DT_NODE_XLATOR 18 /* translator definition */
162 #define DT_NODE_PROBE 19 /* probe definition */
163 #define DT_NODE_PROVIDER 20 /* provider definition */
164 #define DT_NODE_PROG 21 /* program translation unit */
165
166 #define DT_NF_SIGNED 0x01 /* data is a signed quantity (else unsigned) */
167 #define DT_NF_COOKED 0x02 /* data is a known type (else still cooking) */
168 #define DT_NF_REF 0x04 /* pass by reference (array, struct, union) */
169 #define DT_NF_LVALUE 0x08 /* node is an l-value according to ANSI-C */
170 #define DT_NF_WRITABLE 0x10 /* node is writable (can be modified) */
171 #define DT_NF_BITFIELD 0x20 /* node is an integer bitfield */
172 #define DT_NF_USERLAND 0x40 /* data is a userland address */
173
174 #define DT_TYPE_NAMELEN 128 /* reasonable size for ctf_type_name() */
175
176 extern int dt_node_is_integer(const dt_node_t *);
177 extern int dt_node_is_float(const dt_node_t *);
178 extern int dt_node_is_scalar(const dt_node_t *);
179 extern int dt_node_is_arith(const dt_node_t *);
180 extern int dt_node_is_vfptr(const dt_node_t *);
181 extern int dt_node_is_dynamic(const dt_node_t *);
182 extern int dt_node_is_stack(const dt_node_t *);
183 extern int dt_node_is_symaddr(const dt_node_t *);
184 extern int dt_node_is_usymaddr(const dt_node_t *);
196 extern dt_node_t *dt_node_string(char *);
197 extern dt_node_t *dt_node_ident(char *);
198 extern dt_node_t *dt_node_type(dt_decl_t *);
199 extern dt_node_t *dt_node_vatype(void);
200 extern dt_node_t *dt_node_decl(void);
201 extern dt_node_t *dt_node_func(dt_node_t *, dt_node_t *);
202 extern dt_node_t *dt_node_offsetof(dt_decl_t *, char *);
203 extern dt_node_t *dt_node_op1(int, dt_node_t *);
204 extern dt_node_t *dt_node_op2(int, dt_node_t *, dt_node_t *);
205 extern dt_node_t *dt_node_op3(dt_node_t *, dt_node_t *, dt_node_t *);
206 extern dt_node_t *dt_node_statement(dt_node_t *);
207 extern dt_node_t *dt_node_pdesc_by_name(char *);
208 extern dt_node_t *dt_node_pdesc_by_id(uintmax_t);
209 extern dt_node_t *dt_node_clause(dt_node_t *, dt_node_t *, dt_node_t *);
210 extern dt_node_t *dt_node_inline(dt_node_t *);
211 extern dt_node_t *dt_node_member(dt_decl_t *, char *, dt_node_t *);
212 extern dt_node_t *dt_node_xlator(dt_decl_t *, dt_decl_t *, char *, dt_node_t *);
213 extern dt_node_t *dt_node_probe(char *, int, dt_node_t *, dt_node_t *);
214 extern dt_node_t *dt_node_provider(char *, dt_node_t *);
215 extern dt_node_t *dt_node_program(dt_node_t *);
216
217 extern dt_node_t *dt_node_link(dt_node_t *, dt_node_t *);
218 extern dt_node_t *dt_node_cook(dt_node_t *, uint_t);
219
220 extern dt_node_t *dt_node_xalloc(dtrace_hdl_t *, int);
221 extern void dt_node_free(dt_node_t *);
222
223 extern dtrace_attribute_t dt_node_list_cook(dt_node_t **, uint_t);
224 extern void dt_node_list_free(dt_node_t **);
225 extern void dt_node_link_free(dt_node_t **);
226
227 extern void dt_node_attr_assign(dt_node_t *, dtrace_attribute_t);
228 extern void dt_node_type_assign(dt_node_t *, ctf_file_t *, ctf_id_t, boolean_t);
229 extern void dt_node_type_propagate(const dt_node_t *, dt_node_t *);
230 extern const char *dt_node_type_name(const dt_node_t *, char *, size_t);
231 extern size_t dt_node_type_size(const dt_node_t *);
232
233 extern dt_ident_t *dt_node_resolve(const dt_node_t *, uint_t);
234 extern size_t dt_node_sizeof(const dt_node_t *);
235 extern void dt_node_promote(dt_node_t *, dt_node_t *, dt_node_t *);
236
237 extern void dt_node_diftype(dtrace_hdl_t *,
238 const dt_node_t *, dtrace_diftype_t *);
239 extern void dt_node_printr(dt_node_t *, FILE *, int);
240 extern const char *dt_node_name(const dt_node_t *, char *, size_t);
241 extern int dt_node_root(dt_node_t *);
242
243 struct dtrace_typeinfo; /* see <dtrace.h> */
244 struct dt_pcb; /* see <dt_impl.h> */
245
246 #define IS_CHAR(e) \
247 (((e).cte_format & (CTF_INT_CHAR | CTF_INT_SIGNED)) == \
248 (CTF_INT_CHAR | CTF_INT_SIGNED) && (e).cte_bits == NBBY)
249
250 #define IS_VOID(e) \
251 ((e).cte_offset == 0 && (e).cte_bits == 0)
252
253 extern int dt_type_lookup(const char *, struct dtrace_typeinfo *);
254 extern int dt_type_pointer(struct dtrace_typeinfo *);
255 extern const char *dt_type_name(ctf_file_t *, ctf_id_t, char *, size_t);
256
257 typedef enum {
258 YYS_CLAUSE, /* lex/yacc state for finding program clauses */
259 YYS_DEFINE, /* lex/yacc state for parsing persistent definitions */
|
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25 /*
26 * Copyright (c) 2013 by Delphix. All rights reserved.
27 * Copyright (c) 2013 Joyent, Inc. All rights reserved.
28 */
29
30 /*
31 * Copyright (c) 2014 by Delphix. All rights reserved.
32 */
33
34 #ifndef _DT_PARSER_H
35 #define _DT_PARSER_H
36
37 #include <sys/types.h>
38 #include <sys/dtrace.h>
39
40 #include <libctf.h>
41 #include <stdarg.h>
42 #include <stdio.h>
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #include <dt_errtags.h>
49 #include <dt_ident.h>
50 #include <dt_decl.h>
51 #include <dt_xlator.h>
52 #include <dt_list.h>
53
92
93 struct {
94 char *_name; /* string name of member */
95 struct dt_node *_expr; /* expression node pointer */
96 dt_xlator_t *_xlator; /* translator reference */
97 uint_t _id; /* member identifier */
98 } _member;
99
100 struct {
101 dt_xlator_t *_xlator; /* translator reference */
102 struct dt_node *_xmemb; /* individual xlator member */
103 struct dt_node *_membs; /* list of member nodes */
104 } _xlator;
105
106 struct {
107 char *_name; /* string name of provider */
108 struct dt_provider *_pvp; /* provider references */
109 struct dt_node *_probes; /* list of probe nodes */
110 int _redecl; /* provider redeclared */
111 } _provider;
112
113 struct {
114 struct dt_node *_conditional;
115 struct dt_node *_body;
116 struct dt_node *_alternate_body;
117 } _conditional;
118 } dn_u;
119
120 struct dt_node *dn_list; /* parse tree list link */
121 struct dt_node *dn_link; /* allocation list link */
122 } dt_node_t;
123
124 #define dn_value dn_u._const._value /* DT_NODE_INT */
125 #define dn_string dn_u._const._string /* STRING, IDENT, TYPE */
126 #define dn_ident dn_u._nodes._ident /* VAR,SYM,FUN,AGG,INL,PROBE */
127 #define dn_args dn_u._nodes._links[0] /* DT_NODE_VAR, FUNC */
128 #define dn_child dn_u._nodes._links[0] /* DT_NODE_OP1 */
129 #define dn_left dn_u._nodes._links[0] /* DT_NODE_OP2, OP3 */
130 #define dn_right dn_u._nodes._links[1] /* DT_NODE_OP2, OP3 */
131 #define dn_expr dn_u._nodes._links[2] /* DT_NODE_OP3, DEXPR */
132 #define dn_aggfun dn_u._nodes._links[0] /* DT_NODE_AGG */
133 #define dn_aggtup dn_u._nodes._links[1] /* DT_NODE_AGG */
134 #define dn_pdescs dn_u._clause._descs /* DT_NODE_CLAUSE */
135 #define dn_pred dn_u._clause._pred /* DT_NODE_CLAUSE */
136 #define dn_acts dn_u._clause._acts /* DT_NODE_CLAUSE */
137 #define dn_locals dn_u._clause._locals /* DT_NODE_CLAUSE */
138 #define dn_ctxattr dn_u._clause._attr /* DT_NODE_CLAUSE */
139 #define dn_spec dn_u._pdesc._spec /* DT_NODE_PDESC */
140 #define dn_desc dn_u._pdesc._desc /* DT_NODE_PDESC */
141 #define dn_membname dn_u._member._name /* DT_NODE_MEMBER */
142 #define dn_membexpr dn_u._member._expr /* DT_NODE_MEMBER */
143 #define dn_membxlator dn_u._member._xlator /* DT_NODE_MEMBER */
144 #define dn_membid dn_u._member._id /* DT_NODE_MEMBER */
145 #define dn_xlator dn_u._xlator._xlator /* DT_NODE_XLATOR */
146 #define dn_xmember dn_u._xlator._xmemb /* DT_NODE_XLATOR */
147 #define dn_members dn_u._xlator._membs /* DT_NODE_XLATOR */
148 #define dn_provname dn_u._provider._name /* DT_NODE_PROVIDER */
149 #define dn_provider dn_u._provider._pvp /* DT_NODE_PROVIDER */
150 #define dn_provred dn_u._provider._redecl /* DT_NODE_PROVIDER */
151 #define dn_probes dn_u._provider._probes /* DT_NODE_PROVIDER */
152
153 /* DT_NODE_IF: */
154 #define dn_conditional dn_u._conditional._conditional
155 #define dn_body dn_u._conditional._body
156 #define dn_alternate_body dn_u._conditional._alternate_body
157
158 #define DT_NODE_FREE 0 /* unused node (waiting to be freed) */
159 #define DT_NODE_INT 1 /* integer value */
160 #define DT_NODE_STRING 2 /* string value */
161 #define DT_NODE_IDENT 3 /* identifier */
162 #define DT_NODE_VAR 4 /* variable reference */
163 #define DT_NODE_SYM 5 /* symbol reference */
164 #define DT_NODE_TYPE 6 /* type reference or formal parameter */
165 #define DT_NODE_FUNC 7 /* function call */
166 #define DT_NODE_OP1 8 /* unary operator */
167 #define DT_NODE_OP2 9 /* binary operator */
168 #define DT_NODE_OP3 10 /* ternary operator */
169 #define DT_NODE_DEXPR 11 /* D expression action */
170 #define DT_NODE_DFUNC 12 /* D function action */
171 #define DT_NODE_AGG 13 /* aggregation */
172 #define DT_NODE_PDESC 14 /* probe description */
173 #define DT_NODE_CLAUSE 15 /* clause definition */
174 #define DT_NODE_INLINE 16 /* inline definition */
175 #define DT_NODE_MEMBER 17 /* member definition */
176 #define DT_NODE_XLATOR 18 /* translator definition */
177 #define DT_NODE_PROBE 19 /* probe definition */
178 #define DT_NODE_PROVIDER 20 /* provider definition */
179 #define DT_NODE_PROG 21 /* program translation unit */
180 #define DT_NODE_IF 22 /* if statement */
181
182 #define DT_NF_SIGNED 0x01 /* data is a signed quantity (else unsigned) */
183 #define DT_NF_COOKED 0x02 /* data is a known type (else still cooking) */
184 #define DT_NF_REF 0x04 /* pass by reference (array, struct, union) */
185 #define DT_NF_LVALUE 0x08 /* node is an l-value according to ANSI-C */
186 #define DT_NF_WRITABLE 0x10 /* node is writable (can be modified) */
187 #define DT_NF_BITFIELD 0x20 /* node is an integer bitfield */
188 #define DT_NF_USERLAND 0x40 /* data is a userland address */
189
190 #define DT_TYPE_NAMELEN 128 /* reasonable size for ctf_type_name() */
191
192 extern int dt_node_is_integer(const dt_node_t *);
193 extern int dt_node_is_float(const dt_node_t *);
194 extern int dt_node_is_scalar(const dt_node_t *);
195 extern int dt_node_is_arith(const dt_node_t *);
196 extern int dt_node_is_vfptr(const dt_node_t *);
197 extern int dt_node_is_dynamic(const dt_node_t *);
198 extern int dt_node_is_stack(const dt_node_t *);
199 extern int dt_node_is_symaddr(const dt_node_t *);
200 extern int dt_node_is_usymaddr(const dt_node_t *);
212 extern dt_node_t *dt_node_string(char *);
213 extern dt_node_t *dt_node_ident(char *);
214 extern dt_node_t *dt_node_type(dt_decl_t *);
215 extern dt_node_t *dt_node_vatype(void);
216 extern dt_node_t *dt_node_decl(void);
217 extern dt_node_t *dt_node_func(dt_node_t *, dt_node_t *);
218 extern dt_node_t *dt_node_offsetof(dt_decl_t *, char *);
219 extern dt_node_t *dt_node_op1(int, dt_node_t *);
220 extern dt_node_t *dt_node_op2(int, dt_node_t *, dt_node_t *);
221 extern dt_node_t *dt_node_op3(dt_node_t *, dt_node_t *, dt_node_t *);
222 extern dt_node_t *dt_node_statement(dt_node_t *);
223 extern dt_node_t *dt_node_pdesc_by_name(char *);
224 extern dt_node_t *dt_node_pdesc_by_id(uintmax_t);
225 extern dt_node_t *dt_node_clause(dt_node_t *, dt_node_t *, dt_node_t *);
226 extern dt_node_t *dt_node_inline(dt_node_t *);
227 extern dt_node_t *dt_node_member(dt_decl_t *, char *, dt_node_t *);
228 extern dt_node_t *dt_node_xlator(dt_decl_t *, dt_decl_t *, char *, dt_node_t *);
229 extern dt_node_t *dt_node_probe(char *, int, dt_node_t *, dt_node_t *);
230 extern dt_node_t *dt_node_provider(char *, dt_node_t *);
231 extern dt_node_t *dt_node_program(dt_node_t *);
232 extern dt_node_t *dt_node_if(dt_node_t *, dt_node_t *, dt_node_t *);
233
234 extern dt_node_t *dt_node_link(dt_node_t *, dt_node_t *);
235 extern dt_node_t *dt_node_cook(dt_node_t *, uint_t);
236
237 extern dt_node_t *dt_node_xalloc(dtrace_hdl_t *, int);
238 extern void dt_node_free(dt_node_t *);
239
240 extern dtrace_attribute_t dt_node_list_cook(dt_node_t **, uint_t);
241 extern void dt_node_list_free(dt_node_t **);
242 extern void dt_node_link_free(dt_node_t **);
243
244 extern void dt_node_attr_assign(dt_node_t *, dtrace_attribute_t);
245 extern void dt_node_type_assign(dt_node_t *, ctf_file_t *, ctf_id_t, boolean_t);
246 extern void dt_node_type_propagate(const dt_node_t *, dt_node_t *);
247 extern const char *dt_node_type_name(const dt_node_t *, char *, size_t);
248 extern size_t dt_node_type_size(const dt_node_t *);
249
250 extern dt_ident_t *dt_node_resolve(const dt_node_t *, uint_t);
251 extern size_t dt_node_sizeof(const dt_node_t *);
252 extern void dt_node_promote(dt_node_t *, dt_node_t *, dt_node_t *);
253
254 extern void dt_node_diftype(dtrace_hdl_t *,
255 const dt_node_t *, dtrace_diftype_t *);
256 extern void dt_node_printr(dt_node_t *, FILE *, int);
257 extern void dt_printd(dt_node_t *, FILE *, int);
258 extern const char *dt_node_name(const dt_node_t *, char *, size_t);
259 extern int dt_node_root(dt_node_t *);
260
261 struct dtrace_typeinfo; /* see <dtrace.h> */
262 struct dt_pcb; /* see <dt_impl.h> */
263
264 #define IS_CHAR(e) \
265 (((e).cte_format & (CTF_INT_CHAR | CTF_INT_SIGNED)) == \
266 (CTF_INT_CHAR | CTF_INT_SIGNED) && (e).cte_bits == NBBY)
267
268 #define IS_VOID(e) \
269 ((e).cte_offset == 0 && (e).cte_bits == 0)
270
271 extern int dt_type_lookup(const char *, struct dtrace_typeinfo *);
272 extern int dt_type_pointer(struct dtrace_typeinfo *);
273 extern const char *dt_type_name(ctf_file_t *, ctf_id_t, char *, size_t);
274
275 typedef enum {
276 YYS_CLAUSE, /* lex/yacc state for finding program clauses */
277 YYS_DEFINE, /* lex/yacc state for parsing persistent definitions */
|