"Fossies" - the Fresh Open Source Software Archive 
Member "mpr-2.8/mprfl" (3 Nov 2002, 1899 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
3 TMP=${MPRTMP-/tmp}
4 MPRAWK=${MPRAWK-awk}
5
6 pcfile=$TMP/mpr.pc.$$
7 gdbfile=$TMP/mpr.gdb.$$
8 gdbcmdfile=$TMP/mpr.gdbcmd.$$
9 fofiles=
10
11 for arg in "$@"; do
12 case "$1" in
13 -F ) fofiles="$2"; shift;;
14 -F*) fofiles=`echo "$1" | sed 's/-F//'`;;
15 --) shift; break;;
16 -*) echo "mprfl: warning: ignoring unknown option $1" >&2;;
17 *) break;;
18 esac
19 shift
20 done
21
22 case "$#" in
23 1|2) ;;
24 *) echo "usage: mprfl [-F foo.c,bar.c,..] a.out [log]" >&2
25 exit 1;;
26 esac
27
28 aout=`mprwhich "$1"` || exit 1; shift
29 MPRFILTER=`mprfilter mprfl "$@"` || exit 1
30
31 status=1
32 set -e
33 trap 'set +e; rm -f $pcfile $gdbfile $gdbcmdfile; trap 0; exit $status' 0 1 2 13 15
34
35 $MPRFILTER |
36
37 $MPRAWK -F: '
38 function savepc(n, i) { for (i=2; i<=n; i++) pc[$i]=1 }
39 /^m/ { savepc(NF-2) }
40 /^r/ { savepc(NF-3) }
41 /^f/ { savepc(NF-1) }
42 END { for (i in pc) print i }
43 ' |
44
45 sort -n | tee $pcfile |
46
47 (
48 echo set prompt
49 echo set width 0
50 echo set print demangle off
51 echo set print asm-demangle off
52 $MPRAWK '{ printf "info line *%s\n", $1 }'
53 echo quit
54 ) >$gdbcmdfile
55
56 (gdb -nx -q --command=$gdbcmdfile "$aout" 2>/dev/null; echo) |
57
58 $MPRAWK '
59 {
60 gsub(/\(gdb\) /, "")
61 }
62 /^$/ {
63 next
64 }
65 /^Line/ {
66 gsub("\"", "", $4)
67 if ($4 ~ /^\.\//) # delete leading ./
68 $4 = substr($4, 3)
69 printf "%s\t%s\n", $4, $2
70 next
71 }
72 /No line number/ {
73 print "xxx" # needed for paste
74 next
75 }
76 /^(Current language|\(no debugging|\[New|\[Switching)/ {
77 next
78 }
79 # unexpected output from gdb -> print a warning
80 {
81 printf "*** mprfl: warning: unexpected output from gdb\n" |"cat 1>&2"
82 printf "*** mprfl: [%s]\n", $0 |"cat 1>&2"
83 }
84
85 ' >$gdbfile
86
87 paste $pcfile $gdbfile |
88
89 $MPRAWK -F" " -v fofiles="$fofiles" '
90 BEGIN {
91 if (fofiles != "") {
92 gsub(",", "|", fofiles)
93 gsub(" ", "|", fofiles)
94 gsub("/", "\\/", fofiles)
95 gsub("\\.", "\\.", fofiles)
96 }
97 }
98 /xxx$/ {
99 next
100 }
101 {
102 if (fofiles == "" || $2 ~ "^("fofiles")$")
103 print
104 }
105 '
106
107 status=0