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