summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/common/kmdb/kmdb_module.h
blob: 5b4576d4b742574f5fd3e8130182d54f6904419b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _KMDB_MODULE_H
#define	_KMDB_MODULE_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/modctl.h>
#include <sys/kobj.h>

#include <mdb/mdb_gelf.h>
#include <mdb/mdb_module.h>
#include <kmdb/kmdb_wr_impl.h>

#ifdef __cplusplus
extern "C" {
#endif

#define	KMDB_MC_STATE_LOADING	1
#define	KMDB_MC_STATE_LOADED	2
#define	KMDB_MC_STATE_UNLOADING	3

#define	KMDB_MC_FL_NOUNLOAD	0x1

/*
 * The mdb_module_t describes the runtime attributes of dmods - things that
 * matter after the dmod has been loaded.  kmdb needs to track information about
 * modules before they've been loaded, and while they're in the process of
 * being unloaded.  As such, a kmdb_modctl_t is created for each module when the
 * load is requested, and isn't destroyed until the module has completed
 * unloading.
 *
 * This description reflects the sequence of events that occur during the
 * successful loading and unloading of a dmod.
 *
 * 1. Debugger requests a dmod load.
 *
 *    A kmdb_modctl_t is allocated.  kmc_state is set to KMDB_MC_STATE_LOADING.
 *
 * 2. The driver reports the successful loading of the dmod.
 *
 *    kmc_state is set to KMDB_MC_STATE_LOADED, and an mdb_module_t is created
 *    by mdb_module_create.
 *
 * 3. Debugger requests a dmod unload.
 *
 *    The mdb_module_t is destroyed, and kmc_state is set to
 *    KMDB_MC_STATE_UNLOADING.
 *
 * 4. The driver reports the successful unloading of the dmod.
 *
 *    The kmdb_modctl_t is destroyed.
 */
typedef struct kmdb_modctl {
	mdb_module_t *kmc_mod;		/* common dmod state */
	struct modctl *kmc_modctl;	/* kernel's modctl for this dmod */
	int kmc_exported;		/* KOBJ_EXPORTED set when last seen? */
	char *kmc_modname;		/* name of this dmod */
	ushort_t kmc_loadmode;		/* MDB_MOD_* from load request */
	ushort_t kmc_flags;		/* KMDB_MC_FL_* (above) */
	int kmc_dlrefcnt;		/* Counts dlopens/dlcloses */
	int kmc_state;			/* KMDB_MC_STATE_* (above) */
	mdb_gelf_symtab_t *kmc_symtab;	/* This dmod's symbol table */
	GElf_Ehdr kmc_ehdr;		/* Copy of ehdr in gelf format */
} kmdb_modctl_t;

extern int kmdb_module_loaded(kmdb_wr_load_t *);
extern void kmdb_module_load_ack(kmdb_wr_load_t *);
extern void kmdb_module_load_all_ack(kmdb_wr_t *);
extern int kmdb_module_unloaded(kmdb_wr_unload_t *);
extern void kmdb_module_unload_ack(kmdb_wr_unload_t *);

extern void kmdb_module_path_set(const char **, size_t);
extern void kmdb_module_path_ack(kmdb_wr_path_t *);

extern int kmdb_module_lookup_by_addr(uintptr_t, uint_t, char *, size_t,
    GElf_Sym *, mdb_syminfo_t *);
extern int kmdb_module_lookup_by_name(const char *, const char *, GElf_Sym *,
    mdb_syminfo_t *);
extern ctf_file_t *kmdb_module_addr_to_ctf(uintptr_t);
extern ctf_file_t *kmdb_module_name_to_ctf(const char *);
extern int kmdb_module_symbol_iter(const char *, uint_t, mdb_tgt_sym_f *,
    void *);
extern void kmdb_module_sync(void);

#ifdef __cplusplus
}
#endif

#endif /* _KMDB_MODULE_H */