xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_ks.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_KS_H
27 #define	_MDB_KS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/int_types.h>
33 #include <sys/stream.h>
34 #include <sys/vnode.h>
35 #include <sys/proc.h>
36 #include <sys/dumphdr.h>
37 #include <sys/auxv.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * MDB Kernel Support Interfaces:
45  *
46  * Debugger modules for kernel crash dumps can make use of these utility
47  * functions.  This module also provides support for <mdb/mdb_param.h>.
48  */
49 
50 extern int mdb_vnode2path(uintptr_t, char *, size_t);
51 
52 extern uintptr_t mdb_vnode2page(uintptr_t, uintptr_t);
53 
54 extern uintptr_t mdb_pid2proc(pid_t, proc_t *);
55 extern char mdb_vtype2chr(vtype_t, mode_t);
56 extern uintptr_t mdb_addr2modctl(uintptr_t);
57 
58 extern ssize_t mdb_read_refstr(uintptr_t, char *, size_t);
59 
60 extern int mdb_name_to_major(const char *, major_t *);
61 extern const char *mdb_major_to_name(major_t);
62 
63 extern int mdb_devinfo2driver(uintptr_t, char *, size_t);
64 extern int mdb_devinfo2statep(uintptr_t, char *, uintptr_t *);
65 
66 extern int mdb_cpu2cpuid(uintptr_t);
67 
68 extern int mdb_cpuset_find(uintptr_t);
69 
70 /*
71  * Returns a pointer to the top of the soft state struct for the instance
72  * specified, given the address of the global soft state pointer and size
73  * of the struct.  Also fills in the buffer pointed to by state_buf_p (if
74  * non-NULL) with the contents of the state struct.
75  */
76 extern int mdb_get_soft_state_byaddr(uintptr_t, uint_t, uintptr_t *, void *,
77     size_t);
78 
79 /*
80  * Returns a pointer to the top of the soft state struct for the instance
81  * specified, given the name of the global soft state pointer and size
82  * of the struct.  Also fills in the buffer pointed to by state_buf_p (if
83  * non-NULL) with the contents of the state struct.
84  */
85 extern int mdb_get_soft_state_byname(char *, uint_t, uintptr_t *, void *,
86     size_t);
87 
88 /*
89  * Returns the pathname from the root devinfo node to the dip supplied.
90  * Just like ddi_pathname in sunddi.c.
91  */
92 extern char *mdb_ddi_pathname(uintptr_t, char *, size_t);
93 
94 
95 /*
96  * MDB Kernel STREAMS Subsystem:
97  *
98  * Debugger modules such as ip can provide facilities for decoding private
99  * q_ptr data for STREAMS queues using this mechanism.  The module first
100  * registers a set of functions which may be invoked when q->q_qinfo matches
101  * a given qinit address (such as ip`winit).  The q_info function provides
102  * a way for the module to return an information string about the particular
103  * queue.  The q_rnext and q_wnext functions provide a way for the generic
104  * queue walker to ask how to proceed deeper in the STREAM when q_next is
105  * NULL.  This allows ip, for example, to provide access to the link-layer
106  * queues beneath the ip-client queue.
107  */
108 
109 typedef struct mdb_qops {
110 	void (*q_info)(const queue_t *, char *, size_t);
111 	uintptr_t (*q_rnext)(const queue_t *);
112 	uintptr_t (*q_wnext)(const queue_t *);
113 } mdb_qops_t;
114 
115 extern void mdb_qops_install(const mdb_qops_t *, uintptr_t);
116 extern void mdb_qops_remove(const mdb_qops_t *, uintptr_t);
117 
118 extern char *mdb_qname(const queue_t *, char *, size_t);
119 extern void mdb_qinfo(const queue_t *, char *, size_t);
120 
121 extern uintptr_t mdb_qrnext(const queue_t *);
122 extern uintptr_t mdb_qwnext(const queue_t *);
123 
124 /*
125  * These functions, provided by mdb_ks, may be used to fill in the q_rnext
126  * and q_wnext members of mdb_qops_t, in the case where the client wishes
127  * to simply return q->q_next:
128  */
129 extern uintptr_t mdb_qrnext_default(const queue_t *);
130 extern uintptr_t mdb_qwnext_default(const queue_t *);
131 
132 extern int mdb_mblk_count(const mblk_t *);
133 
134 /* DLPI primitive to string; returns NULL for unknown primitives */
135 extern const char *mdb_dlpi_prim(int);
136 
137 /* Generic function for working with MAC (network layer 2) addresses. */
138 extern void mdb_mac_addr(const uint8_t *, size_t, char *, size_t);
139 
140 /*
141  * Target-specific interfaces
142  *
143  * The existence and accessibility of the functions listed below is relied upon
144  * by the indicated targets.  The targets look up and invoke these functions in
145  * mdb_ks so that dependencies on the current kernel implementation are
146  * isolated in mdb_ks.
147  */
148 
149 /*
150  * MDB KPROC Target Interface:
151  * (user processes from kernel crash dump)
152  */
153 
154 struct mdb_map; /* Private between kproc and ks */
155 
156 extern int mdb_kproc_asiter(uintptr_t,
157     void (*)(const struct mdb_map *, void *), void *);
158 extern int mdb_kproc_auxv(uintptr_t, auxv_t *);
159 extern uintptr_t mdb_kproc_as(uintptr_t);
160 extern pid_t mdb_kproc_pid(uintptr_t);
161 
162 
163 /*
164  * MDB KVM Target Interface:
165  * (kernel dump)
166  */
167 
168 extern void mdb_dump_print_content(dumphdr_t *, pid_t);
169 extern int mdb_dump_find_curproc(void);
170 
171 /*
172  * KMDB Target Interface:
173  */
174 #ifdef _KMDB
175 extern const mdb_modinfo_t *mdb_ks_init(void);
176 #endif
177 
178 #ifdef	__cplusplus
179 }
180 #endif
181 
182 #endif	/* _MDB_KS_H */
183