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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 /* 26 * Copyright (c) 2013, 2015 by Delphix. All rights reserved. 27 * Copyright 2018 Joyent, Inc. 28 */ 29 30 #ifndef _MDB_CTF_H 31 #define _MDB_CTF_H 32 33 #include <mdb/mdb_target.h> 34 #include <libctf.h> 35 36 #ifdef _MDB 37 #include <sys/machelf.h> 38 #include <mdb/mdb_modapi.h> 39 #endif 40 41 /* 42 * The following directive tells the mapfile generator that prototypes and 43 * declarations ending with an "Internal" comment should be excluded from the 44 * mapfile. 45 * 46 * MAPFILE: exclude "Internal" 47 */ 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 typedef struct mdb_ctf_id { 54 void *_opaque[2]; 55 } mdb_ctf_id_t; 56 57 typedef struct mdb_ctf_funcinfo { 58 mdb_ctf_id_t mtf_return; /* function return type */ 59 uint_t mtf_argc; /* number of arguments */ 60 uint_t mtf_flags; /* function attributes (see libctf.h) */ 61 uint_t mtf_symidx; /* for ctf_func_args */ 62 } mdb_ctf_funcinfo_t; 63 64 typedef struct mdb_ctf_arinfo { 65 mdb_ctf_id_t mta_contents; /* type of array conents */ 66 mdb_ctf_id_t mta_index; /* type of array index */ 67 uint_t mta_nelems; /* number of elements */ 68 } mdb_ctf_arinfo_t; 69 70 typedef int mdb_ctf_visit_f(const char *, mdb_ctf_id_t, mdb_ctf_id_t, ulong_t, 71 int, void *); 72 typedef int mdb_ctf_member_f(const char *, mdb_ctf_id_t, ulong_t, void *); 73 typedef int mdb_ctf_enum_f(const char *, int, void *); 74 typedef int mdb_ctf_type_f(mdb_ctf_id_t, void *); 75 76 extern int mdb_ctf_enabled_by_object(const char *); 77 78 extern int mdb_ctf_lookup_by_name(const char *, mdb_ctf_id_t *); 79 extern int mdb_ctf_lookup_by_addr(uintptr_t, mdb_ctf_id_t *); 80 81 extern int mdb_ctf_module_lookup(const char *, mdb_ctf_id_t *); 82 83 extern int mdb_ctf_func_info(const GElf_Sym *, const mdb_syminfo_t *, 84 mdb_ctf_funcinfo_t *); 85 extern int mdb_ctf_func_args(const mdb_ctf_funcinfo_t *, uint_t, 86 mdb_ctf_id_t *); 87 88 extern void mdb_ctf_type_invalidate(mdb_ctf_id_t *); 89 extern int mdb_ctf_type_valid(mdb_ctf_id_t); 90 extern int mdb_ctf_type_cmp(mdb_ctf_id_t, mdb_ctf_id_t); 91 92 extern int mdb_ctf_type_resolve(mdb_ctf_id_t, mdb_ctf_id_t *); 93 extern char *mdb_ctf_type_name(mdb_ctf_id_t, char *, size_t); 94 extern ssize_t mdb_ctf_type_size(mdb_ctf_id_t); 95 extern int mdb_ctf_type_kind(mdb_ctf_id_t); 96 extern int mdb_ctf_type_reference(const mdb_ctf_id_t, mdb_ctf_id_t *); 97 extern int mdb_ctf_type_encoding(mdb_ctf_id_t, ctf_encoding_t *); 98 extern int mdb_ctf_type_visit(mdb_ctf_id_t, mdb_ctf_visit_f *, void *); 99 100 extern int mdb_ctf_array_info(mdb_ctf_id_t, mdb_ctf_arinfo_t *); 101 extern const char *mdb_ctf_enum_name(mdb_ctf_id_t, int); 102 103 extern int mdb_ctf_member_iter(mdb_ctf_id_t, mdb_ctf_member_f *, void *, 104 uint32_t); 105 extern int mdb_ctf_enum_iter(mdb_ctf_id_t, mdb_ctf_enum_f *, void *); 106 extern int mdb_ctf_type_iter(const char *, mdb_ctf_type_f *, void *); 107 extern int mdb_ctf_type_delete(const mdb_ctf_id_t *); 108 109 /* 110 * Flags to mdb_ctf_member_iter to change iteration behavior. 111 * 112 * MDB_CTF_F_ITER_ANON This controls whether or not type member 113 * iteration will descend into anonymous structs 114 * or unions recursively. This is used for cases 115 * where one is trying to reason about member 116 * references (ala ::print) in a similar way to a C 117 * compiler. 118 */ 119 #define MDB_CTF_F_ITER_ANON (1 << 0) 120 121 /* 122 * Special values for mdb_ctf_type_iter. 123 */ 124 #define MDB_CTF_SYNTHETIC_ITER (const char *)(-1L) 125 126 #define SYNTHETIC_ILP32 1 127 #define SYNTHETIC_LP64 2 128 extern int mdb_ctf_synthetics_create_base(int); 129 extern int mdb_ctf_synthetics_reset(void); 130 131 /* 132 * Synthetic creation routines 133 */ 134 extern int mdb_ctf_add_typedef(const char *, const mdb_ctf_id_t *, 135 mdb_ctf_id_t *); 136 extern int mdb_ctf_add_struct(const char *, mdb_ctf_id_t *); 137 extern int mdb_ctf_add_union(const char *, mdb_ctf_id_t *); 138 extern int mdb_ctf_add_member(const mdb_ctf_id_t *, const char *, 139 const mdb_ctf_id_t *, mdb_ctf_id_t *); 140 extern int mdb_ctf_add_array(const mdb_ctf_arinfo_t *, mdb_ctf_id_t *); 141 extern int mdb_ctf_add_pointer(const mdb_ctf_id_t *, mdb_ctf_id_t *); 142 143 /* utility stuff */ 144 extern ctf_id_t mdb_ctf_type_id(mdb_ctf_id_t); 145 extern ctf_file_t *mdb_ctf_type_file(mdb_ctf_id_t); 146 147 148 extern int mdb_ctf_member_info(mdb_ctf_id_t, const char *, 149 ulong_t *, mdb_ctf_id_t *); 150 extern int mdb_ctf_offsetof(mdb_ctf_id_t, const char *, ulong_t *); 151 extern int mdb_ctf_num_members(mdb_ctf_id_t); 152 extern int mdb_ctf_offsetof_by_name(const char *, const char *); 153 extern ssize_t mdb_ctf_sizeof_by_name(const char *); 154 155 extern ssize_t mdb_ctf_offset_to_name(mdb_ctf_id_t, ulong_t, char *, size_t, 156 int, mdb_ctf_id_t *, ulong_t *); 157 158 #define MDB_CTF_VREAD_QUIET 0x100 159 #define MDB_CTF_VREAD_IGNORE_ABSENT 0x200 160 161 extern int mdb_ctf_vread(void *, const char *, const char *, 162 uintptr_t, uint_t); 163 extern int mdb_ctf_readsym(void *, const char *, const char *, uint_t); 164 165 #ifdef _MDB 166 167 extern ctf_file_t *mdb_ctf_open(const char *, int *); /* Internal */ 168 extern ctf_file_t *mdb_ctf_bufopen(const void *, size_t, /* Internal */ 169 const void *, Shdr *, const void *, Shdr *, int *); 170 extern int mdb_ctf_write(const char *, ctf_file_t *fp); /* Internal */ 171 extern void mdb_ctf_close(ctf_file_t *fp); /* Internal */ 172 extern int mdb_ctf_synthetics_init(void); /* Internal */ 173 extern void mdb_ctf_synthetics_fini(void); /* Internal */ 174 extern int mdb_ctf_synthetics_from_file(const char *); /* Internal */ 175 extern int mdb_ctf_synthetics_to_file(const char *); /* Internal */ 176 extern int cmd_typelist(uintptr_t, uint_t, int, /* Internal */ 177 const mdb_arg_t *); 178 179 #endif 180 181 #ifdef __cplusplus 182 } 183 #endif 184 185 #endif /* _MDB_CTF_H */ 186