|
2 | 2 | |
3 | 3 | #set -x |
4 | 4 |
|
5 | | -if [[ $# != 2 ]]; then |
| 5 | +if [[ $# < 2 ]]; then |
6 | 6 | echo "Usage:" |
7 | | - echo " $0 [vmlinux] [base path]" |
| 7 | + echo " $0 [vmlinux] [base path] [modules path]" |
8 | 8 | exit 1 |
9 | 9 | fi |
10 | 10 |
|
11 | 11 | vmlinux=$1 |
12 | 12 | basepath=$2 |
| 13 | +modpath=$3 |
13 | 14 | declare -A cache |
| 15 | +declare -A modcache |
14 | 16 |
|
15 | 17 | parse_symbol() { |
16 | 18 | # The structure of symbol at this point is: |
@@ -19,6 +21,17 @@ parse_symbol() { |
19 | 21 | # For example: |
20 | 22 | # do_basic_setup+0x9c/0xbf |
21 | 23 |
|
| 24 | + if [[ $module == "" ]] ; then |
| 25 | + local objfile=$vmlinux |
| 26 | + elif [[ "${modcache[$module]+isset}" == "isset" ]]; then |
| 27 | + local objfile=${modcache[$module]} |
| 28 | + else |
| 29 | + [[ $modpath == "" ]] && return |
| 30 | + local objfile=$(find "$modpath" -name $module.ko -print -quit) |
| 31 | + [[ $objfile == "" ]] && return |
| 32 | + modcache[$module]=$objfile |
| 33 | + fi |
| 34 | + |
22 | 35 | # Remove the englobing parenthesis |
23 | 36 | symbol=${symbol#\(} |
24 | 37 | symbol=${symbol%\)} |
@@ -29,11 +42,11 @@ parse_symbol() { |
29 | 42 | # Use 'nm vmlinux' to figure out the base address of said symbol. |
30 | 43 | # It's actually faster to call it every time than to load it |
31 | 44 | # all into bash. |
32 | | - if [[ "${cache[$name]+isset}" == "isset" ]]; then |
33 | | - local base_addr=${cache[$name]} |
| 45 | + if [[ "${cache[$module,$name]+isset}" == "isset" ]]; then |
| 46 | + local base_addr=${cache[$module,$name]} |
34 | 47 | else |
35 | | - local base_addr=$(nm "$vmlinux" | grep -i ' t ' | awk "/ $name\$/ {print \$1}" | head -n1) |
36 | | - cache["$name"]="$base_addr" |
| 48 | + local base_addr=$(nm "$objfile" | grep -i ' t ' | awk "/ $name\$/ {print \$1}" | head -n1) |
| 49 | + cache[$module,$name]="$base_addr" |
37 | 50 | fi |
38 | 51 | # Let's start doing the math to get the exact address into the |
39 | 52 | # symbol. First, strip out the symbol total length. |
@@ -48,12 +61,12 @@ parse_symbol() { |
48 | 61 | local address=$(printf "%x\n" "$expr") |
49 | 62 |
|
50 | 63 | # Pass it to addr2line to get filename and line number |
51 | | - # Could get more than one result |
52 | | - if [[ "${cache[$address]+isset}" == "isset" ]]; then |
53 | | - local code=${cache[$address]} |
| 64 | + # Could get more than one result |
| 65 | + if [[ "${cache[$module,$address]+isset}" == "isset" ]]; then |
| 66 | + local code=${cache[$module,$address]} |
54 | 67 | else |
55 | | - local code=$(addr2line -i -e "$vmlinux" "$address") |
56 | | - cache[$address]=$code |
| 68 | + local code=$(addr2line -i -e "$objfile" "$address") |
| 69 | + cache[$module,$address]=$code |
57 | 70 | fi |
58 | 71 |
|
59 | 72 | # addr2line doesn't return a proper error code if it fails, so |
@@ -105,13 +118,23 @@ handle_line() { |
105 | 118 | fi |
106 | 119 | done |
107 | 120 |
|
108 | | - # The symbol is the last element, process it |
109 | | - symbol=${words[$last]} |
| 121 | + if [[ ${words[$last]} =~ \[([^]]+)\] ]]; then |
| 122 | + module=${words[$last]} |
| 123 | + module=${module#\[} |
| 124 | + module=${module%\]} |
| 125 | + symbol=${words[$last-1]} |
| 126 | + unset words[$last-1] |
| 127 | + else |
| 128 | + # The symbol is the last element, process it |
| 129 | + symbol=${words[$last]} |
| 130 | + module= |
| 131 | + fi |
| 132 | + |
110 | 133 | unset words[$last] |
111 | 134 | parse_symbol # modifies $symbol |
112 | 135 |
|
113 | 136 | # Add up the line number to the symbol |
114 | | - echo "${words[@]}" "$symbol" |
| 137 | + echo "${words[@]}" "$symbol $module" |
115 | 138 | } |
116 | 139 |
|
117 | 140 | while read line; do |
@@ -121,8 +144,8 @@ while read line; do |
121 | 144 | handle_line "$line" |
122 | 145 | # Is it a code line? |
123 | 146 | elif [[ $line == *Code:* ]]; then |
124 | | - decode_code "$line" |
125 | | - else |
| 147 | + decode_code "$line" |
| 148 | + else |
126 | 149 | # Nothing special in this line, show it as is |
127 | 150 | echo "$line" |
128 | 151 | fi |
|