xref: /onnv-gate/usr/src/cmd/mdb/common/modules/genunix/findstack.h (revision 12902:3bb859a7330c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
58721SJonathan.Adams@Sun.COM  * Common Development and Distribution License (the "License").
68721SJonathan.Adams@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*12902SBryan.Cantrill@Sun.COM 
220Sstevel@tonic-gate /*
23*12902SBryan.Cantrill@Sun.COM  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_MDB_FINDSTACK_H
270Sstevel@tonic-gate #define	_MDB_FINDSTACK_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
30*12902SBryan.Cantrill@Sun.COM #include <sys/param.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
36*12902SBryan.Cantrill@Sun.COM typedef struct findstack_info {
37*12902SBryan.Cantrill@Sun.COM 	uintptr_t	*fsi_stack;	/* place to record frames */
38*12902SBryan.Cantrill@Sun.COM 	uintptr_t	fsi_sp;		/* stack pointer */
39*12902SBryan.Cantrill@Sun.COM 	uintptr_t	fsi_pc;		/* pc */
40*12902SBryan.Cantrill@Sun.COM 	uintptr_t	fsi_sobj_ops;	/* sobj_ops */
41*12902SBryan.Cantrill@Sun.COM 	uint_t		fsi_tstate;	/* t_state */
42*12902SBryan.Cantrill@Sun.COM 	uchar_t		fsi_depth;	/* stack depth */
43*12902SBryan.Cantrill@Sun.COM 	uchar_t		fsi_failed;	/* search failed */
44*12902SBryan.Cantrill@Sun.COM 	uchar_t		fsi_overflow;	/* stack was deeper than max_depth */
45*12902SBryan.Cantrill@Sun.COM 	uchar_t		fsi_panic;	/* thread called panic() */
46*12902SBryan.Cantrill@Sun.COM 	uchar_t		fsi_max_depth;	/* stack frames available */
47*12902SBryan.Cantrill@Sun.COM } findstack_info_t;
48*12902SBryan.Cantrill@Sun.COM 
49*12902SBryan.Cantrill@Sun.COM #define	FSI_FAIL_BADTHREAD	1
50*12902SBryan.Cantrill@Sun.COM #define	FSI_FAIL_NOTINMEMORY	2
51*12902SBryan.Cantrill@Sun.COM #define	FSI_FAIL_THREADCORRUPT	3
52*12902SBryan.Cantrill@Sun.COM #define	FSI_FAIL_STACKNOTFOUND	4
53*12902SBryan.Cantrill@Sun.COM 
54*12902SBryan.Cantrill@Sun.COM typedef struct stacks_module {
55*12902SBryan.Cantrill@Sun.COM 	char		sm_name[MAXPATHLEN]; /* name of module */
56*12902SBryan.Cantrill@Sun.COM 	uintptr_t	sm_text;	/* base address of text in module */
57*12902SBryan.Cantrill@Sun.COM 	size_t		sm_size;	/* size of text in module */
58*12902SBryan.Cantrill@Sun.COM } stacks_module_t;
59*12902SBryan.Cantrill@Sun.COM 
600Sstevel@tonic-gate extern int findstack(uintptr_t, uint_t, int, const mdb_arg_t *);
610Sstevel@tonic-gate extern int findstack_debug(uintptr_t, uint_t, int, const mdb_arg_t *);
628721SJonathan.Adams@Sun.COM 
63*12902SBryan.Cantrill@Sun.COM /*
64*12902SBryan.Cantrill@Sun.COM  * The following routines are implemented in findstack.c, shared across both
65*12902SBryan.Cantrill@Sun.COM  * genunix and libc.
66*12902SBryan.Cantrill@Sun.COM  */
678721SJonathan.Adams@Sun.COM extern int stacks(uintptr_t, uint_t, int, const mdb_arg_t *);
68*12902SBryan.Cantrill@Sun.COM extern void stacks_cleanup(int);
69*12902SBryan.Cantrill@Sun.COM 
70*12902SBryan.Cantrill@Sun.COM /*
71*12902SBryan.Cantrill@Sun.COM  * The following routines are specific to their context (kernel vs. user-land)
72*12902SBryan.Cantrill@Sun.COM  * and are therefore implemented in findstack_subr.c (of which each of genunix
73*12902SBryan.Cantrill@Sun.COM  * and libc have their own copy).
74*12902SBryan.Cantrill@Sun.COM  */
758721SJonathan.Adams@Sun.COM extern void stacks_help(void);
76*12902SBryan.Cantrill@Sun.COM extern int stacks_findstack(uintptr_t, findstack_info_t *, uint_t);
77*12902SBryan.Cantrill@Sun.COM extern void stacks_findstack_cleanup();
78*12902SBryan.Cantrill@Sun.COM extern int stacks_module(stacks_module_t *);
79*12902SBryan.Cantrill@Sun.COM 
80*12902SBryan.Cantrill@Sun.COM extern int findstack_debug_on;
81*12902SBryan.Cantrill@Sun.COM 
82*12902SBryan.Cantrill@Sun.COM #define	fs_dprintf(x)					\
83*12902SBryan.Cantrill@Sun.COM 	if (findstack_debug_on) {			\
84*12902SBryan.Cantrill@Sun.COM 		mdb_printf("findstack debug: ");	\
85*12902SBryan.Cantrill@Sun.COM 		/*CSTYLED*/				\
86*12902SBryan.Cantrill@Sun.COM 		mdb_printf x ;				\
87*12902SBryan.Cantrill@Sun.COM 	}
880Sstevel@tonic-gate 
890Sstevel@tonic-gate #ifdef	__cplusplus
900Sstevel@tonic-gate }
910Sstevel@tonic-gate #endif
920Sstevel@tonic-gate 
930Sstevel@tonic-gate #endif	/* _MDB_FINDSTACK_H */
94