1#!/usr/sbin/dtrace -Cs 2/* 3 * crash.d - Crashed Application info. 4 * Written in DTrace (Solaris 10 3/05). 5 * 6 * 24-Apr-2006, ver 0.92 7 * 8 * When applications crash via a SIGSEGV or SIGBUS, a report of the 9 * process state is printed out. 10 * 11 * USAGE: crash.d 12 * 13 * FIELDS: 14 * Type Signal type 15 * Program Execname of process 16 * Agrs Argument listing of process 17 * PID Process ID 18 * TID Thread ID 19 * LWPs Number of Light Weight Processes 20 * PPID Parent Process ID 21 * UID User ID 22 * GID Group ID 23 * TaskID Task ID 24 * ProjID Project ID 25 * PoolID Pool ID 26 * ZoneID Zone ID 27 * zone Zone name 28 * CWD Current working directory 29 * errno Error number of last syscall 30 * 31 * SEE ALSO: mdb, pstack, coreadm 32 * app_crash.d - Greg Nakhimovsky & Morgan Herrington 33 * 34 * COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 35 * 36 * CDDL HEADER START 37 * 38 * The contents of this file are subject to the terms of the 39 * Common Development and Distribution License, Version 1.0 only 40 * (the "License"). You may not use this file except in compliance 41 * with the License. 42 * 43 * You can obtain a copy of the license at Docs/cddl1.txt 44 * or http://www.opensolaris.org/os/licensing. 45 * See the License for the specific language governing permissions 46 * and limitations under the License. 47 * 48 * CDDL HEADER END 49 * 50 * 29-May-2005 Brendan Gregg Created this. 51 */ 52 53#pragma D option quiet 54#pragma D option destructive 55 56dtrace:::BEGIN 57{ 58 printf("Waiting for crashing applications...\n"); 59} 60 61/* 62 * Print Report Header 63 */ 64proc:::signal-send 65/(args[2] == SIGBUS || args[2] == SIGSEGV) && pid == args[1]->pr_pid/ 66{ 67 stop(); 68 self->elapsed = timestamp - curthread->t_procp->p_mstart; 69 self->crash = 1; 70 71 printf("\n-----------------------------------------------------\n"); 72 printf("CRASH DETECTED at %Y\n", walltimestamp); 73 printf("-----------------------------------------------------\n"); 74 printf("Type: %s\n", args[2] == SIGBUS ? "SIGBUS" : "SIGSEGV"); 75 printf("Program: %s\n", execname); 76 printf("Args: %S\n", curpsinfo->pr_psargs); 77 printf("PID: %d\n", pid); 78 printf("TID: %d\n", tid); 79 printf("LWPs: %d\n", curthread->t_procp->p_lwpcnt); 80 printf("PPID: %d\n", ppid); 81 printf("UID: %d\n", uid); 82 printf("GID: %d\n", gid); 83 printf("TaskID: %d\n", curpsinfo->pr_taskid); 84 printf("ProjID: %d\n", curpsinfo->pr_projid); 85 printf("PoolID: %d\n", curpsinfo->pr_poolid); 86 printf("ZoneID: %d\n", curpsinfo->pr_zoneid); 87 printf("zone: %s\n", zonename); 88 printf("CWD: %s\n", cwd); 89 printf("errno: %d\n", errno); 90 91 printf("\nUser Stack Backtrace,"); 92 ustack(); 93 94 printf("\nKernel Stack Backtrace,"); 95 stack(); 96} 97 98/* 99 * Print Java Details 100 */ 101proc:::signal-send 102/self->crash && execname == "java"/ 103{ 104 printf("\nJava Stack Backtrace,"); 105 jstack(); 106} 107 108/* 109 * Print Ancestors 110 */ 111proc:::signal-send 112/self->crash/ 113{ 114 printf("\nAnsestors,\n"); 115 self->level = 1; 116 self->procp = curthread->t_procp; 117 self->ptr = self->procp; 118} 119 120/* ancestory un-rolled loop, reverse order, 6 deep */ 121proc:::signal-send /self->crash && self->ptr != 0/ 122{ 123 printf("%*s %d %S\n", self->level += 2, "", 124 self->ptr->p_pidp->pid_id, self->ptr->p_user.u_psargs); 125 self->ptr = self->ptr->p_parent; 126} 127proc:::signal-send /self->crash && self->ptr != 0/ 128{ 129 printf("%*s %d %S\n", self->level += 2, "", 130 self->ptr->p_pidp->pid_id, self->ptr->p_user.u_psargs); 131 self->ptr = self->ptr->p_parent; 132} 133proc:::signal-send /self->crash && self->ptr != 0/ 134{ 135 printf("%*s %d %S\n", self->level += 2, "", 136 self->ptr->p_pidp->pid_id, self->ptr->p_user.u_psargs); 137 self->ptr = self->ptr->p_parent; 138} 139proc:::signal-send /self->crash && self->ptr != 0/ 140{ 141 printf("%*s %d %S\n", self->level += 2, "", 142 self->ptr->p_pidp->pid_id, self->ptr->p_user.u_psargs); 143 self->ptr = self->ptr->p_parent; 144} 145proc:::signal-send /self->crash && self->ptr != 0/ 146{ 147 printf("%*s %d %S\n", self->level += 2, "", 148 self->ptr->p_pidp->pid_id, self->ptr->p_user.u_psargs); 149 self->ptr = self->ptr->p_parent; 150} 151proc:::signal-send /self->crash && self->ptr != 0/ 152{ 153 printf("%*s %d %S\n", self->level += 2, "", 154 self->ptr->p_pidp->pid_id, self->ptr->p_user.u_psargs); 155 self->ptr = self->ptr->p_parent; 156} 157 158/* 159 * Print Report Footer 160 */ 161proc:::signal-send 162/self->crash/ 163{ 164 165 printf("\nTimes,\n"); 166 printf(" User: %d ticks\n", self->procp->p_utime); 167 printf(" Sys: %d ticks\n", self->procp->p_stime); 168 printf(" Elapsed: %d ms\n", self->elapsed/1000000); 169 170 printf("\nSizes,\n"); 171 printf(" Heap: %d bytes\n", self->procp->p_brksize); 172 printf(" Stack: %d bytes\n", self->procp->p_stksize); 173 174 self->ptr = 0; 175 self->procp = 0; 176 self->crash = 0; 177 self->level = 0; 178 self->elapsed = 0; 179 system("/usr/bin/prun %d", pid); 180} 181