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