xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_ctf.h (revision c71ad176)
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 extern int mdb_ctf_enum_iter(mdb_ctf_id_t, mdb_ctf_enum_f *, void *);
105 extern int mdb_ctf_type_iter(const char *, mdb_ctf_type_f *, void *);
106 extern int mdb_ctf_type_delete(const mdb_ctf_id_t *);
107 
108 /*
109  * Special values for mdb_ctf_type_iter.
110  */
111 #define	MDB_CTF_SYNTHETIC_ITER	(const char *)(-1L)
112 
113 #define	SYNTHETIC_ILP32	1
114 #define	SYNTHETIC_LP64	2
115 extern int mdb_ctf_synthetics_create_base(int);
116 extern int mdb_ctf_synthetics_reset(void);
117 
118 /*
119  * Synthetic creation routines
120  */
121 extern int mdb_ctf_add_typedef(const char *, const mdb_ctf_id_t *,
122     mdb_ctf_id_t *);
123 extern int mdb_ctf_add_struct(const char *, mdb_ctf_id_t *);
124 extern int mdb_ctf_add_union(const char *, mdb_ctf_id_t *);
125 extern int mdb_ctf_add_member(const mdb_ctf_id_t *, const char *,
126     const mdb_ctf_id_t *, mdb_ctf_id_t *);
127 extern int mdb_ctf_add_array(const mdb_ctf_arinfo_t *, mdb_ctf_id_t *);
128 extern int mdb_ctf_add_pointer(const mdb_ctf_id_t *, mdb_ctf_id_t *);
129 
130 /* utility stuff */
131 extern ctf_id_t mdb_ctf_type_id(mdb_ctf_id_t);
132 extern ctf_file_t *mdb_ctf_type_file(mdb_ctf_id_t);
133 
134 
135 extern int mdb_ctf_member_info(mdb_ctf_id_t, const char *,
136     ulong_t *, mdb_ctf_id_t *);
137 extern int mdb_ctf_offsetof(mdb_ctf_id_t, const char *, ulong_t *);
138 extern int mdb_ctf_num_members(mdb_ctf_id_t);
139 extern int mdb_ctf_offsetof_by_name(const char *, const char *);
140 extern ssize_t mdb_ctf_sizeof_by_name(const char *);
141 
142 extern ssize_t mdb_ctf_offset_to_name(mdb_ctf_id_t, ulong_t, char *, size_t,
143     int, mdb_ctf_id_t *, ulong_t *);
144 
145 #define	MDB_CTF_VREAD_QUIET		0x100
146 #define	MDB_CTF_VREAD_IGNORE_ABSENT	0x200
147 
148 extern int mdb_ctf_vread(void *, const char *, const char *,
149     uintptr_t, uint_t);
150 extern int mdb_ctf_readsym(void *, const char *, const char *, uint_t);
151 
152 #ifdef _MDB
153 
154 extern ctf_file_t *mdb_ctf_open(const char *, int *);		/* Internal */
155 extern ctf_file_t *mdb_ctf_bufopen(const void *, size_t,	/* Internal */
156     const void *, Shdr *, const void *, Shdr *, int *);
157 extern int mdb_ctf_write(const char *, ctf_file_t *fp);		/* Internal */
158 extern void mdb_ctf_close(ctf_file_t *fp);			/* Internal */
159 extern int mdb_ctf_synthetics_init(void);			/* Internal */
160 extern void mdb_ctf_synthetics_fini(void);			/* Internal */
161 extern int mdb_ctf_synthetics_from_file(const char *);		/* Internal */
162 extern int mdb_ctf_synthetics_to_file(const char *);		/* Internal */
163 extern int cmd_typelist(uintptr_t, uint_t, int,			/* Internal */
164     const mdb_arg_t *);
165 
166 #endif
167 
168 #ifdef	__cplusplus
169 }
170 #endif
171 
172 #endif	/* _MDB_CTF_H */
173