dt_impl.h revision 6009dbc6db3fe0e2890761d3d562bb4c4b9bf0be
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _DT_IMPL_H
#define _DT_IMPL_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <setjmp.h>
#include <libctf.h>
#include <dtrace.h>
#include <gelf.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <dt_parser.h>
#include <dt_regset.h>
#include <dt_inttab.h>
#include <dt_strtab.h>
#include <dt_ident.h>
#include <dt_list.h>
#include <dt_decl.h>
#include <dt_as.h>
#include <dt_proc.h>
#include <dt_dof.h>
#include <dt_pcb.h>
struct dt_module; /* see below */
struct dt_pfdict; /* see <dt_printf.h> */
struct dt_arg; /* see below */
struct dt_provider; /* see <dt_provider.h> */
struct dt_xlator; /* see <dt_xlator.h> */
typedef struct dt_intrinsic {
const char *din_name; /* string name of the intrinsic type */
typedef struct dt_typedef {
const char *dty_src; /* string name of typedef source type */
const char *dty_dst; /* string name of typedef destination type */
} dt_typedef_t;
typedef struct dt_intdesc {
const char *did_name; /* string name of the integer type */
} dt_intdesc_t;
typedef struct dt_modops {
void (*do_symsort)(struct dt_module *);
} dt_modops_t;
typedef struct dt_arg {
int da_ndx; /* index of this argument */
int da_mapping; /* mapping of argument indices to arguments */
} dt_arg_t;
typedef struct dt_sym {
} dt_sym_t;
typedef struct dt_module {
void *dm_asmap; /* symbol pointers sorted by value */
int dm_modid; /* modinfo(1M) module identifier */
} dt_module_t;
typedef struct dt_provmod {
char *dp_name; /* name of provider module */
} dt_provmod_t;
typedef struct dt_ahashent {
typedef struct dt_ahash {
} dt_ahash_t;
typedef struct dt_aggregate {
int dtat_flags; /* aggregate flags */
typedef struct dt_print_aggdata {
int dtpa_allunprint; /* print only unprinted aggregations */
typedef struct dt_dirpath {
char *dir_path; /* directory pathname */
} dt_dirpath_t;
typedef struct dt_lib_depend {
char *dtld_library; /* library name */
char *dtld_libpath; /* library pathname */
struct dtrace_hdl {
void *dt_varg; /* vector argument, if vectored open */
const char *dt_errtag; /* tag used with last call to dt_set_errmsg() */
int dt_maxformat; /* max format ID */
void **dt_formats; /* pointer to format array */
char *dt_cpp_path; /* pathname of cpp(1) to invoke if needed */
char **dt_cpp_argv; /* argument vector for exec'ing cpp(1) */
int dt_cpp_argc; /* count of initialized cpp(1) arguments */
int dt_cpp_args; /* size of dt_cpp_argv[] array */
char *dt_ld_path; /* pathname of ld(1) to invoke if needed */
int dt_version; /* library version requested by client */
int dt_ctferr; /* error resulting from last CTF failure */
int dt_errno; /* error resulting from last failed operation */
int dt_fd; /* file descriptor for dtrace pseudo-device */
int dt_ftfd; /* file descriptor for fasttrap pseudo-device */
int dt_fterr; /* saved errno from failed open of dt_ftfd */
int dt_cdefs_fd; /* file descriptor for C CTF debugging cache */
int dt_ddefs_fd; /* file descriptor for D CTF debugging cache */
int dt_stdout_fd; /* file descriptor for saved stdout */
void *dt_errarg; /* error handler argument */
void *dt_droparg; /* drop handler argument */
void *dt_procarg; /* proc handler argument */
void *dt_setoptarg; /* setopt handler argument */
int dt_statusgen; /* current status generation */
char *dt_sprintf_buf; /* buffer for dtrace_sprintf() */
int dt_sprintf_buflen; /* length of dtrace_sprintf() buffer */
const char *dt_filetag; /* default filetag for dt_set_errmsg() */
char *dt_buffered_buf; /* buffer for buffered output */
void *dt_bufarg; /* buffered handler argument */
};
/*
* Values for the user arg of the ECB.
*/
#define DT_ECB_DEFAULT 0
#define DT_ECB_ERROR 1
/*
* Values for the dt_linkmode property, which is used by the assembler when
* processing external symbol references. User can set using -xlink=<mode>.
*/
#define DT_LINK_KERNEL 0 /* kernel syms static, user syms dynamic */
/*
* Values for the dt_linktype property, which is used by dtrace_program_link()
* to determine the type of output file that is desired by the client.
*/
#define DT_LTYP_ELF 0 /* produce ELF containing DOF */
/*
* Values for the dt_xlatemode property, which is used to determine whether
* references to dynamic translators are permitted. Set using -xlate=<mode>.
*/
#define DT_XL_STATIC 0 /* require xlators to be statically defined */
/*
* Values for the dt_stdcmode property, which is used by the compiler when
* running cpp to determine the presence and setting of the __STDC__ macro.
*/
#define DT_STDC_XA 0 /* ISO C + K&R C compat w/o ISO: __STDC__=0 */
/*
* Macro to test whether a given pass bit is set in the dt_treedump bit-vector.
* If the bit for pass 'p' is set, the D compiler displays the parse tree for
* the program by printing it to stderr at the end of compiler pass 'p'.
*/
/*
* Macros for accessing the cached CTF container and type ID for the common
* types "int", "string", and <DYN>, which we need to use frequently in the D
* compiler. The DT_INT_* macro relies upon "int" being at index 0 in the
* _dtrace_ints_* tables in dt_open.c; the others are also set up there.
*/
/*
* Actions and subroutines are both DT_NODE_FUNC nodes; to avoid confusing
* an action for a subroutine (or vice versa), we assure that the DT_ACT_*
* constants and the DIF_SUBR_* constants occupy non-overlapping ranges by
* starting the DT_ACT_* constants at DIF_SUBR_MAX + 1.
*/
#define DT_ACT(n) (DT_ACT_BASE + (n))
/*
* Sentinel to tell freopen() to restore the saved stdout. This must not
* be ever valid for opening for write access via freopen(3C), which of
* course, "." never is.
*/
#define DT_FREOPEN_RESTORE "."
enum {
EDT_VERSINVAL, /* version string is invalid or overflows */
EDT_VERSUNDEF, /* requested API version is not defined */
EDT_VERSREDUCED, /* requested API version has been reduced */
EDT_CTF, /* libctf called failed (dt_ctferr has more) */
EDT_COMPILER, /* error in D program compilation */
EDT_NOREG, /* register allocation failure */
EDT_NOTUPREG, /* tuple register allocation failure */
EDT_NOMEM, /* memory allocation failure */
EDT_INT2BIG, /* integer limit exceeded */
EDT_STR2BIG, /* string limit exceeded */
EDT_NOMOD, /* unknown module name */
EDT_NOPROV, /* unknown provider name */
EDT_NOPROBE, /* unknown probe name */
EDT_NOSYM, /* unknown symbol name */
EDT_NOSYMADDR, /* no symbol corresponds to address */
EDT_NOTYPE, /* unknown type name */
EDT_NOVAR, /* unknown variable name */
EDT_NOAGG, /* unknown aggregation name */
EDT_BADSCOPE, /* improper use of type name scoping operator */
EDT_BADSPEC, /* overspecified probe description */
EDT_BADSPCV, /* bad macro variable in probe description */
EDT_BADID, /* invalid probe identifier */
EDT_NOTLOADED, /* module is not currently loaded */
EDT_NOCTF, /* module does not contain any CTF data */
EDT_DATAMODEL, /* module and program data models don't match */
EDT_DIFVERS, /* library has newer DIF version than driver */
EDT_BADAGG, /* unrecognized aggregating action */
EDT_FIO, /* file i/o error */
EDT_DIFINVAL, /* invalid DIF program */
EDT_DIFSIZE, /* invalid DIF size */
EDT_DIFFAULT, /* failed to copyin DIF program */
EDT_BADPROBE, /* bad probe description */
EDT_BADPGLOB, /* bad probe description globbing pattern */
EDT_NOSCOPE, /* declaration scope stack underflow */
EDT_NODECL, /* declaration stack underflow */
EDT_DMISMATCH, /* record list does not match statement */
EDT_DOFFSET, /* record data offset error */
EDT_DALIGN, /* record data alignment error */
EDT_BADOPTNAME, /* invalid dtrace_setopt option name */
EDT_BADOPTVAL, /* invalid dtrace_setopt option value */
EDT_BADOPTCTX, /* invalid dtrace_setopt option context */
EDT_CPPFORK, /* failed to fork preprocessor */
EDT_CPPEXEC, /* failed to exec preprocessor */
EDT_CPPENT, /* preprocessor not found */
EDT_CPPERR, /* unknown preprocessor error */
EDT_SYMOFLOW, /* external symbol table overflow */
EDT_ACTIVE, /* operation illegal when tracing is active */
EDT_DESTRUCTIVE, /* destructive actions not allowed */
EDT_NOANON, /* no anonymous tracing state */
EDT_ISANON, /* can't claim anon state and enable probes */
EDT_ENDTOOBIG, /* END enablings exceed size of prncpl buffer */
EDT_NOCONV, /* failed to load type for printf conversion */
EDT_BADCONV, /* incomplete printf conversion */
EDT_BADERROR, /* invalid library ERROR action */
EDT_ERRABORT, /* abort due to error */
EDT_DROPABORT, /* abort due to drop */
EDT_DIRABORT, /* abort explicitly directed */
EDT_BADRVAL, /* invalid return value from callback */
EDT_BADNORMAL, /* invalid normalization */
EDT_BUFTOOSMALL, /* enabling exceeds size of buffer */
EDT_BADTRUNC, /* invalid truncation */
EDT_BUSY, /* device busy (active kernel debugger) */
EDT_ACCESS, /* insufficient privileges to use DTrace */
EDT_NOENT, /* dtrace device not available */
EDT_BRICKED, /* abort due to systemic unresponsiveness */
EDT_HARDWIRE, /* failed to load hard-wired definitions */
EDT_ELFVERSION, /* libelf is out-of-date w.r.t libdtrace */
EDT_NOBUFFERED, /* attempt to buffer output without handler */
EDT_UNSTABLE, /* description matched unstable set of probes */
EDT_BADSETOPT, /* invalid setopt library action */
EDT_BADSTACKPC, /* invalid stack program counter size */
EDT_BADAGGVAR, /* invalid aggregation variable identifier */
EDT_OVERSION /* client is requesting deprecated version */
};
/*
* Interfaces for parsing and comparing DTrace attribute tuples, which describe
* stability and architectural binding information. The dtrace_attribute_t
*/
/*
* Interfaces for parsing and handling DTrace version strings. Version binding
* is a feature of the D compiler that is handled completely independently of
* the DTrace kernel infrastructure, so the definitions are here in libdtrace.
* Version strings are compiled into an encoded uint32_t which can be compared
* using C comparison operators. Version definitions are found in dt_open.c.
*/
#define DT_VERSION_NUMBER(M, m, u) \
((((M) & 0xFF) << 24) | (((m) & 0xFFF) << 12) | ((u) & 0xFFF))
#define DT_VERSION_MICRO(v) ((v) & 0x00000FFF)
extern int dt_version_str2num(const char *, dt_version_t *);
extern int dt_version_defined(dt_version_t);
/*
* Miscellaneous internal libdtrace interfaces. The definitions below are for
* libdtrace routines that do not yet merit their own separate header file.
*/
extern char *dt_cpp_add_arg(dtrace_hdl_t *, const char *);
extern char *dt_cpp_pop_arg(dtrace_hdl_t *);
extern int dt_set_errno(dtrace_hdl_t *, int);
extern void dt_set_errmsg(dtrace_hdl_t *, const char *, const char *,
const char *, int, const char *, va_list);
extern int dt_ioctl(dtrace_hdl_t *, int, void *);
extern long dt_sysconf(dtrace_hdl_t *, int);
extern void dt_free(dtrace_hdl_t *, void *);
extern int dt_gmatch(const char *, const char *);
extern char *dt_basename(char *);
extern int dt_buffered_enable(dtrace_hdl_t *);
extern void dt_buffered_disable(dtrace_hdl_t *);
extern void dt_buffered_destroy(dtrace_hdl_t *);
extern int dt_rw_read_held(pthread_rwlock_t *);
extern int dt_rw_write_held(pthread_rwlock_t *);
extern int dt_mutex_held(pthread_mutex_t *);
#define DT_RW_READ_HELD(x) dt_rw_read_held(x)
#define DT_RW_WRITE_HELD(x) dt_rw_write_held(x)
#define DT_MUTEX_HELD(x) dt_mutex_held(x)
extern int dt_options_load(dtrace_hdl_t *);
extern void dt_dprintf(const char *, ...);
extern void dt_endcontext(dtrace_hdl_t *);
extern int dt_aggregate_go(dtrace_hdl_t *);
extern int dt_aggregate_init(dtrace_hdl_t *);
extern void dt_aggregate_destroy(dtrace_hdl_t *);
dtrace_eprobedesc_t **, dtrace_probedesc_t **);
extern void dt_epid_destroy(dtrace_hdl_t *);
extern void dt_aggid_destroy(dtrace_hdl_t *);
extern void *dt_format_lookup(dtrace_hdl_t *, int);
extern void dt_format_destroy(dtrace_hdl_t *);
extern int dt_print_agg(const dtrace_aggdata_t *, void *);
extern int dt_handle_liberr(dtrace_hdl_t *,
const dtrace_probedata_t *, const char *);
extern int dt_handle_status(dtrace_hdl_t *,
dtrace_status_t *, dtrace_status_t *);
extern char yyintprefix; /* int token prefix for macros (+/-) */
extern int yyintdecimal; /* int token is decimal (1) or octal/hex (0) */
extern char yytext[]; /* lex input buffer */
extern int yylineno; /* lex line number */
extern int yydebug; /* lex debugging */
extern const char *const _dtrace_version; /* current version string */
extern int _dtrace_strbuckets; /* number of hash buckets for strings */
extern int _dtrace_intbuckets; /* number of hash buckets for ints */
extern int _dtrace_debug; /* debugging messages enabled */
extern int _dtrace_argmax; /* default maximum probe arguments */
extern const char *_dtrace_libdir; /* default library directory */
extern const char *_dtrace_moddir; /* default kernel module directory */
#ifdef __cplusplus
}
#endif
#endif /* _DT_IMPL_H */