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