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/* 28 * This header file defines the interfaces available from the CTF debugger 29 * library, libctf, and an equivalent kernel module. This API can be used by 30 * a debugger to operate on data in the Compact ANSI-C Type Format (CTF). 31 * This is NOT a public interface, although it may eventually become one in 32 * the fullness of time after we gain more experience with the interfaces. 33 * 34 * In the meantime, be aware that any program linked with this API in this 35 * release of Solaris is almost guaranteed to break in the next release. 36 * 37 * In short, do not user this header file or the CTF routines for any purpose. 38 */ 39 40#ifndef _CTF_API_H 41#define _CTF_API_H 42 43#pragma ident "@(#)ctf_api.h 1.4 05/06/08 SMI" 44 45#include <sys/types.h> 46#include <sys/param.h> 47 48#if defined(__LP64__) 49#if !defined(_LP64) 50#define _LP64 /* Solaris vs. Darwin */ 51#endif 52#else 53#if !defined(_ILP32) 54#define _ILP32 /* Solaris vs. Darwin */ 55#endif 56#endif 57 58#ifdef KERNEL 59#ifndef _KERNEL 60#define _KERNEL /* Solaris vs. Darwin */ 61#endif 62#endif 63 64#if defined(__BIG_ENDIAN__) 65#if !defined(_BIG_ENDIAN) 66#define _BIG_ENDIAN /* Solaris vs. Darwin */ 67#endif 68#elif defined(__LITTLE_ENDIAN__) 69#if !defined(_LITTLE_ENDIAN) 70#define _LITTLE_ENDIAN /* Solaris vs. Darwin */ 71#endif 72#else 73#error Unknown endian-ness 74#endif 75 76#include "elf.h" /* In lieu of Solaris <sys/elf.h> */ 77#include "ctf.h" /* In lieu of Solaris <sys/ctf.h> */ 78 79#ifdef __cplusplus 80extern "C" { 81#endif 82 83/* 84 * Clients can open one or more CTF containers and obtain a pointer to an 85 * opaque ctf_file_t. Types are identified by an opaque ctf_id_t token. 86 * These opaque definitions allow libctf to evolve without breaking clients. 87 */ 88typedef struct ctf_file ctf_file_t; 89typedef long ctf_id_t; 90 91/* 92 * If the debugger needs to provide the CTF library with a set of raw buffers 93 * for use as the CTF data, symbol table, and string table, it can do so by 94 * filling in ctf_sect_t structures and passing them to ctf_bufopen(): 95 */ 96typedef struct ctf_sect { 97 const char *cts_name; /* section name (if any) */ 98 ulong_t cts_type; /* section type (ELF SHT_... value) */ 99 ulong_t cts_flags; /* section flags (ELF SHF_... value) */ 100 const void *cts_data; /* pointer to section data */ 101 size_t cts_size; /* size of data in bytes */ 102 size_t cts_entsize; /* size of each section entry (symtab only) */ 103 off64_t cts_offset; /* file offset of this section (if any) */ 104} ctf_sect_t; 105 106/* 107 * Encoding information for integers, floating-point values, and certain other 108 * intrinsics can be obtained by calling ctf_type_encoding(), below. The flags 109 * field will contain values appropriate for the type defined in <sys/ctf.h>. 110 */ 111typedef struct ctf_encoding { 112 uint_t cte_format; /* data format (CTF_INT_* or CTF_FP_* flags) */ 113 uint_t cte_offset; /* offset of value in bits */ 114 uint_t cte_bits; /* size of storage in bits */ 115} ctf_encoding_t; 116 117typedef struct ctf_membinfo { 118 ctf_id_t ctm_type; /* type of struct or union member */ 119 ulong_t ctm_offset; /* offset of member in bits */ 120} ctf_membinfo_t; 121 122typedef struct ctf_arinfo { 123 ctf_id_t ctr_contents; /* type of array contents */ 124 ctf_id_t ctr_index; /* type of array index */ 125 uint_t ctr_nelems; /* number of elements */ 126} ctf_arinfo_t; 127 128typedef struct ctf_funcinfo { 129 ctf_id_t ctc_return; /* function return type */ 130 uint_t ctc_argc; /* number of typed arguments to function */ 131 uint_t ctc_flags; /* function attributes (see below) */ 132} ctf_funcinfo_t; 133 134typedef struct ctf_lblinfo { 135 ctf_id_t ctb_typeidx; /* last type associated with the label */ 136} ctf_lblinfo_t; 137 138#define CTF_FUNC_VARARG 0x1 /* function arguments end with varargs */ 139 140/* 141 * Functions that return integer status or a ctf_id_t use the following value 142 * to indicate failure. ctf_errno() can be used to obtain an error code. 143 */ 144#define CTF_ERR (-1L) 145 146/* 147 * The CTF data model is inferred to be the caller's data model or the data 148 * model of the given object, unless ctf_setmodel() is explicitly called. 149 */ 150#define CTF_MODEL_ILP32 1 /* object data model is ILP32 */ 151#define CTF_MODEL_LP64 2 /* object data model is LP64 */ 152#ifdef _LP64 153#define CTF_MODEL_NATIVE CTF_MODEL_LP64 154#else 155#define CTF_MODEL_NATIVE CTF_MODEL_ILP32 156#endif 157 158/* 159 * Dynamic CTF containers can be created using ctf_create(). The ctf_add_* 160 * routines can be used to add new definitions to the dynamic container. 161 * New types are labeled as root or non-root to determine whether they are 162 * visible at the top-level program scope when subsequently doing a lookup. 163 */ 164#define CTF_ADD_NONROOT 0 /* type only visible in nested scope */ 165#define CTF_ADD_ROOT 1 /* type visible at top-level scope */ 166 167/* 168 * These typedefs are used to define the signature for callback functions 169 * that can be used with the iteration and visit functions below: 170 */ 171typedef int ctf_visit_f(const char *, ctf_id_t, ulong_t, int, void *); 172typedef int ctf_member_f(const char *, ctf_id_t, ulong_t, void *); 173typedef int ctf_enum_f(const char *, int, void *); 174typedef int ctf_type_f(ctf_id_t, void *); 175typedef int ctf_label_f(const char *, const ctf_lblinfo_t *, void *); 176 177extern ctf_file_t *ctf_bufopen(const ctf_sect_t *, const ctf_sect_t *, 178 const ctf_sect_t *, int *); 179extern ctf_file_t *ctf_fdopen(int, int *); 180extern ctf_file_t *ctf_open(const char *, int *); 181extern ctf_file_t *ctf_create(int *); 182extern void ctf_close(ctf_file_t *); 183 184extern ctf_file_t *ctf_parent_file(ctf_file_t *); 185extern const char *ctf_parent_name(ctf_file_t *); 186 187extern int ctf_import(ctf_file_t *, ctf_file_t *); 188extern int ctf_setmodel(ctf_file_t *, int); 189extern int ctf_getmodel(ctf_file_t *); 190 191extern void ctf_setspecific(ctf_file_t *, void *); 192extern void *ctf_getspecific(ctf_file_t *); 193 194extern int ctf_errno(ctf_file_t *); 195extern const char *ctf_errmsg(int); 196extern int ctf_version(int); 197 198extern int ctf_func_info(ctf_file_t *, ulong_t, ctf_funcinfo_t *); 199extern int ctf_func_args(ctf_file_t *, ulong_t, uint_t, ctf_id_t *); 200 201extern ctf_id_t ctf_lookup_by_name(ctf_file_t *, const char *); 202extern ctf_id_t ctf_lookup_by_symbol(ctf_file_t *, ulong_t); 203 204extern ctf_id_t ctf_type_resolve(ctf_file_t *, ctf_id_t); 205extern ssize_t ctf_type_lname(ctf_file_t *, ctf_id_t, char *, size_t); 206extern char *ctf_type_name(ctf_file_t *, ctf_id_t, char *, size_t); 207extern ssize_t ctf_type_size(ctf_file_t *, ctf_id_t); 208extern ssize_t ctf_type_align(ctf_file_t *, ctf_id_t); 209extern int ctf_type_kind(ctf_file_t *, ctf_id_t); 210extern ctf_id_t ctf_type_reference(ctf_file_t *, ctf_id_t); 211extern ctf_id_t ctf_type_pointer(ctf_file_t *, ctf_id_t); 212extern int ctf_type_encoding(ctf_file_t *, ctf_id_t, ctf_encoding_t *); 213extern int ctf_type_visit(ctf_file_t *, ctf_id_t, ctf_visit_f *, void *); 214extern int ctf_type_cmp(ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t); 215extern int ctf_type_compat(ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t); 216extern int ctf_type_printf_compat(ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t); 217 218extern int ctf_member_info(ctf_file_t *, ctf_id_t, const char *, 219 ctf_membinfo_t *); 220extern int ctf_array_info(ctf_file_t *, ctf_id_t, ctf_arinfo_t *); 221 222extern const char *ctf_enum_name(ctf_file_t *, ctf_id_t, int); 223extern int ctf_enum_value(ctf_file_t *, ctf_id_t, const char *, int *); 224 225extern const char *ctf_label_topmost(ctf_file_t *); 226extern int ctf_label_info(ctf_file_t *, const char *, ctf_lblinfo_t *); 227 228extern int ctf_member_iter(ctf_file_t *, ctf_id_t, ctf_member_f *, void *); 229extern int ctf_enum_iter(ctf_file_t *, ctf_id_t, ctf_enum_f *, void *); 230extern int ctf_type_iter(ctf_file_t *, ctf_type_f *, void *); 231extern int ctf_label_iter(ctf_file_t *, ctf_label_f *, void *); 232 233extern ctf_id_t ctf_add_array(ctf_file_t *, uint_t, const ctf_arinfo_t *); 234extern ctf_id_t ctf_add_const(ctf_file_t *, uint_t, ctf_id_t); 235extern ctf_id_t ctf_add_enum(ctf_file_t *, uint_t, const char *); 236extern ctf_id_t ctf_add_float(ctf_file_t *, uint_t, 237 const char *, const ctf_encoding_t *); 238extern ctf_id_t ctf_add_forward(ctf_file_t *, uint_t, const char *, uint_t); 239extern ctf_id_t ctf_add_function(ctf_file_t *, uint_t, 240 const ctf_funcinfo_t *, const ctf_id_t *); 241extern ctf_id_t ctf_add_integer(ctf_file_t *, uint_t, 242 const char *, const ctf_encoding_t *); 243extern ctf_id_t ctf_add_pointer(ctf_file_t *, uint_t, ctf_id_t); 244extern ctf_id_t ctf_add_type(ctf_file_t *, ctf_file_t *, ctf_id_t); 245extern ctf_id_t ctf_add_typedef(ctf_file_t *, uint_t, const char *, ctf_id_t); 246extern ctf_id_t ctf_add_restrict(ctf_file_t *, uint_t, ctf_id_t); 247extern ctf_id_t ctf_add_struct(ctf_file_t *, uint_t, const char *); 248extern ctf_id_t ctf_add_union(ctf_file_t *, uint_t, const char *); 249extern ctf_id_t ctf_add_volatile(ctf_file_t *, uint_t, ctf_id_t); 250 251extern int ctf_add_enumerator(ctf_file_t *, ctf_id_t, const char *, int); 252extern int ctf_add_member(ctf_file_t *, ctf_id_t, const char *, ctf_id_t); 253 254extern int ctf_set_array(ctf_file_t *, ctf_id_t, const ctf_arinfo_t *); 255 256extern int ctf_update(ctf_file_t *); 257extern int ctf_discard(ctf_file_t *); 258extern int ctf_write(ctf_file_t *, int); 259 260#ifdef _KERNEL 261 262struct module; 263extern ctf_file_t *ctf_modopen(struct module *, int *); 264 265#endif 266 267#ifdef __cplusplus 268} 269#endif 270 271#endif /* _CTF_API_H */ 272