dt_ident.h revision 178479
1178479Sjb/* 2178479Sjb * CDDL HEADER START 3178479Sjb * 4178479Sjb * The contents of this file are subject to the terms of the 5178479Sjb * Common Development and Distribution License, Version 1.0 only 6178479Sjb * (the "License"). You may not use this file except in compliance 7178479Sjb * with the License. 8178479Sjb * 9178479Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10178479Sjb * or http://www.opensolaris.org/os/licensing. 11178479Sjb * See the License for the specific language governing permissions 12178479Sjb * and limitations under the License. 13178479Sjb * 14178479Sjb * When distributing Covered Code, include this CDDL HEADER in each 15178479Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16178479Sjb * If applicable, add the following below this CDDL HEADER, with the 17178479Sjb * fields enclosed by brackets "[]" replaced with your own identifying 18178479Sjb * information: Portions Copyright [yyyy] [name of copyright owner] 19178479Sjb * 20178479Sjb * CDDL HEADER END 21178479Sjb */ 22178479Sjb/* 23178479Sjb * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24178479Sjb * Use is subject to license terms. 25178479Sjb */ 26178479Sjb 27178479Sjb#ifndef _DT_IDENT_H 28178479Sjb#define _DT_IDENT_H 29178479Sjb 30178479Sjb#pragma ident "%Z%%M% %I% %E% SMI" 31178479Sjb 32178479Sjb#include <libctf.h> 33178479Sjb#include <dtrace.h> 34178479Sjb 35178479Sjb#ifdef __cplusplus 36178479Sjbextern "C" { 37178479Sjb#endif 38178479Sjb 39178479Sjb#include <dt_list.h> 40178479Sjb 41178479Sjbstruct dt_node; 42178479Sjbstruct dt_ident; 43178479Sjbstruct dt_idhash; 44178479Sjbstruct dt_irlist; 45178479Sjbstruct dt_regset; 46178479Sjb 47178479Sjbtypedef struct dt_idsig { 48178479Sjb int dis_varargs; /* argument index of start of varargs (or -1) */ 49178479Sjb int dis_optargs; /* argument index of start of optargs (or -1) */ 50178479Sjb int dis_argc; /* number of types in this signature */ 51178479Sjb struct dt_node *dis_args; /* array of nodes representing formal types */ 52178479Sjb uint64_t dis_auxinfo; /* auxiliary signature information, if any */ 53178479Sjb} dt_idsig_t; 54178479Sjb 55178479Sjbtypedef struct dt_idnode { 56178479Sjb struct dt_node *din_list; /* allocation list for parse tree nodes */ 57178479Sjb struct dt_node *din_root; /* root of this identifier's parse tree */ 58178479Sjb struct dt_idhash *din_hash; /* identifiers private to this subtree */ 59178479Sjb struct dt_ident **din_argv; /* identifiers in din_hash for arguments */ 60178479Sjb int din_argc; /* length of din_argv[] array */ 61178479Sjb} dt_idnode_t; 62178479Sjb 63178479Sjbtypedef struct dt_idops { 64178479Sjb void (*di_cook)(struct dt_node *, struct dt_ident *, 65178479Sjb int, struct dt_node *); 66178479Sjb void (*di_dtor)(struct dt_ident *); 67178479Sjb size_t (*di_size)(struct dt_ident *); 68178479Sjb} dt_idops_t; 69178479Sjb 70178479Sjbtypedef struct dt_ident { 71178479Sjb char *di_name; /* identifier name */ 72178479Sjb ushort_t di_kind; /* identifier kind (see below) */ 73178479Sjb ushort_t di_flags; /* identifier flags (see below) */ 74178479Sjb uint_t di_id; /* variable or subr id (see <sys/dtrace.h>) */ 75178479Sjb dtrace_attribute_t di_attr; /* identifier stability attributes */ 76178479Sjb uint_t di_vers; /* identifier version number (dt_version_t) */ 77178479Sjb const dt_idops_t *di_ops; /* identifier's class-specific ops vector */ 78178479Sjb void *di_iarg; /* initial argument pointer for ops vector */ 79178479Sjb void *di_data; /* private data pointer for ops vector */ 80178479Sjb ctf_file_t *di_ctfp; /* CTF container for the variable data type */ 81178479Sjb ctf_id_t di_type; /* CTF identifier for the variable data type */ 82178479Sjb struct dt_ident *di_next; /* pointer to next ident in hash chain */ 83178479Sjb ulong_t di_gen; /* generation number (pass that created me) */ 84178479Sjb int di_lineno; /* line number that defined this identifier */ 85178479Sjb} dt_ident_t; 86178479Sjb 87178479Sjb#define DT_IDENT_ARRAY 0 /* identifier is an array variable */ 88178479Sjb#define DT_IDENT_SCALAR 1 /* identifier is a scalar variable */ 89178479Sjb#define DT_IDENT_PTR 2 /* identifier is a magic pointer */ 90178479Sjb#define DT_IDENT_FUNC 3 /* identifier is a built-in function */ 91178479Sjb#define DT_IDENT_AGG 4 /* identifier is an aggregation */ 92178479Sjb#define DT_IDENT_AGGFUNC 5 /* identifier is an aggregating function */ 93178479Sjb#define DT_IDENT_ACTFUNC 6 /* identifier is an action function */ 94178479Sjb#define DT_IDENT_XLSOU 7 /* identifier is a translated struct or union */ 95178479Sjb#define DT_IDENT_XLPTR 8 /* identifier is a translated pointer */ 96178479Sjb#define DT_IDENT_SYMBOL 9 /* identifier is an external symbol */ 97178479Sjb#define DT_IDENT_ENUM 10 /* identifier is an enumerator */ 98178479Sjb#define DT_IDENT_PRAGAT 11 /* identifier is #pragma attributes */ 99178479Sjb#define DT_IDENT_PRAGBN 12 /* identifier is #pragma binding */ 100178479Sjb#define DT_IDENT_PROBE 13 /* identifier is a probe definition */ 101178479Sjb 102178479Sjb#define DT_IDFLG_TLS 0x0001 /* variable is thread-local storage */ 103178479Sjb#define DT_IDFLG_LOCAL 0x0002 /* variable is local storage */ 104178479Sjb#define DT_IDFLG_WRITE 0x0004 /* variable is writable (can be modified) */ 105178479Sjb#define DT_IDFLG_INLINE 0x0008 /* variable is an inline definition */ 106178479Sjb#define DT_IDFLG_REF 0x0010 /* variable is referenced by this program */ 107178479Sjb#define DT_IDFLG_MOD 0x0020 /* variable is modified by this program */ 108178479Sjb#define DT_IDFLG_DIFR 0x0040 /* variable is referenced by current DIFO */ 109178479Sjb#define DT_IDFLG_DIFW 0x0080 /* variable is modified by current DIFO */ 110178479Sjb#define DT_IDFLG_CGREG 0x0100 /* variable is inlined by code generator */ 111178479Sjb#define DT_IDFLG_USER 0x0200 /* variable is associated with userland */ 112178479Sjb#define DT_IDFLG_PRIM 0x0400 /* variable is associated with primary object */ 113178479Sjb#define DT_IDFLG_DECL 0x0800 /* variable is associated with explicit decl */ 114178479Sjb#define DT_IDFLG_ORPHAN 0x1000 /* variable is in a dt_node and not dt_idhash */ 115178479Sjb 116178479Sjbtypedef struct dt_idhash { 117178479Sjb dt_list_t dh_list; /* list prev/next pointers for dt_idstack */ 118178479Sjb const char *dh_name; /* name of this hash table */ 119178479Sjb void (*dh_defer)(struct dt_idhash *, dt_ident_t *); /* defer callback */ 120178479Sjb const dt_ident_t *dh_tmpl; /* template for initial ident population */ 121178479Sjb uint_t dh_nextid; /* next id to be returned by idhash_nextid() */ 122178479Sjb uint_t dh_minid; /* min id to be returned by idhash_nextid() */ 123178479Sjb uint_t dh_maxid; /* max id to be returned by idhash_nextid() */ 124178479Sjb ulong_t dh_nelems; /* number of identifiers in hash table */ 125178479Sjb ulong_t dh_hashsz; /* number of entries in dh_buckets array */ 126178479Sjb dt_ident_t *dh_hash[1]; /* array of hash table bucket pointers */ 127178479Sjb} dt_idhash_t; 128178479Sjb 129178479Sjbtypedef struct dt_idstack { 130178479Sjb dt_list_t dids_list; /* list meta-data for dt_idhash_t stack */ 131178479Sjb} dt_idstack_t; 132178479Sjb 133178479Sjbextern const dt_idops_t dt_idops_assc; /* associative array or aggregation */ 134178479Sjbextern const dt_idops_t dt_idops_func; /* function call built-in */ 135178479Sjbextern const dt_idops_t dt_idops_args; /* args[] built-in */ 136178479Sjbextern const dt_idops_t dt_idops_regs; /* regs[]/uregs[] built-in */ 137178479Sjbextern const dt_idops_t dt_idops_type; /* predefined type name string */ 138178479Sjbextern const dt_idops_t dt_idops_thaw; /* prefrozen type identifier */ 139178479Sjbextern const dt_idops_t dt_idops_inline; /* inline variable */ 140178479Sjbextern const dt_idops_t dt_idops_probe; /* probe definition */ 141178479Sjb 142178479Sjbextern dt_idhash_t *dt_idhash_create(const char *, const dt_ident_t *, 143178479Sjb uint_t, uint_t); 144178479Sjbextern void dt_idhash_destroy(dt_idhash_t *); 145178479Sjbextern void dt_idhash_update(dt_idhash_t *); 146178479Sjbextern dt_ident_t *dt_idhash_lookup(dt_idhash_t *, const char *); 147178479Sjbextern int dt_idhash_nextid(dt_idhash_t *, uint_t *); 148178479Sjbextern ulong_t dt_idhash_size(const dt_idhash_t *); 149178479Sjbextern const char *dt_idhash_name(const dt_idhash_t *); 150178479Sjb 151178479Sjbextern dt_ident_t *dt_idhash_insert(dt_idhash_t *, const char *, ushort_t, 152178479Sjb ushort_t, uint_t, dtrace_attribute_t, uint_t, 153178479Sjb const dt_idops_t *, void *, ulong_t); 154178479Sjb 155178479Sjbextern void dt_idhash_xinsert(dt_idhash_t *, dt_ident_t *); 156178479Sjbextern void dt_idhash_delete(dt_idhash_t *, dt_ident_t *); 157178479Sjb 158178479Sjbtypedef int dt_idhash_f(dt_idhash_t *, dt_ident_t *, void *); 159178479Sjbextern int dt_idhash_iter(dt_idhash_t *, dt_idhash_f *, void *); 160178479Sjb 161178479Sjbextern dt_ident_t *dt_idstack_lookup(dt_idstack_t *, const char *); 162178479Sjbextern void dt_idstack_push(dt_idstack_t *, dt_idhash_t *); 163178479Sjbextern void dt_idstack_pop(dt_idstack_t *, dt_idhash_t *); 164178479Sjb 165178479Sjbextern dt_ident_t *dt_ident_create(const char *, ushort_t, ushort_t, uint_t, 166178479Sjb dtrace_attribute_t, uint_t, const dt_idops_t *, void *, ulong_t); 167178479Sjbextern void dt_ident_destroy(dt_ident_t *); 168178479Sjbextern void dt_ident_morph(dt_ident_t *, ushort_t, const dt_idops_t *, void *); 169178479Sjbextern dtrace_attribute_t dt_ident_cook(struct dt_node *, 170178479Sjb dt_ident_t *, struct dt_node **); 171178479Sjb 172178479Sjbextern void dt_ident_type_assign(dt_ident_t *, ctf_file_t *, ctf_id_t); 173178479Sjbextern dt_ident_t *dt_ident_resolve(dt_ident_t *); 174178479Sjbextern size_t dt_ident_size(dt_ident_t *); 175178479Sjbextern int dt_ident_unref(const dt_ident_t *); 176178479Sjb 177178479Sjbextern const char *dt_idkind_name(uint_t); 178178479Sjb 179178479Sjb#ifdef __cplusplus 180178479Sjb} 181178479Sjb#endif 182178479Sjb 183178479Sjb#endif /* _DT_IDENT_H */ 184