xref: /illumos-gate/usr/src/cmd/mdb/common/modules/genunix/findstack.h (revision 4f364e7c95ee7fd9d5bbeddc1940e92405bb0e72)
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_NOTINMEMORY	2
51 #define	FSI_FAIL_THREADCORRUPT	3
52 #define	FSI_FAIL_STACKNOTFOUND	4
53 
54 typedef struct stacks_module {
55 	char		sm_name[MAXPATHLEN]; /* name of module */
56 	uintptr_t	sm_text;	/* base address of text in module */
57 	size_t		sm_size;	/* size of text in module */
58 } stacks_module_t;
59 
60 extern int findstack(uintptr_t, uint_t, int, const mdb_arg_t *);
61 extern int findstack_debug(uintptr_t, uint_t, int, const mdb_arg_t *);
62 
63 /*
64  * The following routines are implemented in findstack.c, shared across both
65  * genunix and libc.
66  */
67 extern int stacks(uintptr_t, uint_t, int, const mdb_arg_t *);
68 extern void stacks_cleanup(int);
69 
70 /*
71  * The following routines are specific to their context (kernel vs. user-land)
72  * and are therefore implemented in findstack_subr.c (of which each of genunix
73  * and libc have their own copy).
74  */
75 extern void stacks_help(void);
76 extern int stacks_findstack(uintptr_t, findstack_info_t *, uint_t);
77 extern void stacks_findstack_cleanup();
78 extern int stacks_module(stacks_module_t *);
79 
80 extern int findstack_debug_on;
81 
82 #define	fs_dprintf(x)					\
83 	if (findstack_debug_on) {			\
84 		mdb_printf("findstack debug: ");	\
85 		/*CSTYLED*/				\
86 		mdb_printf x ;				\
87 	}
88 
89 #ifdef	__cplusplus
90 }
91 #endif
92 
93 #endif	/* _MDB_FINDSTACK_H */
94