xref: /titanic_50/usr/src/cmd/mdb/common/mdb/mdb_ctf.h (revision 2becb8cdf9cd77e1a76224f216be15d6ae3b9ec9)
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 by Delphix. All rights reserved.
27  * Copyright (c) 2015, 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 #endif
39 
40 /*
41  * The following directive tells the mapfile generator that prototypes and
42  * declarations ending with an "Internal" comment should be excluded from the
43  * mapfile.
44  *
45  * MAPFILE: exclude "Internal"
46  */
47 
48 #ifdef	__cplusplus
49 extern "C" {
50 #endif
51 
52 typedef struct mdb_ctf_id {
53 	void *_opaque[2];
54 } mdb_ctf_id_t;
55 
56 typedef struct mdb_ctf_funcinfo {
57 	mdb_ctf_id_t mtf_return;	/* function return type */
58 	uint_t mtf_argc;		/* number of arguments */
59 	uint_t mtf_flags;		/* function attributes (see libctf.h) */
60 	uint_t mtf_symidx;		/* for ctf_func_args */
61 } mdb_ctf_funcinfo_t;
62 
63 typedef struct mdb_ctf_arinfo {
64 	mdb_ctf_id_t mta_contents;	/* type of array conents */
65 	mdb_ctf_id_t mta_index;		/* type of array index */
66 	uint_t mta_nelems;		/* number of elements */
67 } mdb_ctf_arinfo_t;
68 
69 typedef int mdb_ctf_visit_f(const char *, mdb_ctf_id_t, mdb_ctf_id_t, ulong_t,
70     int, void *);
71 typedef int mdb_ctf_member_f(const char *, mdb_ctf_id_t, ulong_t, void *);
72 typedef int mdb_ctf_enum_f(const char *, int, void *);
73 typedef int mdb_ctf_type_f(mdb_ctf_id_t, void *);
74 
75 extern int mdb_ctf_enabled_by_object(const char *);
76 
77 extern int mdb_ctf_lookup_by_name(const char *, mdb_ctf_id_t *);
78 extern int mdb_ctf_lookup_by_addr(uintptr_t, mdb_ctf_id_t *);
79 
80 extern int mdb_ctf_module_lookup(const char *, mdb_ctf_id_t *);
81 
82 extern int mdb_ctf_func_info(const GElf_Sym *, const mdb_syminfo_t *,
83     mdb_ctf_funcinfo_t *);
84 extern int mdb_ctf_func_args(const mdb_ctf_funcinfo_t *, uint_t,
85     mdb_ctf_id_t *);
86 
87 extern void mdb_ctf_type_invalidate(mdb_ctf_id_t *);
88 extern int mdb_ctf_type_valid(mdb_ctf_id_t);
89 extern int mdb_ctf_type_cmp(mdb_ctf_id_t, mdb_ctf_id_t);
90 
91 extern int mdb_ctf_type_resolve(mdb_ctf_id_t, mdb_ctf_id_t *);
92 extern char *mdb_ctf_type_name(mdb_ctf_id_t, char *, size_t);
93 extern ssize_t mdb_ctf_type_size(mdb_ctf_id_t);
94 extern int mdb_ctf_type_kind(mdb_ctf_id_t);
95 extern int mdb_ctf_type_reference(const mdb_ctf_id_t, mdb_ctf_id_t *);
96 extern int mdb_ctf_type_encoding(mdb_ctf_id_t, ctf_encoding_t *);
97 extern int mdb_ctf_type_visit(mdb_ctf_id_t, mdb_ctf_visit_f *, void *);
98 
99 extern int mdb_ctf_array_info(mdb_ctf_id_t, mdb_ctf_arinfo_t *);
100 extern const char *mdb_ctf_enum_name(mdb_ctf_id_t, int);
101 
102 extern int mdb_ctf_member_iter(mdb_ctf_id_t, mdb_ctf_member_f *, void *);
103 extern int mdb_ctf_enum_iter(mdb_ctf_id_t, mdb_ctf_enum_f *, void *);
104 extern int mdb_ctf_type_iter(const char *, mdb_ctf_type_f *, void *);
105 extern int mdb_ctf_type_delete(const mdb_ctf_id_t *);
106 
107 /*
108  * Special values for mdb_ctf_type_iter.
109  */
110 #define	MDB_CTF_SYNTHETIC_ITER	(const char *)(-1L)
111 
112 #define	SYNTHETIC_ILP32	1
113 #define	SYNTHETIC_LP64	2
114 extern int mdb_ctf_synthetics_create_base(int);
115 extern int mdb_ctf_synthetics_reset(void);
116 
117 /*
118  * Synthetic creation routines
119  */
120 extern int mdb_ctf_add_typedef(const char *, const mdb_ctf_id_t *,
121     mdb_ctf_id_t *);
122 extern int mdb_ctf_add_struct(const char *, mdb_ctf_id_t *);
123 extern int mdb_ctf_add_union(const char *, mdb_ctf_id_t *);
124 extern int mdb_ctf_add_member(const mdb_ctf_id_t *, const char *,
125     const mdb_ctf_id_t *, mdb_ctf_id_t *);
126 extern int mdb_ctf_add_array(const mdb_ctf_arinfo_t *, mdb_ctf_id_t *);
127 extern int mdb_ctf_add_pointer(const mdb_ctf_id_t *, mdb_ctf_id_t *);
128 
129 /* utility stuff */
130 extern ctf_id_t mdb_ctf_type_id(mdb_ctf_id_t);
131 extern ctf_file_t *mdb_ctf_type_file(mdb_ctf_id_t);
132 
133 
134 extern int mdb_ctf_member_info(mdb_ctf_id_t, const char *,
135     ulong_t *, mdb_ctf_id_t *);
136 extern int mdb_ctf_offsetof(mdb_ctf_id_t, const char *, ulong_t *);
137 extern int mdb_ctf_num_members(mdb_ctf_id_t);
138 extern int mdb_ctf_offsetof_by_name(const char *, const char *);
139 
140 extern ssize_t mdb_ctf_offset_to_name(mdb_ctf_id_t, ulong_t, char *, size_t,
141     int, mdb_ctf_id_t *, ulong_t *);
142 
143 #define	MDB_CTF_VREAD_QUIET		0x100
144 
145 extern int mdb_ctf_vread(void *, const char *, const char *,
146     uintptr_t, uint_t);
147 extern int mdb_ctf_readsym(void *, const char *, const char *, uint_t);
148 
149 #ifdef _MDB
150 
151 extern ctf_file_t *mdb_ctf_open(const char *, int *);		/* Internal */
152 extern ctf_file_t *mdb_ctf_bufopen(const void *, size_t,	/* Internal */
153     const void *, Shdr *, const void *, Shdr *, int *);
154 extern int mdb_ctf_write(const char *, ctf_file_t *fp);		/* Internal */
155 extern void mdb_ctf_close(ctf_file_t *fp);			/* Internal */
156 extern int mdb_ctf_synthetics_init(void);			/* Internal */
157 extern void mdb_ctf_synthetics_fini(void);			/* Internal */
158 extern int mdb_ctf_synthetics_from_file(const char *);		/* Internal */
159 extern int mdb_ctf_synthetics_to_file(const char *);		/* Internal */
160 
161 #endif
162 
163 #ifdef	__cplusplus
164 }
165 #endif
166 
167 #endif	/* _MDB_CTF_H */
168