xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_ctf.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_MDB_CTF_H
28 #define	_MDB_CTF_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <mdb/mdb_target.h>
33 #include <libctf.h>
34 
35 #ifdef _MDB
36 #include <sys/machelf.h>
37 #endif
38 
39 /*
40  * The following directive tells the mapfile generator that prototypes and
41  * declarations ending with an "Internal" comment should be excluded from the
42  * mapfile.
43  *
44  * MAPFILE: exclude "Internal"
45  */
46 
47 #ifdef	__cplusplus
48 extern "C" {
49 #endif
50 
51 typedef struct mdb_ctf_id {
52 	void *_opaque[2];
53 } mdb_ctf_id_t;
54 
55 typedef struct mdb_ctf_funcinfo {
56 	mdb_ctf_id_t mtf_return;	/* function return type */
57 	uint_t mtf_argc;		/* number of arguments */
58 	uint_t mtf_flags;		/* function attributes (see libctf.h) */
59 	uint_t mtf_symidx;		/* for ctf_func_args */
60 } mdb_ctf_funcinfo_t;
61 
62 typedef struct mdb_ctf_arinfo {
63 	mdb_ctf_id_t mta_contents;	/* type of array conents */
64 	mdb_ctf_id_t mta_index;		/* type of array index */
65 	uint_t mta_nelems;		/* number of elements */
66 } mdb_ctf_arinfo_t;
67 
68 typedef int mdb_ctf_visit_f(const char *, mdb_ctf_id_t, ulong_t, int, void *);
69 typedef int mdb_ctf_member_f(const char *, mdb_ctf_id_t, ulong_t, void *);
70 typedef int mdb_ctf_enum_f(const char *, int, void *);
71 typedef int mdb_ctf_type_f(mdb_ctf_id_t, void *);
72 
73 extern int mdb_ctf_enabled_by_object(const char *);
74 
75 extern int mdb_ctf_lookup_by_name(const char *, mdb_ctf_id_t *);
76 extern int mdb_ctf_lookup_by_addr(uintptr_t, mdb_ctf_id_t *);
77 
78 extern int mdb_ctf_module_lookup(const char *, mdb_ctf_id_t *);
79 
80 extern int mdb_ctf_func_info(const GElf_Sym *, const mdb_syminfo_t *,
81     mdb_ctf_funcinfo_t *);
82 extern int mdb_ctf_func_args(const mdb_ctf_funcinfo_t *, uint_t,
83     mdb_ctf_id_t *);
84 
85 extern void mdb_ctf_type_invalidate(mdb_ctf_id_t *);
86 extern int mdb_ctf_type_valid(mdb_ctf_id_t);
87 extern int mdb_ctf_type_cmp(mdb_ctf_id_t, mdb_ctf_id_t);
88 
89 extern int mdb_ctf_type_resolve(mdb_ctf_id_t, mdb_ctf_id_t *);
90 extern char *mdb_ctf_type_name(mdb_ctf_id_t, char *, size_t);
91 extern ssize_t mdb_ctf_type_size(mdb_ctf_id_t);
92 extern int mdb_ctf_type_kind(mdb_ctf_id_t);
93 extern int mdb_ctf_type_reference(const mdb_ctf_id_t, mdb_ctf_id_t *);
94 extern int mdb_ctf_type_encoding(mdb_ctf_id_t, ctf_encoding_t *);
95 extern int mdb_ctf_type_visit(mdb_ctf_id_t, mdb_ctf_visit_f *, void *);
96 
97 extern int mdb_ctf_array_info(mdb_ctf_id_t, mdb_ctf_arinfo_t *);
98 extern const char *mdb_ctf_enum_name(mdb_ctf_id_t, int);
99 
100 extern int mdb_ctf_member_iter(mdb_ctf_id_t, mdb_ctf_member_f *, void *);
101 extern int mdb_ctf_enum_iter(mdb_ctf_id_t, mdb_ctf_enum_f *, void *);
102 extern int mdb_ctf_type_iter(const char *, mdb_ctf_type_f *, void *);
103 
104 /* utility stuff */
105 extern ctf_id_t mdb_ctf_type_id(mdb_ctf_id_t);
106 extern ctf_file_t *mdb_ctf_type_file(mdb_ctf_id_t);
107 
108 
109 extern int mdb_ctf_member_info(mdb_ctf_id_t, const char *,
110     ulong_t *, mdb_ctf_id_t *);
111 extern int mdb_ctf_offsetof(mdb_ctf_id_t, const char *, ulong_t *);
112 extern int mdb_ctf_num_members(mdb_ctf_id_t);
113 
114 extern ssize_t mdb_ctf_offset_to_name(mdb_ctf_id_t, ulong_t, char *, size_t,
115     int, mdb_ctf_id_t *, ulong_t *);
116 
117 #define	MDB_CTF_VREAD_IGNORE_GROW	0x01
118 #define	MDB_CTF_VREAD_IGNORE_ABSENT	0x02
119 #define	MDB_CTF_VREAD_IGNORE_UNIONS	0x04
120 
121 #define	MDB_CTF_VREAD_IGNORE_ALL	0x07
122 
123 extern int mdb_ctf_vread(void *, const char *, uintptr_t, uint_t);
124 extern int mdb_ctf_readsym(void *, const char *, const char *, uint_t);
125 
126 #ifdef _MDB
127 
128 extern ctf_file_t *mdb_ctf_open(const char *, int *);		/* Internal */
129 extern ctf_file_t *mdb_ctf_bufopen(const void *, size_t,	/* Internal */
130     const void *, Shdr *, const void *, Shdr *, int *);
131 extern void mdb_ctf_close(ctf_file_t *fp);			/* Internal */
132 
133 #endif
134 
135 #ifdef	__cplusplus
136 }
137 #endif
138 
139 #endif	/* _MDB_CTF_H */
140