/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
*/
#include <mdb/mdb_modapi.h>
#include "findstack.h"
#include "thread.h"
#include "sobj.h"
struct rwindow {
};
#endif
#ifndef STACK_BIAS
#define STACK_BIAS 0
#endif
/*
* Given a stack pointer, try to crawl down it to the bottom.
* "frame" is a VA in MDB's address space.
*
* Returns the number of frames successfully crawled down, or
* CRAWL_FOUNDALL if it got to the bottom of the stack.
*/
static int
{
int levels = 0;
fsip->fsi_overflow = 0;
fs_dprintf(("<0> frame = %p, kbase = %p, ktop = %p, ubase = %p\n",
for (;;) {
break;
else
return (CRAWL_FOUNDALL);
fs_dprintf(("<3> not at base\n"));
fs_dprintf(("<4> found base\n"));
return (CRAWL_FOUNDALL);
}
#endif
fs_dprintf(("<5> fp = %p, kbase = %p, ktop - size = %p\n",
break;
/*
* NULL out the old %fp so we don't go down this stack
* more than once.
*/
if (kill_fp) {
}
levels++;
}
return (levels);
}
typedef struct mdb_findstack_kthread {
/*ARGSUSED*/
int
{
fsip->fsi_failed = 0;
fsip->fsi_overflow = 0;
return (DCMD_ERR);
}
if (print_warnings)
return (DCMD_ERR);
}
if (print_warnings)
"stack base or stack top corrupt for thread %p\n",
addr);
return (DCMD_ERR);
}
#ifdef __amd64
/*
* The stack on amd64 is intentionally misaligned, so ignore the top
* half-frame. See thread_stk_init(). When handling traps, the frame
* is automatically aligned by the hardware, so we only alter ktop if
* needed.
*/
#endif
/*
* If the stack size is larger than a meg, assume that it's bogus.
*/
if (stksz > TOO_BIG_FOR_A_STACK) {
if (print_warnings)
mdb_warn("stack size for thread %p is too big to be "
"reasonable\n", addr);
return (DCMD_ERR);
}
/*
* This could be (and was) a UM_GC allocation. Unfortunately,
* stksz tends to be very large. As currently implemented, dcmds
* invoked as part of pipelines don't have their UM_GC-allocated
* memory freed until the pipeline completes. With stksz in the
* neighborhood of 20k, the popular ::walk thread |::findstack
* pipeline can easily run memory-constrained debuggers (kmdb) out
* of memory. This can be changed back to a gc-able allocation when
* the debugger is changed to free UM_GC memory more promptly.
*/
if (print_warnings)
mdb_warn("couldn't read entire stack for thread %p\n",
addr);
return (DCMD_ERR);
}
/*
* Try the saved %sp first, if it looks reasonable.
*/
#if !defined(__i386)
#endif
goto found;
}
}
/*
* Now walk through the whole stack, starting at the base,
* trying every possible "window".
*/
goto found;
}
}
/*
* We didn't conclusively find the stack. So we'll take another lap,
* and print out anything that looks possible.
*/
if (print_warnings)
int levels;
if (print_warnings)
} else if (levels == CRAWL_FOUNDALL) {
/*
* If this is a live system, the stack could change
* between the two mdb_vread(ubase, utop, kbase)'s,
* and we could have a fully valid stack here.
*/
goto found;
}
}
fsip->fsi_overflow = 0;
return (DCMD_ERR);
return (DCMD_OK);
}
void
{}
/*ARGSUSED*/
int
{
if (!mp->mod_modname)
return (WALK_NEXT);
mdb_warn("failed to read mod_modname in \"modctl\" walk");
return (WALK_ERR);
}
return (WALK_NEXT);
return (WALK_DONE);
}
int
{
mdb_warn("cannot walk \"modctl\"");
return (-1);
}
return (0);
}
/*ARGSUSED*/
static void
{
}
/*ARGSUSED*/
static void
{
}
void
stacks_help(void)
{
"::stacks processes all of the thread stacks on the system, grouping\n"
"together threads which have the same:\n"
"\n"
" * Thread state,\n"
" * Sync object type, and\n"
" * PCs in their stack trace.\n"
"\n"
"The default output (no address or options) is just a dump of the thread\n"
"groups in the system. For a view of active threads, use \"::stacks -i\",\n"
"which filters out FREE threads (interrupt threads which are currently\n"
"inactive) and threads sleeping on a CV. (Note that those threads may still\n"
"be noteworthy; this is just for a first glance.) More general filtering\n"
"options are described below, in the \"FILTERS\" section.\n"
"\n"
"::stacks can be used in a pipeline. The input to ::stacks is one or more\n"
"thread pointers. For example, to get a summary of threads in a process,\n"
"you can do:\n"
"\n"
" %<b>procp%</b>::walk thread | ::stacks\n"
"\n"
"When output into a pipe, ::stacks prints all of the threads input,\n"
"filtered by the given filtering options. This means that multiple\n"
"::stacks invocations can be piped together to achieve more complicated\n"
"filters. For example, to get threads which have both 'fop_read' and\n"
"'cv_wait_sig_swap' in their stack trace, you could do:\n"
"\n"
" ::stacks -c fop_read | ::stacks -c cv_wait_sig_swap_core\n"
"\n"
"To get the full list of threads in each group, use the '-a' flag:\n"
"\n"
" ::stacks -a\n"
"\n");
mdb_dec_indent(2);
mdb_printf("%<b>OPTIONS%</b>\n");
mdb_inc_indent(2);
mdb_printf("%s",
" -a Print all of the grouped threads, instead of just a count.\n"
" -f Force a re-run of the thread stack gathering.\n"
" -v Be verbose about thread stack gathering.\n"
"\n");
mdb_dec_indent(2);
mdb_printf("%<b>FILTERS%</b>\n");
mdb_inc_indent(2);
mdb_printf("%s",
" -i Show active threads; equivalent to '-S CV -T FREE'.\n"
" -c func[+offset]\n"
" -C func[+offset]\n"
" -m module\n"
" Only print threads whose stacks contain functions from module.\n"
" -M module\n"
" Only print threads whose stacks do not contain functions from\n"
" module.\n"
" -s {type | ALL}\n"
" Only print threads which are on a 'type' synchronization object\n"
" (SOBJ).\n"
" -S {type | ALL}\n"
" Only print threads which are not on a 'type' SOBJ.\n"
" -t tstate\n"
" Only print threads which are in thread state 'tstate'.\n"
" -T tstate\n"
" Only print threads which are not in thread state 'tstate'.\n"
"\n");
mdb_printf(" SOBJ types:");
mdb_printf("\n");
mdb_printf("Thread states:");
mdb_printf(" panic\n");
}