home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume20 / pmd / part01 next >
Encoding:
Text File  |  1991-06-28  |  4.6 KB  |  145 lines

  1. Newsgroups: comp.sources.misc
  2. From: Ian Cottam <ian@cs.man.ac.uk>
  3. Subject:  v20i072:  pmd - script to improve on "*fault - core dumped", Part01/01
  4. Message-ID: <1991Jun27.173852.1860@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 6679aea46ec46427d1a6b957fdbf2b35
  6. Date: Thu, 27 Jun 1991 17:38:52 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Ian Cottam <ian@cs.man.ac.uk>
  10. Posting-number: Volume 20, Issue 72
  11. Archive-name: pmd/part01
  12. Environment: DBX, UNIX
  13.  
  14. This is a free, public domain, shell script to run a binary prog and, 
  15. if it dumps core runs the dbx debugger automatically to tell you why.
  16.  
  17. Ian
  18. _________________________cut here__________________
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then feed it
  21. # into a shell via "sh file" or similar.  To overwrite existing files,
  22. # type "sh file -c".
  23. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  24. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  25. # Contents:  pmd
  26. # Wrapped by kent@sparky on Thu Jun 27 11:00:31 1991
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. echo If this archive is complete, you will see the following message:
  29. echo '          "shar: End of archive."'
  30. if test -f 'pmd' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'pmd'\"
  32. else
  33.   echo shar: Extracting \"'pmd'\" \(2545 characters\)
  34.   sed "s/^X//" >'pmd' <<'END_OF_FILE'
  35. X#!/bin/sh
  36. X#
  37. X# usage: pmd [-v] prog args...
  38. X# shell script to run a binary prog and, if it dumps,
  39. X# runs a debugger to tell you why!
  40. X# The flag -v means print more verbose explanatory text.
  41. X#
  42. X# Ian Cottam, June 91 release 6, friday.
  43. X# Donated to the public domain :-)
  44. X
  45. Xif test $# -eq  0; then
  46. X   echo "`basename $0`: usage: `basename $0` [-v] prog args..." 1>&2 ; exit 1;
  47. Xfi
  48. X
  49. Xif test $1 = "-v"
  50. Xthen
  51. X    SPEAKUP=1
  52. X    shift
  53. X    if test $# -eq  0; then
  54. X          echo "`basename $0`: usage: `basename $0` [-v] prog args..." 1>&2 ; exit 1;
  55. X    fi
  56. Xfi
  57. X
  58. X# don't be confused by random core files
  59. Xif test -f core; then rm -f core; fi
  60. X
  61. X# execute prog args...
  62. X$*
  63. Xif test ! -f core; then exit $?; fi
  64. X
  65. X# only do rest of script if prog dumped on us
  66. X# '\n'
  67. XNL='
  68. X'
  69. X# number of lines to print either side of fault
  70. XWINDOW=3
  71. X
  72. Xtrap "rm -f /tmp/pmd$$; exit 1" 1 2 15
  73. X
  74. X# find out how deeply nested we were when fault occured
  75. X{ echo up 10000; echo quit; } |  dbx $1 core 2> /tmp/pmd$$ > /dev/null
  76. Xread MOVED UP N LEVELS < /tmp/pmd$$
  77. X
  78. X# find out what line number, approximately, we crashed at
  79. X{ echo list; echo quit; } | dbx $1 core 2>/dev/null | sed '1,2d' > /tmp/pmd$$
  80. Xread LINENO JUNK < /tmp/pmd$$
  81. Xrm -f /tmp/pmd$$
  82. X# be careful re occasional junk from dbx
  83. Xexpr $LINENO + 42 > /dev/null 2>&1
  84. Xif test $? = 2; then
  85. X  echo "`basename $0`: confused! (was -g given to compiler?), run debugger by hand!" 1>&2
  86. X  exit 1
  87. Xfi
  88. X
  89. Xif test $SPEAKUP; then
  90. X   echo
  91. X   echo Your command "($*)" has aborted.
  92. X   echo A source-related analysis, via dbx\(1\), follows.
  93. X   echo You are cautioned to read the Bugs section of the dbx man page.
  94. Xfi
  95. X
  96. X# sort out line number range to print around fault area
  97. Xecho "($*) -- fault on or about line $LINENO"
  98. Xif test $LINENO -le $WINDOW; then LINENO=`expr $WINDOW + 1`; fi
  99. X
  100. X# check if crash in main
  101. Xif test $SPEAKUP; then
  102. X   echo "A few lines either side of the fault line are also printed."
  103. X   if test "$LEVELS" = "top call level"; then
  104. X    echo "The arguments and local variables to main follow."
  105. X   else
  106. X    echo "The arguments and local variables to the offending function follow."
  107. X    echo "Subsequent output shows the call trace back up to main."
  108. X   fi
  109. Xfi
  110. X
  111. X# print for each function level from fault point backwards
  112. X{ echo file
  113. X  echo func
  114. X  echo list `expr $LINENO - $WINDOW` "," `expr $LINENO + $WINDOW`
  115. X  echo dump
  116. X  if test "$LEVELS" && test "$LEVELS" != "top call level"; then
  117. X    while test $N -ne 0; do
  118. X      echo up; echo file; echo dump
  119. X      N=`expr $N - 1`
  120. X    done
  121. X  fi
  122. X}| dbx $1 core| sed "1,2d;s/^Current function is/\\${NL}Called from function:/"
  123. X
  124. Xexit 0
  125. END_OF_FILE
  126.   if test 2545 -ne `wc -c <'pmd'`; then
  127.     echo shar: \"'pmd'\" unpacked with wrong size!
  128.   fi
  129.   # end of 'pmd'
  130. fi
  131. echo shar: End of archive.
  132. exit 0
  133. --
  134. Ian Cottam, Room IT209, Department of Computer Science,
  135. University of Manchester, Oxford Road, Manchester, M13 9PL, U.K.
  136. Tel: (+44) 61-275 6157         FAX: (+44) 61-275-6236
  137. Internet: ian%cs.man.ac.uk;  JANET: ian@uk.ac.man.cs
  138.  
  139. exit 0 # Just in case...
  140. -- 
  141. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  142. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  143. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  144. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  145.