xref: /titanic_41/usr/src/cmd/mdb/common/mdb/mdb_module.h (revision 3b6e0a598869dfc84461624e8699bf51738f68b3)
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 /*
28  * Copyright (c) 2012 by Delphix. All rights reserved.
29  * Copyright (c) 2012 Joyent, Inc. All rights reserved.
30  */
31 
32 #ifndef	_MDB_MODULE_H
33 #define	_MDB_MODULE_H
34 
35 #include <mdb/mdb_argvec.h>
36 #include <mdb/mdb_nv.h>
37 #include <mdb/mdb_modapi.h>
38 #include <mdb/mdb_target.h>
39 #include <mdb/mdb_disasm.h>
40 
41 #include <libctf.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 #ifdef _MDB
48 
49 struct mdb_callb;
50 
51 typedef struct mdb_module {
52 	mdb_nv_t mod_dcmds;		/* Module dcmds hash */
53 	mdb_nv_t mod_walkers;		/* Module walkers hash */
54 	const char *mod_name;		/* Module name */
55 	void *mod_hdl;			/* Module object handle */
56 	mdb_modinfo_t *mod_info;	/* Module information */
57 	const mdb_modinfo_t *(*mod_init)(void);	/* Module load callback */
58 	void (*mod_fini)(void);		/* Module unload callback */
59 	mdb_tgt_ctor_f *mod_tgt_ctor;	/* Module target constructor */
60 	mdb_dis_ctor_f *mod_dis_ctor;	/* Module disassembler constructor */
61 	struct mdb_module *mod_prev;	/* Previous module on dependency list */
62 	struct mdb_module *mod_next;	/* Next module on dependency list */
63 	ctf_file_t *mod_ctfp;		/* CTF container for this module */
64 	struct mdb_callb *mod_cb;	/* First callback for this module */
65 } mdb_module_t;
66 
67 typedef struct mdb_idcmd {
68 	const char *idc_name;		/* Backpointer to variable name */
69 	const char *idc_usage;		/* Usage message */
70 	const char *idc_descr;		/* Description */
71 	mdb_dcmd_f *idc_funcp;		/* Command function */
72 	void (*idc_help)(void);		/* Help function */
73 	mdb_dcmd_tab_f *idc_tabp;	/* Tab completion pointer */
74 	mdb_module_t *idc_modp;		/* Backpointer to module */
75 	mdb_var_t *idc_var;		/* Backpointer to global variable */
76 } mdb_idcmd_t;
77 
78 typedef struct mdb_iwalker {
79 	const char *iwlk_name;		/* Walk type name */
80 	char *iwlk_descr;		/* Walk description */
81 	int (*iwlk_init)(struct mdb_walk_state *);	/* Walk constructor */
82 	int (*iwlk_step)(struct mdb_walk_state *);	/* Walk iterator */
83 	void (*iwlk_fini)(struct mdb_walk_state *);	/* Walk destructor */
84 	void *iwlk_init_arg;		/* Walk constructor argument */
85 	mdb_module_t *iwlk_modp;	/* Backpointer to module */
86 	mdb_var_t *iwlk_var;		/* Backpointer to global variable */
87 } mdb_iwalker_t;
88 
89 #define	MDB_MOD_LOCAL		0x00	/* Load module RTLD_LOCAL */
90 #define	MDB_MOD_GLOBAL		0x01	/* Load module RTLD_GLOBAL */
91 #define	MDB_MOD_SILENT		0x02	/* Remain silent if no module found */
92 #define	MDB_MOD_FORCE		0x04	/* Forcibly interpose module defs */
93 #define	MDB_MOD_BUILTIN		0x08	/* Module is compiled into debugger */
94 #define	MDB_MOD_DEFER		0x10	/* Defer load/unload (kmdb only) */
95 
96 extern int mdb_module_load(const char *, int);
97 extern mdb_module_t *mdb_module_load_builtin(const char *);
98 extern void mdb_module_load_all(int);
99 
100 extern int mdb_module_unload(const char *, int);
101 extern void mdb_module_unload_all(int);
102 extern int mdb_module_unload_common(const char *);
103 
104 extern int mdb_module_add_dcmd(mdb_module_t *, const mdb_dcmd_t *, int);
105 extern int mdb_module_remove_dcmd(mdb_module_t *, const char *);
106 
107 extern int mdb_module_add_walker(mdb_module_t *, const mdb_walker_t *, int);
108 extern int mdb_module_remove_walker(mdb_module_t *, const char *);
109 
110 extern int mdb_module_create(const char *, const char *, int, mdb_module_t **);
111 
112 extern int mdb_module_validate_name(const char *, const char **);
113 
114 #endif	/* _MDB */
115 
116 #ifdef	__cplusplus
117 }
118 #endif
119 
120 #endif	/* _MDB_MODULE_H */
121