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 /*
  23  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 #ifndef _MDB_FINDSTACK_H
  27 #define _MDB_FINDSTACK_H
  28 
  29 #include <mdb/mdb_modapi.h>
  30 #include <sys/param.h>
  31 
  32 #ifdef  __cplusplus
  33 extern "C" {
  34 #endif
  35 
  36 typedef struct findstack_info {
  37         uintptr_t       *fsi_stack;     /* place to record frames */
  38         uintptr_t       fsi_sp;         /* stack pointer */
  39         uintptr_t       fsi_pc;         /* pc */
  40         uintptr_t       fsi_sobj_ops;   /* sobj_ops */
  41         uint_t          fsi_tstate;     /* t_state */
  42         uchar_t         fsi_depth;      /* stack depth */
  43         uchar_t         fsi_failed;     /* search failed */
  44         uchar_t         fsi_overflow;   /* stack was deeper than max_depth */
  45         uchar_t         fsi_panic;      /* thread called panic() */
  46         uchar_t         fsi_max_depth;  /* stack frames available */
  47 } findstack_info_t;
  48 
  49 #define FSI_FAIL_BADTHREAD      1
  50 #define FSI_FAIL_THREADCORRUPT  2
  51 #define FSI_FAIL_STACKNOTFOUND  3
  52 
  53 typedef struct stacks_module {
  54         char            sm_name[MAXPATHLEN]; /* name of module */
  55         uintptr_t       sm_text;        /* base address of text in module */
  56         size_t          sm_size;        /* size of text in module */
  57 } stacks_module_t;
  58 
  59 extern int findstack(uintptr_t, uint_t, int, const mdb_arg_t *);
  60 extern int findstack_debug(uintptr_t, uint_t, int, const mdb_arg_t *);
  61 
  62 /*
  63  * The following routines are implemented in findstack.c, shared across both
  64  * genunix and libc.
  65  */
  66 extern int stacks(uintptr_t, uint_t, int, const mdb_arg_t *);
  67 extern void stacks_cleanup(int);
  68 
  69 /*
  70  * The following routines are specific to their context (kernel vs. user-land)
  71  * and are therefore implemented in findstack_subr.c (of which each of genunix
  72  * and libc have their own copy).
  73  */
  74 extern void stacks_help(void);
  75 extern int stacks_findstack(uintptr_t, findstack_info_t *, uint_t);
  76 extern void stacks_findstack_cleanup();
  77 extern int stacks_module(stacks_module_t *);
  78 
  79 extern int findstack_debug_on;
  80 
  81 #define fs_dprintf(x)                                   \
  82         if (findstack_debug_on) {                       \
  83                 mdb_printf("findstack debug: ");        \
  84                 /*CSTYLED*/                             \
  85                 mdb_printf x ;                          \
  86         }
  87 
  88 #ifdef  __cplusplus
  89 }
  90 #endif
  91 
  92 #endif  /* _MDB_FINDSTACK_H */