# COREinfo.def: Extracts Core Dump Information # $Id: COREinfo.def,v 1.8 2008/02/25 17:32:54 mschenke Exp $ # ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/modules/COREinfo.def,v 1.8 2008/02/25 17:32:54 mschenke Exp $ # # Change History # 20080225 MSC Change the copyright notice. =head1 NAME COREinfo - Extracts Core Dump Information =head1 DESCRIPTION This module extracts relevant information from a core dump file. The following macros are available: =cut # Make the module persistent and share macros keep $KEEP_BLOCK,@SHARE_MACROS var @SHARE_MACROS = ('can_analyze_core','analyze_core') # Initialisation keep $CORE_DEBUG,$CORE_INFO,$CORE_PFLAGS,$CORE_PMAP,$CORE_TYPE,%CORE_OPT if !$CORE_INFO {var $CORE_INFO = true # Define some variables that are shared between macros var $CORE_DEBUG var $CORE_PFLAGS var $CORE_PMAP var $CORE_TYPE var %CORE_OPT = ('gdb',' -quiet') # Find a debugger if isUnix() {macro find_command {if findCommand($arg[0],true) {var $pgm = last if testFile('x',$pgm) return quote($pgm,'x') } return undef } if match(getOsName(),'sunos') {if find_command('pstack') {var $CORE_DEBUG = last var $CORE_PFLAGS = find_command('pflags') var $CORE_PMAP = find_command('pmap') } } if !$CORE_DEBUG {loop $CORE_TYPE ('gdb','adb','dbx','sdb') {if find_command($CORE_TYPE) {var $CORE_DEBUG = last break } } } } } =head2 can_analyze_core() This macro indicates which command has been found to analyze core dumps. Otherwise, it returns an undefined value. =cut macro can_analyze_core {import $CORE_DEBUG keep $CORE_DEBUG return $CORE_DEBUG } =head2 analyze_core($dmp...) This macro analyzes all core dumps specified as arguments. For each dump, it determines the location of the corresponding executable first and then extracts the stack information. =cut macro analyze_core {import $CORE_DEBUG,$CORE_PFLAGS,$CORE_PMAP,$CORE_TYPE,%CORE_OPT keep $CORE_DEBUG,$CORE_PFLAGS,$CORE_PMAP,$CORE_TYPE,%CORE_OPT # Abort when no debugger has been found if !$CORE_DEBUG return # Initialize the debugger input file if compare('eq',$CORE_TYPE,'gdb') {var $inp = createTemp('debug') call writeTemp('debug','thread apply all where') call writeTemp('debug','q') call closeTemp('debug') } elsif compare('eq',$CORE_TYPE,'adb') {var $inp = createTemp('debug') call writeTemp('debug','$c') call writeTemp('debug','$q') call closeTemp('debug') } elsif compare('eq',$CORE_TYPE,'sdb') {var $inp = createTemp('debug') call writeTemp('debug','t') call writeTemp('debug','quit') call closeTemp('debug') } elsif compare('eq',$CORE_TYPE,'dbx') {var $inp = createTemp('debug') call writeTemp('debug','where') call writeTemp('debug','quit') call closeTemp('debug') } else var $inp = undef # Generate the report loop $dmp (@arg) {write '---+ ',$dmp if testFile('r',$dmp) {# Try to extract the program name that produced the core var $pgm = field("'",1,command(concat('file ',quote($dmp,'x')))) # List the environment, what we know so far write '|*Core file*|',$dmp,' |' write '|*Program *|',$pgm,' |' # Extract information from the core file if $CORE_TYPE {# Extract possible executables from the corefile var ($flg,%exe) = () loop $exe ($pgm,\ catFile(dirname($dmp),$pgm),\ grepCommand(concat('strings ',quote($dmp,'x')),\ concat('^(.*\/)?',$pgm,'$'))) {var $exe = replace($exe,'^\.\/+') if testFile('x',$exe) {next testDir('d',$exe) var $exe{$exe} = 1 var $flg = true } } # Try them individually to extract a stack trace. if $flg {loop $exe (keys(%exe)) {write '---## Core extraction be attempted with ',$exe call writeCommand(concat($CORE_DEBUG,\ $CORE_OPT{$CORE_TYPE},' ',quote($exe,'x'),' ',\ quote($dmp,'x'),' <',quote($inp,'x'))) } } else write '** Program not found.**%BR%' } else {# If pstack is available, just call the code and be done with it. call writeCommand(concat($CORE_DEBUG,' ',quote($dmp,'x'))) # If we found pmap, run it if $CORE_PMAP {write '---' call writeCommand(concat($CORE_PMAP,' ',quote($dmp,'x'))) } # If we found pflags, run it too if $CORE_PFLAGS {write '---' call writeCommand(concat($CORE_PFLAGS,' ',quote($dmp,'x'))) } } } else {write '** Not readable.**%BR%' call statFile('b',$dmp) } write $TOP } # Remove the temporary debug file if $inp call unlinkTemp('debug') } =begin credits =over 10 =item RDA 4.4: Roger Snowden. =back =end credits =head1 COPYRIGHT NOTICE Copyright (c) 2002-2008, Oracle. All rights reserved. =head1 TRADEMARK NOTICE Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. =cut