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