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