ian@cs.man.ac.uk (Ian Cottam) (06/28/91)
Submitted-by: Ian Cottam <ian@cs.man.ac.uk> Posting-number: Volume 20, Issue 72 Archive-name: pmd/part01 Environment: DBX, UNIX This is a free, public domain, shell script to run a binary prog and, if it dumps core runs the dbx debugger automatically to tell you why. Ian _________________________cut here__________________ #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # Contents: pmd # Wrapped by kent@sparky on Thu Jun 27 11:00:31 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH echo If this archive is complete, you will see the following message: echo ' "shar: End of archive."' if test -f 'pmd' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'pmd'\" else echo shar: Extracting \"'pmd'\" \(2545 characters\) sed "s/^X//" >'pmd' <<'END_OF_FILE' X#!/bin/sh X# X# usage: pmd [-v] prog args... X# shell script to run a binary prog and, if it dumps, X# runs a debugger to tell you why! X# The flag -v means print more verbose explanatory text. X# X# Ian Cottam, June 91 release 6, friday. X# Donated to the public domain :-) X Xif test $# -eq 0; then X echo "`basename $0`: usage: `basename $0` [-v] prog args..." 1>&2 ; exit 1; Xfi X Xif test $1 = "-v" Xthen X SPEAKUP=1 X shift X if test $# -eq 0; then X echo "`basename $0`: usage: `basename $0` [-v] prog args..." 1>&2 ; exit 1; X fi Xfi X X# don't be confused by random core files Xif test -f core; then rm -f core; fi X X# execute prog args... X$* Xif test ! -f core; then exit $?; fi X X# only do rest of script if prog dumped on us X# '\n' XNL=' X' X# number of lines to print either side of fault XWINDOW=3 X Xtrap "rm -f /tmp/pmd$$; exit 1" 1 2 15 X X# find out how deeply nested we were when fault occured X{ echo up 10000; echo quit; } | dbx $1 core 2> /tmp/pmd$$ > /dev/null Xread MOVED UP N LEVELS < /tmp/pmd$$ X X# find out what line number, approximately, we crashed at X{ echo list; echo quit; } | dbx $1 core 2>/dev/null | sed '1,2d' > /tmp/pmd$$ Xread LINENO JUNK < /tmp/pmd$$ Xrm -f /tmp/pmd$$ X# be careful re occasional junk from dbx Xexpr $LINENO + 42 > /dev/null 2>&1 Xif test $? = 2; then X echo "`basename $0`: confused! (was -g given to compiler?), run debugger by hand!" 1>&2 X exit 1 Xfi X Xif test $SPEAKUP; then X echo X echo Your command "($*)" has aborted. X echo A source-related analysis, via dbx\(1\), follows. X echo You are cautioned to read the Bugs section of the dbx man page. Xfi X X# sort out line number range to print around fault area Xecho "($*) -- fault on or about line $LINENO" Xif test $LINENO -le $WINDOW; then LINENO=`expr $WINDOW + 1`; fi X X# check if crash in main Xif test $SPEAKUP; then X echo "A few lines either side of the fault line are also printed." X if test "$LEVELS" = "top call level"; then X echo "The arguments and local variables to main follow." X else X echo "The arguments and local variables to the offending function follow." X echo "Subsequent output shows the call trace back up to main." X fi Xfi X X# print for each function level from fault point backwards X{ echo file X echo func X echo list `expr $LINENO - $WINDOW` "," `expr $LINENO + $WINDOW` X echo dump X if test "$LEVELS" && test "$LEVELS" != "top call level"; then X while test $N -ne 0; do X echo up; echo file; echo dump X N=`expr $N - 1` X done X fi X}| dbx $1 core| sed "1,2d;s/^Current function is/\\${NL}Called from function:/" X Xexit 0 END_OF_FILE if test 2545 -ne `wc -c <'pmd'`; then echo shar: \"'pmd'\" unpacked with wrong size! fi # end of 'pmd' fi echo shar: End of archive. exit 0 -- Ian Cottam, Room IT209, Department of Computer Science, University of Manchester, Oxford Road, Manchester, M13 9PL, U.K. Tel: (+44) 61-275 6157 FAX: (+44) 61-275-6236 Internet: ian%cs.man.ac.uk; JANET: ian@uk.ac.man.cs exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.