xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_kvm.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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_MDB_KVM_H
27 #define	_MDB_KVM_H
28 
29 #include <sys/types.h>
30 #include <sys/machelf.h>
31 #include <sys/dumphdr.h>
32 #include <libctf.h>
33 #include <kvm.h>
34 
35 #include <mdb/mdb_target.h>
36 #include <mdb/mdb_list.h>
37 #include <mdb/mdb_gelf.h>
38 #include <mdb/mdb_kb.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 #ifdef _MDB
45 
46 typedef struct kt_module {
47 	mdb_list_t km_list;		/* List forward/back pointers */
48 	char *km_name;			/* Module name */
49 	void *km_data;			/* Data buffer (module->symspace) */
50 	size_t km_datasz;		/* Size of km_data in bytes */
51 	void *km_symbuf;		/* Base of symbol table in km_data */
52 	char *km_strtab;		/* Base of string table in km_data */
53 	mdb_gelf_symtab_t *km_symtab;	/* Symbol table for module */
54 	uintptr_t km_symspace_va;	/* Kernel VA of krtld symspace */
55 	uintptr_t km_symtab_va;		/* Kernel VA of krtld symtab */
56 	uintptr_t km_strtab_va;		/* Kernel VA of krtld strtab */
57 	Shdr km_symtab_hdr;		/* Native .symtab section header */
58 	Shdr km_strtab_hdr;		/* Native .strtab section header */
59 	uintptr_t km_text_va;		/* Kernel VA of start of module text */
60 	size_t km_text_size;		/* Size of module text */
61 	uintptr_t km_data_va;		/* Kernel VA of start of module data */
62 	size_t km_data_size;		/* Size of module data */
63 	uintptr_t km_bss_va;		/* Kernel VA of start of module BSS */
64 	size_t km_bss_size;		/* Size of module BSS */
65 	uintptr_t km_ctf_va;		/* Kernel VA of CTF data */
66 	size_t km_ctf_size;		/* Size of CTF data */
67 	void *km_ctf_buf;		/* CTF data for this module */
68 	ctf_file_t *km_ctfp;		/* CTF container for this module */
69 } kt_module_t;
70 
71 typedef struct kt_data {
72 	mdb_kb_ops_t *k_kb_ops;		/* KVM backend ops */
73 	void (*k_dump_print_content)();	/* mdb_ks dump_print_content routine */
74 	int (*k_dump_find_curproc)();	/* mdb_ks dump_find_curproc routine */
75 	char *k_symfile;		/* Symbol table pathname */
76 	char *k_kvmfile;		/* Core file pathname */
77 	int k_xpv_domu;			/* Hypervisor domain dump? */
78 	const char *k_rtld_name;	/* module containing krtld */
79 	mdb_map_t k_map;		/* Persistant map for callers */
80 	void *k_cookie;			/* Cookie for libkvm routines */
81 	struct as *k_as;		/* Kernel VA of kas struct */
82 	mdb_io_t *k_fio;		/* File i/o backend */
83 	mdb_gelf_file_t *k_file;	/* ELF file object */
84 	mdb_gelf_symtab_t *k_symtab;	/* Standard symbol table */
85 	mdb_gelf_symtab_t *k_dynsym;	/* Dynamic symbol table */
86 	mdb_nv_t k_modules;		/* Hash table of modules */
87 	mdb_list_t k_modlist;		/* List of modules in load order */
88 	char k_platform[MAXNAMELEN];	/* Platform string */
89 	const mdb_tgt_regdesc_t *k_rds;	/* Register description table */
90 	mdb_tgt_gregset_t *k_regs;	/* Representative register set */
91 	size_t k_regsize;		/* Size of k_regs in bytes */
92 	mdb_tgt_tid_t k_tid;		/* Pointer to representative thread */
93 	mdb_dcmd_f *k_dcmd_regs;	/* Dcmd to print registers */
94 	mdb_dcmd_f *k_dcmd_stack;	/* Dcmd to print stack trace */
95 	mdb_dcmd_f *k_dcmd_stackv;	/* Dcmd to print verbose stack trace */
96 	mdb_dcmd_f *k_dcmd_stackr;	/* Dcmd to print stack trace and regs */
97 	mdb_dcmd_f *k_dcmd_cpustack;	/* Dcmd to print CPU stack trace */
98 	mdb_dcmd_f *k_dcmd_cpuregs;	/* Dcmd to print CPU registers */
99 	GElf_Sym k_intr_sym;		/* Kernel locore cmnint symbol */
100 	GElf_Sym k_trap_sym;		/* Kernel locore cmntrap symbol */
101 	struct dumphdr *k_dumphdr;	/* Dump header for post-mortem */
102 	pid_t k_dumpcontent;		/* The pid(s) (if any) in the dump */
103 	int k_activated;		/* Set if kt_activate called */
104 	int k_ctfvalid;			/* Set if kernel has a CTF arena */
105 } kt_data_t;
106 
107 /* values for k_dumpcontent */
108 #define	KT_DUMPCONTENT_KERNEL	0
109 #define	KT_DUMPCONTENT_INVALID	-1
110 #define	KT_DUMPCONTENT_ALL	-2
111 
112 extern int kt_setflags(mdb_tgt_t *, int);
113 extern int kt_setcontext(mdb_tgt_t *, void *);
114 
115 extern void kt_activate(mdb_tgt_t *);
116 extern void kt_deactivate(mdb_tgt_t *);
117 extern void kt_destroy(mdb_tgt_t *);
118 
119 extern const char *kt_name(mdb_tgt_t *);
120 extern const char *kt_platform(mdb_tgt_t *);
121 extern int kt_uname(mdb_tgt_t *, struct utsname *);
122 extern int kt_dmodel(mdb_tgt_t *);
123 
124 extern ssize_t kt_aread(mdb_tgt_t *, mdb_tgt_as_t,
125     void *, size_t, mdb_tgt_addr_t);
126 
127 extern ssize_t kt_awrite(mdb_tgt_t *, mdb_tgt_as_t,
128     const void *, size_t, mdb_tgt_addr_t);
129 
130 extern ssize_t kt_vread(mdb_tgt_t *, void *, size_t, uintptr_t);
131 extern ssize_t kt_vwrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
132 extern ssize_t kt_pread(mdb_tgt_t *, void *, size_t, physaddr_t);
133 extern ssize_t kt_pwrite(mdb_tgt_t *, const void *, size_t, physaddr_t);
134 extern ssize_t kt_fread(mdb_tgt_t *, void *, size_t, uintptr_t);
135 extern ssize_t kt_fwrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
136 
137 extern int kt_vtop(mdb_tgt_t *, mdb_tgt_as_t, uintptr_t, physaddr_t *);
138 
139 extern int kt_lookup_by_name(mdb_tgt_t *, const char *,
140     const char *, GElf_Sym *, mdb_syminfo_t *);
141 
142 extern int kt_lookup_by_addr(mdb_tgt_t *, uintptr_t,
143     uint_t, char *, size_t, GElf_Sym *, mdb_syminfo_t *);
144 
145 extern int kt_symbol_iter(mdb_tgt_t *, const char *, uint_t,
146     uint_t, mdb_tgt_sym_f *, void *);
147 
148 extern int kt_mapping_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *);
149 extern int kt_object_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *);
150 
151 extern const mdb_map_t *kt_addr_to_map(mdb_tgt_t *, uintptr_t);
152 extern const mdb_map_t *kt_name_to_map(mdb_tgt_t *, const char *);
153 
154 extern struct ctf_file *kt_addr_to_ctf(mdb_tgt_t *, uintptr_t);
155 extern struct ctf_file *kt_name_to_ctf(mdb_tgt_t *, const char *);
156 
157 extern int kt_status(mdb_tgt_t *, mdb_tgt_status_t *);
158 
159 #ifdef __sparc
160 extern void kt_sparcv9_init(mdb_tgt_t *);
161 extern void kt_sparcv7_init(mdb_tgt_t *);
162 #else	/* __sparc */
163 extern void kt_ia32_init(mdb_tgt_t *);
164 extern void kt_amd64_init(mdb_tgt_t *);
165 #endif	/* __sparc */
166 
167 typedef int (*mdb_name_lookup_fcn_t)(const char *, GElf_Sym *);
168 typedef int (*mdb_addr_lookup_fcn_t)(uintptr_t, int, char *, size_t,
169     GElf_Sym *);
170 extern void mdb_kvm_add_name_lookup(mdb_name_lookup_fcn_t);
171 extern void mdb_kvm_add_addr_lookup(mdb_addr_lookup_fcn_t);
172 
173 #endif	/* _MDB */
174 
175 #ifdef	__cplusplus
176 }
177 #endif
178 
179 #endif	/* _MDB_KVM_H */
180