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