Fixed UHCI port bits for big endian machines.
[cake.git] / scripts / findhit
blob26d43fbe8ec90dc760c64e7b3215bbfb797a3ef8
1 #!/bin/sh
3 # $0 <module> <offset> <sym> <hit>
5 # ie. $0 iffparse.library 0x080e34b0: SeekStream 0x80e5257
8 if [ "$#" -eq 0 ]; then
9 echo "$0 module offset sym hit"
10 echo "Example: $0 iffparse.library 0x080e34b0: SeekStream 0x80e5257"
11 exit 0
14 path=`dirname $0`
15 module="$1"
16 symoffset="$2"
17 sym="$3"
18 hitaddr="$4"
20 if [ ! -f "$module" ]; then
21 echo "$0: $module: no such file"
22 exit 1
25 entry=`nm "$module" | egrep " $sym\$"`
27 if [ -z "$entry" ]; then
28 echo "$0: Can't find symbol $sym in $module"
29 exit 1
32 #echo $entry
34 offset=`echo "0x$entry" | cut "-d " -f1`
35 offset=`$path/strtoint $offset`
37 symoffset=`echo $symoffset | gawk ' { if (!match($1,/^0x/)) print "0x"$1; else print $1; }'`
38 hitaddr=`echo $hitaddr | gawk ' { if (!match($1,/^0x/)) print "0x"$1; else print $1; }'`
40 symoffset=`$path/strtoint $symoffset`
41 hitaddr=`$path/strtoint $hitaddr`
43 baseaddr=`expr $symoffset - $offset`
45 hitoffset=`expr $hitaddr - $baseaddr`
47 echo "baseaddr=`printf "%x" $baseaddr`"
48 echo "hitoffset=`printf "%x" $hitoffset`"
50 if [ $hitoffset -lt 0 ]; then
51 echo "Hit is not in $module"
52 exit 1;
55 objdump --source --line-numbers "$module" | \
56 gawk 'BEGIN { \
57 lastoff=0; \
58 hitoffset='$hitoffset'; \
59 found=0; \
60 cline[0]=""; \
61 cline[1]=""; \
62 cline[2]=""; \
63 cline[3]=""; \
64 file=""; \
65 line=0; \
66 } \
67 /^[-a-zA-Z0-9_./]+:[0-9]+$/ { \
68 split($0,a,":"); \
69 file=a[1]; \
70 line=int(a[2]); \
71 next \
72 } \
73 /^[ \t]*[0-9a-f]+:?/ { \
74 asmline[0]=asmline[1]; \
75 asmline[1]=asmline[2]; \
76 asmline[2]=asmline[3]; \
77 asmline[3]=$0; \
78 off=hex2int($1); \
79 #print $1"="off; \
80 if (lastoff <= hitoffset && off > hitoffset) \
81 { \
82 if (file!="")
83 printf ("Hit is at line %d in file %s\n", line, file); \
84 else
85 printf ("Hit is 0x%x bytes in %s\n", hitoffset-lastoff, symbol); \
86 for (t=0; t<4; t++) \
87 print cline[t]; \
88 print " ..."; \
89 for (t=0; t<4; t++) \
90 print asmline[t]; \
91 for (t=0; t<4; t++) \
93 getline; \
94 print; \
95 } \
96 found=1; \
97 while (getline > 0); \
98 nextfile; \
99 } \
100 symbol=$2; \
101 lastoff=off; \
102 next; \
105 cline[0]=cline[1]; \
106 cline[1]=cline[2]; \
107 cline[2]=cline[3]; \
108 cline[3]=$0; \
109 line ++; \
111 END { \
112 if (!found) \
114 print "Hit is not in '$module'"; \
115 exit (1); \
119 function hex2int(str ,x,n) { \
120 x=str; \
121 n=0; \
122 while(x!="") \
124 d=index("0123456789abcdef",tolower(substr(x,1,1)))-1; \
125 if (d < 0) break; \
126 n=n*16 + d;
127 x=substr(x,2); \
129 #print "str="str" n="n; \
130 return n; \