Home | History | Annotate | Download | only in mdb
      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_vnode2page(uintptr_t, uintptr_t);
     51 
     52 extern uintptr_t mdb_pid2proc(pid_t, proc_t *);
     53 extern char mdb_vtype2chr(vtype_t, mode_t);
     54 extern uintptr_t mdb_addr2modctl(uintptr_t);
     55 
     56 extern ssize_t mdb_read_refstr(uintptr_t, char *, size_t);
     57 
     58 extern int mdb_name_to_major(const char *, major_t *);
     59 extern const char *mdb_major_to_name(major_t);
     60 
     61 extern int mdb_devinfo2driver(uintptr_t, char *, size_t);
     62 extern int mdb_devinfo2statep(uintptr_t, char *, uintptr_t *);
     63 
     64 extern int mdb_cpu2cpuid(uintptr_t);
     65 
     66 extern int mdb_cpuset_find(uintptr_t);
     67 
     68 extern hrtime_t mdb_gethrtime(void);
     69 extern int64_t mdb_get_lbolt(void);
     70 
     71 /*
     72  * Returns a pointer to the top of the soft state struct for the instance
     73  * specified, given the address of the global soft state pointer and size
     74  * of the struct.  Also fills in the buffer pointed to by state_buf_p (if
     75  * non-NULL) with the contents of the state struct.
     76  */
     77 extern int mdb_get_soft_state_byaddr(uintptr_t, uint_t, uintptr_t *, void *,
     78     size_t);
     79 
     80 /*
     81  * Returns a pointer to the top of the soft state struct for the instance
     82  * specified, given the name of the global soft state pointer and size
     83  * of the struct.  Also fills in the buffer pointed to by state_buf_p (if
     84  * non-NULL) with the contents of the state struct.
     85  */
     86 extern int mdb_get_soft_state_byname(char *, uint_t, uintptr_t *, void *,
     87     size_t);
     88 
     89 /*
     90  * Returns the pathname from the root devinfo node to the dip supplied.
     91  * Just like ddi_pathname in sunddi.c.
     92  */
     93 extern char *mdb_ddi_pathname(uintptr_t, char *, size_t);
     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