"Fossies" - the Fresh Open Source Software Archive

Member "mpr-2.8/mprfl-so" (3 Jan 2004, 3485 Bytes) of package /linux/misc/old/mpr-2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 # XXX duplicates functionality of mprnm and mprfl
    3 
    4 TMP=${MPRTMP-/tmp}
    5 MPRAWK=${MPRAWK-awk}
    6 
    7 pcfile=$TMP/mprfl.pc.$$
    8 gdbfile=$TMP/mprfl.gdb.$$
    9 gdbcmdfile=$TMP/mprfl.gdbcmd.$$
   10 tmpnmfile=$TMP/mprfll.nm.$$
   11 fofiles=
   12 nmfile=
   13 flfile=
   14 popt=
   15 
   16 for arg in "$@"; do
   17     case "$1" in
   18     -p) popt=-p;;
   19     -n )    nmfile="$2"; shift;;
   20     -n*)    nmfile=`echo "$1" | sed 's/-n//'`;;
   21     -f )    flfile=$2; shift;;
   22     -f*)    flfile=`echo "$1" | sed 's/-f//'`;;
   23     -F )    fofiles="$2"; shift;;
   24     -F*)    fofiles=`echo "$1" | sed 's/-F//'`;;
   25     --) shift; break;;
   26     -*) echo "mprfl-so: warning: ignoring unknown option $1" >&2;;
   27     *)  break;;
   28     esac
   29     shift
   30 done
   31 
   32 usage()
   33 {
   34     echo "usage: mprfl-so -n nmfile -f flfile [-F foo.c,bar.c,..] a.out [log]" >&2
   35     exit 1
   36 }
   37 
   38 case "$nmfile" in
   39 "") usage;;
   40 esac
   41 
   42 case "$flfile" in
   43 "") usage;;
   44 esac
   45 
   46 case "$#" in
   47 1|2)    ;;
   48 *)  usage;;
   49 esac
   50 
   51 aout=`mprwhich "$1"` || exit 1; shift
   52 MPRFILTER=`mprfilter mprfl-so "$@"` || exit 1
   53 
   54 (mprnm "$aout"; mprnm -D "$aout") 2>/dev/null | grep '  _init$' >/dev/null
   55 case "$?" in
   56 0)  ;;
   57 *)  echo mprfl-so: error: cannot find symbol _init in "$aout" >&2
   58     exit 1;;
   59 esac
   60 
   61 unset MPRFI
   62 set -e
   63 status=1
   64 trap 'set +e; rm -f $pcfile $gdbfile $gdbcmdfile $tmpnmfile; trap 0; exit $status' 0 1 2 13 15
   65 
   66 $MPRFILTER |
   67 
   68 $MPRAWK -F: '
   69     function savepc(n, i) { for (i=2; i<=n; i++) pc[$i]=1 }
   70     /^m/ { savepc(NF-2) }
   71     /^r/ { savepc(NF-3) }
   72     /^f/ { savepc(NF-1) }
   73     END  { for (i in pc) print i }
   74 ' |
   75 
   76 sort -n | tee $pcfile |
   77 
   78 (
   79     echo set prompt
   80     echo set confirm 0
   81     echo set width 0
   82     echo set print demangle off
   83     echo set print asm-demangle off
   84     case "$MPRLD_PRELOAD" in
   85     ?*) echo set env LD_PRELOAD "$MPRLD_PRELOAD${LD_PRELOAD:+:}$LD_PRELOAD";;
   86     esac
   87     echo break _init
   88     echo run
   89     $MPRAWK '{ printf "info line *%s\n", $1 }'
   90     echo quit
   91 ) >$gdbcmdfile
   92 
   93 (gdb -nx -q --command=$gdbcmdfile "$aout" 2>/dev/null; echo) |
   94 
   95 $MPRAWK '
   96     {
   97         gsub(/\(gdb\) /, "")
   98     }
   99     /^$/ {
  100         next
  101     }
  102     /^Line/ {
  103         gsub(/"/, "", $4)
  104         sub(/\.$/, "", $(NF-5))
  105         sub(/^</, "", $(NF-5))
  106         sub(/\+[0-9]+>$/, "", $(NF-5))
  107         sub(/>$/, "", $(NF-5))
  108         if ($4 ~ /^\.\//)   # delete leading ./
  109             $4 = substr($4, 3)
  110         printf "%s\t%s\t%s\n", $(NF-5), $4, $2
  111         next
  112     }
  113     /No line number.*>/ {
  114         sub(/\.$/, "", $NF)
  115         sub(/^</, "", $NF)
  116         sub(/\+[0-9]+>$/, "", $NF)
  117         sub(/>$/, "", $NF)
  118         printf "%s\txxx\n", $NF
  119         next
  120     }
  121     /No line number/ {
  122         printf "xxx\n"
  123         next
  124     }
  125     /^(Breakpoint [0-9]|Current language|\(no debugging|\[New|\[Switching)/ {
  126         next
  127     }
  128     /Program exited normally/ {
  129         next
  130     }
  131     # unexpected output from gdb -> print a warning
  132     {
  133         printf "*** mprfl-so: warning: unexpected output from gdb\n" |"cat 1>&2"
  134         printf "*** mprfl-so: [%s]\n", $0 |"cat 1>&2"
  135     }
  136 ' >$gdbfile
  137 
  138 >$flfile
  139 >$tmpnmfile
  140 
  141 paste $pcfile $gdbfile |
  142 
  143 $MPRAWK -v nmfile="$tmpnmfile" -v flfile="$flfile" -v fofiles="$fofiles" '
  144     BEGIN {
  145         OFS="\t"
  146         if (fofiles != "") {
  147             gsub(",", "|", fofiles)
  148             gsub(" ", "|", fofiles)
  149             gsub("/", "\\/", fofiles)
  150             gsub("\\.", "\\.", fofiles)
  151         }
  152     }
  153     {
  154         sub(/   xxx$/, "")
  155     }
  156     NF==1 {
  157         next
  158     }
  159     NF==2 {
  160         print >>nmfile
  161         next
  162     }
  163     NF==4 {
  164         print $1, $2 >>nmfile
  165         if (fofiles == "" || $3 ~ "^("fofiles")$")
  166             print $1, $3, $4 >>flfile
  167         next
  168     }
  169     # unexpected output from paste -> bail out
  170     {
  171         printf "*** mprfl-so: error: unexpected output from paste\n" |"cat 1>&2"
  172         printf "*** mprfl-so: [%s]\n", $0 |"cat 1>&2"
  173         exit 1
  174     }'
  175 
  176 mprdem $popt <$tmpnmfile |
  177 
  178 sed -e 's/global destructors keyed to /_GLOBAL_$D$/' \
  179     -e 's/global constructors keyed to /_GLOBAL_$C$/' \
  180     -e 's/::/<>/g' >"$nmfile"
  181 
  182 status=0