17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 260a47c91cSRobert Mustacchi /* 27*a386cc11SRobert Mustacchi * Copyright (c) 2013, Joyent, Inc. All rights reserved. 280a47c91cSRobert Mustacchi */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * This header file defines the interfaces available from the CTF debugger 327c478bd9Sstevel@tonic-gate * library, libctf, and an equivalent kernel module. This API can be used by 337c478bd9Sstevel@tonic-gate * a debugger to operate on data in the Compact ANSI-C Type Format (CTF). 347c478bd9Sstevel@tonic-gate * This is NOT a public interface, although it may eventually become one in 357c478bd9Sstevel@tonic-gate * the fullness of time after we gain more experience with the interfaces. 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * In the meantime, be aware that any program linked with this API in this 387c478bd9Sstevel@tonic-gate * release of Solaris is almost guaranteed to break in the next release. 397c478bd9Sstevel@tonic-gate * 407c478bd9Sstevel@tonic-gate * In short, do not user this header file or the CTF routines for any purpose. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifndef _CTF_API_H 447c478bd9Sstevel@tonic-gate #define _CTF_API_H 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include <sys/types.h> 477c478bd9Sstevel@tonic-gate #include <sys/param.h> 487c478bd9Sstevel@tonic-gate #include <sys/elf.h> 497c478bd9Sstevel@tonic-gate #include <sys/ctf.h> 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #ifdef __cplusplus 527c478bd9Sstevel@tonic-gate extern "C" { 537c478bd9Sstevel@tonic-gate #endif 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * Clients can open one or more CTF containers and obtain a pointer to an 577c478bd9Sstevel@tonic-gate * opaque ctf_file_t. Types are identified by an opaque ctf_id_t token. 587c478bd9Sstevel@tonic-gate * These opaque definitions allow libctf to evolve without breaking clients. 597c478bd9Sstevel@tonic-gate */ 607c478bd9Sstevel@tonic-gate typedef struct ctf_file ctf_file_t; 617c478bd9Sstevel@tonic-gate typedef long ctf_id_t; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * If the debugger needs to provide the CTF library with a set of raw buffers 657c478bd9Sstevel@tonic-gate * for use as the CTF data, symbol table, and string table, it can do so by 667c478bd9Sstevel@tonic-gate * filling in ctf_sect_t structures and passing them to ctf_bufopen(): 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate typedef struct ctf_sect { 697c478bd9Sstevel@tonic-gate const char *cts_name; /* section name (if any) */ 707c478bd9Sstevel@tonic-gate ulong_t cts_type; /* section type (ELF SHT_... value) */ 717c478bd9Sstevel@tonic-gate ulong_t cts_flags; /* section flags (ELF SHF_... value) */ 727c478bd9Sstevel@tonic-gate const void *cts_data; /* pointer to section data */ 737c478bd9Sstevel@tonic-gate size_t cts_size; /* size of data in bytes */ 747c478bd9Sstevel@tonic-gate size_t cts_entsize; /* size of each section entry (symtab only) */ 757c478bd9Sstevel@tonic-gate off64_t cts_offset; /* file offset of this section (if any) */ 767c478bd9Sstevel@tonic-gate } ctf_sect_t; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* 797c478bd9Sstevel@tonic-gate * Encoding information for integers, floating-point values, and certain other 807c478bd9Sstevel@tonic-gate * intrinsics can be obtained by calling ctf_type_encoding(), below. The flags 817c478bd9Sstevel@tonic-gate * field will contain values appropriate for the type defined in <sys/ctf.h>. 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate typedef struct ctf_encoding { 847c478bd9Sstevel@tonic-gate uint_t cte_format; /* data format (CTF_INT_* or CTF_FP_* flags) */ 857c478bd9Sstevel@tonic-gate uint_t cte_offset; /* offset of value in bits */ 867c478bd9Sstevel@tonic-gate uint_t cte_bits; /* size of storage in bits */ 877c478bd9Sstevel@tonic-gate } ctf_encoding_t; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate typedef struct ctf_membinfo { 907c478bd9Sstevel@tonic-gate ctf_id_t ctm_type; /* type of struct or union member */ 917c478bd9Sstevel@tonic-gate ulong_t ctm_offset; /* offset of member in bits */ 927c478bd9Sstevel@tonic-gate } ctf_membinfo_t; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate typedef struct ctf_arinfo { 957c478bd9Sstevel@tonic-gate ctf_id_t ctr_contents; /* type of array contents */ 967c478bd9Sstevel@tonic-gate ctf_id_t ctr_index; /* type of array index */ 977c478bd9Sstevel@tonic-gate uint_t ctr_nelems; /* number of elements */ 987c478bd9Sstevel@tonic-gate } ctf_arinfo_t; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate typedef struct ctf_funcinfo { 1017c478bd9Sstevel@tonic-gate ctf_id_t ctc_return; /* function return type */ 1027c478bd9Sstevel@tonic-gate uint_t ctc_argc; /* number of typed arguments to function */ 1037c478bd9Sstevel@tonic-gate uint_t ctc_flags; /* function attributes (see below) */ 1047c478bd9Sstevel@tonic-gate } ctf_funcinfo_t; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate typedef struct ctf_lblinfo { 1077c478bd9Sstevel@tonic-gate ctf_id_t ctb_typeidx; /* last type associated with the label */ 1087c478bd9Sstevel@tonic-gate } ctf_lblinfo_t; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define CTF_FUNC_VARARG 0x1 /* function arguments end with varargs */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * Functions that return integer status or a ctf_id_t use the following value 1147c478bd9Sstevel@tonic-gate * to indicate failure. ctf_errno() can be used to obtain an error code. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate #define CTF_ERR (-1L) 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* 1197c478bd9Sstevel@tonic-gate * The CTF data model is inferred to be the caller's data model or the data 1207c478bd9Sstevel@tonic-gate * model of the given object, unless ctf_setmodel() is explicitly called. 1217c478bd9Sstevel@tonic-gate */ 1227c478bd9Sstevel@tonic-gate #define CTF_MODEL_ILP32 1 /* object data model is ILP32 */ 1237c478bd9Sstevel@tonic-gate #define CTF_MODEL_LP64 2 /* object data model is LP64 */ 1247c478bd9Sstevel@tonic-gate #ifdef _LP64 1257c478bd9Sstevel@tonic-gate #define CTF_MODEL_NATIVE CTF_MODEL_LP64 1267c478bd9Sstevel@tonic-gate #else 1277c478bd9Sstevel@tonic-gate #define CTF_MODEL_NATIVE CTF_MODEL_ILP32 1287c478bd9Sstevel@tonic-gate #endif 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Dynamic CTF containers can be created using ctf_create(). The ctf_add_* 1327c478bd9Sstevel@tonic-gate * routines can be used to add new definitions to the dynamic container. 1337c478bd9Sstevel@tonic-gate * New types are labeled as root or non-root to determine whether they are 1347c478bd9Sstevel@tonic-gate * visible at the top-level program scope when subsequently doing a lookup. 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate #define CTF_ADD_NONROOT 0 /* type only visible in nested scope */ 1377c478bd9Sstevel@tonic-gate #define CTF_ADD_ROOT 1 /* type visible at top-level scope */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * These typedefs are used to define the signature for callback functions 1417c478bd9Sstevel@tonic-gate * that can be used with the iteration and visit functions below: 1427c478bd9Sstevel@tonic-gate */ 1437c478bd9Sstevel@tonic-gate typedef int ctf_visit_f(const char *, ctf_id_t, ulong_t, int, void *); 1447c478bd9Sstevel@tonic-gate typedef int ctf_member_f(const char *, ctf_id_t, ulong_t, void *); 1457c478bd9Sstevel@tonic-gate typedef int ctf_enum_f(const char *, int, void *); 1467c478bd9Sstevel@tonic-gate typedef int ctf_type_f(ctf_id_t, void *); 1477c478bd9Sstevel@tonic-gate typedef int ctf_label_f(const char *, const ctf_lblinfo_t *, void *); 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate extern ctf_file_t *ctf_bufopen(const ctf_sect_t *, const ctf_sect_t *, 1507c478bd9Sstevel@tonic-gate const ctf_sect_t *, int *); 1517c478bd9Sstevel@tonic-gate extern ctf_file_t *ctf_fdopen(int, int *); 1527c478bd9Sstevel@tonic-gate extern ctf_file_t *ctf_open(const char *, int *); 1537c478bd9Sstevel@tonic-gate extern ctf_file_t *ctf_create(int *); 154*a386cc11SRobert Mustacchi extern ctf_file_t *ctf_dup(ctf_file_t *); 1557c478bd9Sstevel@tonic-gate extern void ctf_close(ctf_file_t *); 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate extern ctf_file_t *ctf_parent_file(ctf_file_t *); 1587c478bd9Sstevel@tonic-gate extern const char *ctf_parent_name(ctf_file_t *); 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern int ctf_import(ctf_file_t *, ctf_file_t *); 1617c478bd9Sstevel@tonic-gate extern int ctf_setmodel(ctf_file_t *, int); 1627c478bd9Sstevel@tonic-gate extern int ctf_getmodel(ctf_file_t *); 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate extern void ctf_setspecific(ctf_file_t *, void *); 1657c478bd9Sstevel@tonic-gate extern void *ctf_getspecific(ctf_file_t *); 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate extern int ctf_errno(ctf_file_t *); 1687c478bd9Sstevel@tonic-gate extern const char *ctf_errmsg(int); 1697c478bd9Sstevel@tonic-gate extern int ctf_version(int); 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate extern int ctf_func_info(ctf_file_t *, ulong_t, ctf_funcinfo_t *); 1727c478bd9Sstevel@tonic-gate extern int ctf_func_args(ctf_file_t *, ulong_t, uint_t, ctf_id_t *); 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_lookup_by_name(ctf_file_t *, const char *); 1757c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_lookup_by_symbol(ctf_file_t *, ulong_t); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_type_resolve(ctf_file_t *, ctf_id_t); 1787c478bd9Sstevel@tonic-gate extern ssize_t ctf_type_lname(ctf_file_t *, ctf_id_t, char *, size_t); 1797c478bd9Sstevel@tonic-gate extern char *ctf_type_name(ctf_file_t *, ctf_id_t, char *, size_t); 180*a386cc11SRobert Mustacchi extern char *ctf_type_qname(ctf_file_t *, ctf_id_t, char *, size_t, 181*a386cc11SRobert Mustacchi const char *); 1827c478bd9Sstevel@tonic-gate extern ssize_t ctf_type_size(ctf_file_t *, ctf_id_t); 1837c478bd9Sstevel@tonic-gate extern ssize_t ctf_type_align(ctf_file_t *, ctf_id_t); 1847c478bd9Sstevel@tonic-gate extern int ctf_type_kind(ctf_file_t *, ctf_id_t); 1857c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_type_reference(ctf_file_t *, ctf_id_t); 1867c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_type_pointer(ctf_file_t *, ctf_id_t); 1877c478bd9Sstevel@tonic-gate extern int ctf_type_encoding(ctf_file_t *, ctf_id_t, ctf_encoding_t *); 1887c478bd9Sstevel@tonic-gate extern int ctf_type_visit(ctf_file_t *, ctf_id_t, ctf_visit_f *, void *); 1897c478bd9Sstevel@tonic-gate extern int ctf_type_cmp(ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t); 1907c478bd9Sstevel@tonic-gate extern int ctf_type_compat(ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate extern int ctf_member_info(ctf_file_t *, ctf_id_t, const char *, 1937c478bd9Sstevel@tonic-gate ctf_membinfo_t *); 1947c478bd9Sstevel@tonic-gate extern int ctf_array_info(ctf_file_t *, ctf_id_t, ctf_arinfo_t *); 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate extern const char *ctf_enum_name(ctf_file_t *, ctf_id_t, int); 1977c478bd9Sstevel@tonic-gate extern int ctf_enum_value(ctf_file_t *, ctf_id_t, const char *, int *); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate extern const char *ctf_label_topmost(ctf_file_t *); 2007c478bd9Sstevel@tonic-gate extern int ctf_label_info(ctf_file_t *, const char *, ctf_lblinfo_t *); 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate extern int ctf_member_iter(ctf_file_t *, ctf_id_t, ctf_member_f *, void *); 2037c478bd9Sstevel@tonic-gate extern int ctf_enum_iter(ctf_file_t *, ctf_id_t, ctf_enum_f *, void *); 2047c478bd9Sstevel@tonic-gate extern int ctf_type_iter(ctf_file_t *, ctf_type_f *, void *); 2057c478bd9Sstevel@tonic-gate extern int ctf_label_iter(ctf_file_t *, ctf_label_f *, void *); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_array(ctf_file_t *, uint_t, const ctf_arinfo_t *); 2087c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_const(ctf_file_t *, uint_t, ctf_id_t); 2097c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_enum(ctf_file_t *, uint_t, const char *); 2107c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_float(ctf_file_t *, uint_t, 2117c478bd9Sstevel@tonic-gate const char *, const ctf_encoding_t *); 2127c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_forward(ctf_file_t *, uint_t, const char *, uint_t); 2137c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_function(ctf_file_t *, uint_t, 2147c478bd9Sstevel@tonic-gate const ctf_funcinfo_t *, const ctf_id_t *); 2157c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_integer(ctf_file_t *, uint_t, 2167c478bd9Sstevel@tonic-gate const char *, const ctf_encoding_t *); 2177c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_pointer(ctf_file_t *, uint_t, ctf_id_t); 2187c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_type(ctf_file_t *, ctf_file_t *, ctf_id_t); 2197c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_typedef(ctf_file_t *, uint_t, const char *, ctf_id_t); 2207c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_restrict(ctf_file_t *, uint_t, ctf_id_t); 2217c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_struct(ctf_file_t *, uint_t, const char *); 2227c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_union(ctf_file_t *, uint_t, const char *); 2237c478bd9Sstevel@tonic-gate extern ctf_id_t ctf_add_volatile(ctf_file_t *, uint_t, ctf_id_t); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate extern int ctf_add_enumerator(ctf_file_t *, ctf_id_t, const char *, int); 2267c478bd9Sstevel@tonic-gate extern int ctf_add_member(ctf_file_t *, ctf_id_t, const char *, ctf_id_t); 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate extern int ctf_set_array(ctf_file_t *, ctf_id_t, const ctf_arinfo_t *); 2297c478bd9Sstevel@tonic-gate 2300a47c91cSRobert Mustacchi extern int ctf_delete_type(ctf_file_t *, ctf_id_t); 2310a47c91cSRobert Mustacchi 2327c478bd9Sstevel@tonic-gate extern int ctf_update(ctf_file_t *); 2337c478bd9Sstevel@tonic-gate extern int ctf_discard(ctf_file_t *); 2347c478bd9Sstevel@tonic-gate extern int ctf_write(ctf_file_t *, int); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate #ifdef _KERNEL 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate struct module; 2397c478bd9Sstevel@tonic-gate extern ctf_file_t *ctf_modopen(struct module *, int *); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate #endif 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate #endif 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate #endif /* _CTF_API_H */ 248