xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_ks.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_MDB_KS_H
28 #define	_MDB_KS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/int_types.h>
34 #include <sys/stream.h>
35 #include <sys/vnode.h>
36 #include <sys/proc.h>
37 #include <sys/dumphdr.h>
38 #include <sys/auxv.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * MDB Kernel Support Interfaces:
46  *
47  * Debugger modules for kernel crash dumps can make use of these utility
48  * functions.  This module also provides support for <mdb/mdb_param.h>.
49  */
50 
51 extern int mdb_vnode2path(uintptr_t, char *, size_t);
52 
53 extern uintptr_t mdb_vnode2page(uintptr_t, uintptr_t);
54 
55 extern uintptr_t mdb_pid2proc(pid_t, proc_t *);
56 extern char mdb_vtype2chr(vtype_t, mode_t);
57 extern uintptr_t mdb_addr2modctl(uintptr_t);
58 
59 extern ssize_t mdb_read_refstr(uintptr_t, char *, size_t);
60 
61 extern int mdb_name_to_major(const char *, major_t *);
62 extern const char *mdb_major_to_name(major_t);
63 
64 extern int mdb_devinfo2driver(uintptr_t, char *, size_t);
65 extern int mdb_devinfo2statep(uintptr_t, char *, uintptr_t *);
66 
67 /*
68  * Returns a pointer to the top of the soft state struct for the instance
69  * specified, given the address of the global soft state pointer and size
70  * of the struct.  Also fills in the buffer pointed to by state_buf_p (if
71  * non-NULL) with the contents of the state struct.
72  */
73 extern int mdb_get_soft_state_byaddr(uintptr_t, uint_t, uintptr_t *, void *,
74     size_t);
75 
76 /*
77  * Returns a pointer to the top of the soft state struct for the instance
78  * specified, given the name of the global soft state pointer and size
79  * of the struct.  Also fills in the buffer pointed to by state_buf_p (if
80  * non-NULL) with the contents of the state struct.
81  */
82 extern int mdb_get_soft_state_byname(char *, uint_t, uintptr_t *, void *,
83     size_t);
84 
85 /*
86  * Returns the pathname from the root devinfo node to the dip supplied.
87  * Just like ddi_pathname in sunddi.c.
88  */
89 extern char *mdb_ddi_pathname(uintptr_t, char *, size_t);
90 
91 
92 /*
93  * MDB Kernel STREAMS Subsystem:
94  *
95  * Debugger modules such as ip can provide facilities for decoding private
96  * q_ptr data for STREAMS queues using this mechanism.  The module first
97  * registers a set of functions which may be invoked when q->q_qinfo matches
98  * a given qinit address (such as ip`winit).  The q_info function provides
99  * a way for the module to return an information string about the particular
100  * queue.  The q_rnext and q_wnext functions provide a way for the generic
101  * queue walker to ask how to proceed deeper in the STREAM when q_next is
102  * NULL.  This allows ip, for example, to provide access to the link-layer
103  * queues beneath the ip-client queue.
104  */
105 
106 typedef struct mdb_qops {
107 	void (*q_info)(const queue_t *, char *, size_t);
108 	uintptr_t (*q_rnext)(const queue_t *);
109 	uintptr_t (*q_wnext)(const queue_t *);
110 } mdb_qops_t;
111 
112 extern void mdb_qops_install(const mdb_qops_t *, uintptr_t);
113 extern void mdb_qops_remove(const mdb_qops_t *, uintptr_t);
114 
115 extern char *mdb_qname(const queue_t *, char *, size_t);
116 extern void mdb_qinfo(const queue_t *, char *, size_t);
117 
118 extern uintptr_t mdb_qrnext(const queue_t *);
119 extern uintptr_t mdb_qwnext(const queue_t *);
120 
121 /*
122  * These functions, provided by mdb_ks, may be used to fill in the q_rnext
123  * and q_wnext members of mdb_qops_t, in the case where the client wishes
124  * to simply return q->q_next:
125  */
126 extern uintptr_t mdb_qrnext_default(const queue_t *);
127 extern uintptr_t mdb_qwnext_default(const queue_t *);
128 
129 /*
130  * Target-specific interfaces
131  *
132  * The existence and accessibility of the functions listed below is relied upon
133  * by the indicated targets.  The targets look up and invoke these functions in
134  * mdb_ks so that dependencies on the current kernel implementation are
135  * isolated in mdb_ks.
136  */
137 
138 /*
139  * MDB KPROC Target Interface:
140  * (user processes from kernel crash dump)
141  */
142 
143 struct mdb_map; /* Private between kproc and ks */
144 
145 extern int mdb_kproc_asiter(uintptr_t,
146     void (*)(const struct mdb_map *, void *), void *);
147 extern int mdb_kproc_auxv(uintptr_t, auxv_t *);
148 extern uintptr_t mdb_kproc_as(uintptr_t);
149 extern pid_t mdb_kproc_pid(uintptr_t);
150 
151 
152 /*
153  * MDB KVM Target Interface:
154  * (kernel dump)
155  */
156 
157 extern void mdb_dump_print_content(dumphdr_t *, pid_t);
158 extern int mdb_dump_find_curproc(void);
159 
160 /*
161  * KMDB Target Interface:
162  */
163 #ifdef _KMDB
164 extern const mdb_modinfo_t *mdb_ks_init(void);
165 #endif
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif	/* _MDB_KS_H */
172