xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kmdb_module.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _KMDB_MODULE_H
28 #define	_KMDB_MODULE_H
29 
30 #include <sys/modctl.h>
31 #include <sys/kobj.h>
32 
33 #include <mdb/mdb_gelf.h>
34 #include <mdb/mdb_module.h>
35 #include <kmdb/kmdb_wr_impl.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define	KMDB_MC_STATE_LOADING	1
42 #define	KMDB_MC_STATE_LOADED	2
43 #define	KMDB_MC_STATE_UNLOADING	3
44 
45 #define	KMDB_MC_FL_NOUNLOAD	0x1
46 
47 /*
48  * The mdb_module_t describes the runtime attributes of dmods - things that
49  * matter after the dmod has been loaded.  kmdb needs to track information about
50  * modules before they've been loaded, and while they're in the process of
51  * being unloaded.  As such, a kmdb_modctl_t is created for each module when the
52  * load is requested, and isn't destroyed until the module has completed
53  * unloading.
54  *
55  * This description reflects the sequence of events that occur during the
56  * successful loading and unloading of a dmod.
57  *
58  * 1. Debugger requests a dmod load.
59  *
60  *    A kmdb_modctl_t is allocated.  kmc_state is set to KMDB_MC_STATE_LOADING.
61  *
62  * 2. The driver reports the successful loading of the dmod.
63  *
64  *    kmc_state is set to KMDB_MC_STATE_LOADED, and an mdb_module_t is created
65  *    by mdb_module_create.
66  *
67  * 3. Debugger requests a dmod unload.
68  *
69  *    The mdb_module_t is destroyed, and kmc_state is set to
70  *    KMDB_MC_STATE_UNLOADING.
71  *
72  * 4. The driver reports the successful unloading of the dmod.
73  *
74  *    The kmdb_modctl_t is destroyed.
75  */
76 typedef struct kmdb_modctl {
77 	mdb_module_t *kmc_mod;		/* common dmod state */
78 	struct modctl *kmc_modctl;	/* kernel's modctl for this dmod */
79 	int kmc_exported;		/* KOBJ_EXPORTED set when last seen? */
80 	char *kmc_modname;		/* name of this dmod */
81 	ushort_t kmc_loadmode;		/* MDB_MOD_* from load request */
82 	ushort_t kmc_flags;		/* KMDB_MC_FL_* (above) */
83 	int kmc_dlrefcnt;		/* Counts dlopens/dlcloses */
84 	int kmc_state;			/* KMDB_MC_STATE_* (above) */
85 	mdb_gelf_symtab_t *kmc_symtab;	/* This dmod's symbol table */
86 	GElf_Ehdr kmc_ehdr;		/* Copy of ehdr in gelf format */
87 } kmdb_modctl_t;
88 
89 extern int kmdb_module_loaded(kmdb_wr_load_t *);
90 extern void kmdb_module_load_ack(kmdb_wr_load_t *);
91 extern void kmdb_module_load_all_ack(kmdb_wr_t *);
92 extern int kmdb_module_unloaded(kmdb_wr_unload_t *);
93 extern void kmdb_module_unload_ack(kmdb_wr_unload_t *);
94 
95 extern void kmdb_module_path_set(const char **, size_t);
96 extern void kmdb_module_path_ack(kmdb_wr_path_t *);
97 
98 extern int kmdb_module_lookup_by_addr(uintptr_t, uint_t, char *, size_t,
99     GElf_Sym *, mdb_syminfo_t *);
100 extern int kmdb_module_lookup_by_name(const char *, const char *, GElf_Sym *,
101     mdb_syminfo_t *);
102 extern ctf_file_t *kmdb_module_addr_to_ctf(uintptr_t);
103 extern ctf_file_t *kmdb_module_name_to_ctf(const char *);
104 extern int kmdb_module_symbol_iter(const char *, uint_t, mdb_tgt_sym_f *,
105     void *);
106 extern void kmdb_module_sync(void);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* _KMDB_MODULE_H */
113