Now that stacktraces contain the build ID information we can update this script to use debuginfod-find to locate the debuginfo for the vmlinux and modules automatically. This can replace the existing code that requires specifying a path to vmlinux or tries to find the vmlinux and modules automatically by using the release number. Work it into the script as a fallback option if the vmlinux isn't specified on the commandline.
Showing the changes to scripts/decode_stacktrace.sh (1 of 1 file). Show all
Unified · Split
| @@ -3,11 +3,10 @@ · 2 unmodified lines | ||
| 3 | 3 | # (c) 2014, Sasha Levin <sasha.levin@oracle.com> |
| 4 | 4 | #set -x |
| 5 | 5 | |
| 6 | −if [[ $# < 1 ]]; then | |
| 6 | +usage() { | |
| 7 | 7 | echo "Usage:" |
| 8 | 8 | echo " $0 -r <release> | <vmlinux> [base path] [modules path]" |
| 9 | − exit 1 | |
| 10 | −fi | |
| 9 | +} | |
| 11 | 10 | |
| 12 | 11 | if [[ $1 == "-r" ]] ; then |
| 13 | 12 | vmlinux="" |
| @@ -24,6 +23,7 @@ if [[ $1 == "-r" ]] ; then · 10 unmodified lines | ||
| 24 | 23 | |
| 25 | 24 | if [[ $vmlinux == "" ]] ; then |
| 26 | 25 | echo "ERROR! vmlinux image for release $release is not found" >&2 |
| 26 | + usage | |
| 27 | 27 | exit 2 |
| 28 | 28 | fi |
| 29 | 29 | else |
| @@ -31,12 +31,35 @@ else · 1 unmodified line | ||
| 31 | 31 | basepath=${2-auto} |
| 32 | 32 | modpath=$3 |
| 33 | 33 | release="" |
| 34 | + debuginfod= | |
| 35 | + | |
| 36 | + # Can we use debuginfod-find? | |
| 37 | + if type debuginfod-find >/dev/null 2>&1 ; then | |
| 38 | + debuginfod=${1-only} | |
| 39 | + fi | |
| 40 | + | |
| 41 | + if [[ $vmlinux == "" && -z $debuginfod ]] ; then | |
| 42 | + echo "ERROR! vmlinux image must be specified" >&2 | |
| 43 | + usage | |
| 44 | + exit 1 | |
| 45 | + fi | |
| 34 | 46 | fi |
| 35 | 47 | |
| 36 | 48 | declare -A cache |
| 37 | 49 | declare -A modcache |
| 38 | 50 | |
| 39 | 51 | find_module() { |
| 52 | + if [[ -n $debuginfod ]] ; then | |
| 53 | + if [[ -n $modbuildid ]] ; then | |
| 54 | + debuginfod-find debuginfo $modbuildid && return | |
| 55 | + fi | |
| 56 | + | |
| 57 | + # Only using debuginfod so don't try to find vmlinux module path | |
| 58 | + if [[ $debuginfod == "only" ]] ; then | |
| 59 | + return | |
| 60 | + fi | |
| 61 | + fi | |
| 62 | + | |
| 40 | 63 | if [[ "$modpath" != "" ]] ; then |
| 41 | 64 | for fn in $(find "$modpath" -name "${module//_/[-_]}.ko*") ; do |
| 42 | 65 | if readelf -WS "$fn" | grep -qwF .debug_line ; then |
| @@ -150,6 +173,27 @@ parse_symbol() { · 107 unmodified lines | ||
| 150 | 173 | symbol="$segment$name ($code)" |
| 151 | 174 | } |
| 152 | 175 | |
| 176 | +debuginfod_get_vmlinux() { | |
| 177 | + local vmlinux_buildid=${1##* } | |
| 178 | + | |
| 179 | + if [[ $vmlinux != "" ]]; then | |
| 180 | + return | |
| 181 | + fi | |
| 182 | + | |
| 183 | + if [[ $vmlinux_buildid =~ ^[0-9a-f]+ ]]; then | |
| 184 | + vmlinux=$(debuginfod-find debuginfo $vmlinux_buildid) | |
| 185 | + if [[ $? -ne 0 ]] ; then | |
| 186 | + echo "ERROR! vmlinux image not found via debuginfod-find" >&2 | |
| 187 | + usage | |
| 188 | + exit 2 | |
| 189 | + fi | |
| 190 | + return | |
| 191 | + fi | |
| 192 | + echo "ERROR! Build ID for vmlinux not found. Try passing -r or specifying vmlinux" >&2 | |
| 193 | + usage | |
| 194 | + exit 2 | |
| 195 | +} | |
| 196 | + | |
| 153 | 197 | decode_code() { |
| 154 | 198 | local scripts=`dirname "${BASH_SOURCE[0]}"` |
| 155 | 199 | |
| @@ -157,6 +201,14 @@ decode_code() { · 1 unmodified line | ||
| 157 | 201 | } |
| 158 | 202 | |
| 159 | 203 | handle_line() { |
| 204 | + if [[ $basepath == "auto" && $vmlinux != "" ]] ; then | |
| 205 | + module="" | |
| 206 | + symbol="kernel_init+0x0/0x0" | |
| 207 | + parse_symbol | |
| 208 | + basepath=${symbol#kernel_init (} | |
| 209 | + basepath=${basepath%/init/main.c:*)} | |
| 210 | + fi | |
| 211 | + | |
| 160 | 212 | local words |
| 161 | 213 | |
| 162 | 214 | # Tokenize |
| @@ -182,16 +234,28 @@ handle_line() { · 19 unmodified lines | ||
| 182 | 234 | fi |
| 183 | 235 | done |
| 184 | 236 | |
| 237 | + if [[ ${words[$last]} =~ ^[0-9a-f]+\] ]]; then | |
| 238 | + words[$last-1]="${words[$last-1]} ${words[$last]}" | |
| 239 | + unset words[$last] | |
| 240 | + last=$(( $last - 1 )) | |
| 241 | + fi | |
| 242 | + | |
| 185 | 243 | if [[ ${words[$last]} =~ \[([^]]+)\] ]]; then |
| 186 | 244 | module=${words[$last]} |
| 187 | 245 | module=${module#\[} |
| 188 | 246 | module=${module%\]} |
| 247 | + modbuildid=${module#* } | |
| 248 | + module=${module% *} | |
| 249 | + if [[ $modbuildid == $module ]]; then | |
| 250 | + modbuildid= | |
| 251 | + fi | |
| 189 | 252 | symbol=${words[$last-1]} |
| 190 | 253 | unset words[$last-1] |
| 191 | 254 | else |
| 192 | 255 | # The symbol is the last element, process it |
| 193 | 256 | symbol=${words[$last]} |
| 194 | 257 | module= |
| 258 | + modbuildid= | |
| 195 | 259 | fi |
| 196 | 260 | |
| 197 | 261 | unset words[$last] |
| @@ -201,14 +265,6 @@ handle_line() { · 3 unmodified lines | ||
| 201 | 265 | echo "${words[@]}" "$symbol $module" |
| 202 | 266 | } |
| 203 | 267 | |
| 204 | −if [[ $basepath == "auto" ]] ; then | |
| 205 | − module="" | |
| 206 | − symbol="kernel_init+0x0/0x0" | |
| 207 | − parse_symbol | |
| 208 | − basepath=${symbol#kernel_init (} | |
| 209 | − basepath=${basepath%/init/main.c:*)} | |
| 210 | −fi | |
| 211 | − | |
| 212 | 268 | while read line; do |
| 213 | 269 | # Let's see if we have an address in the line |
| 214 | 270 | if [[ $line =~ \[\<([^]]+)\>\] ]] || |
| @@ -218,6 +274,9 @@ while read line; do · 3 unmodified lines | ||
| 218 | 274 | # Is it a code line? |
| 219 | 275 | elif [[ $line == *Code:* ]]; then |
| 220 | 276 | decode_code "$line" |
| 277 | + # Is it a version line? | |
| 278 | + elif [[ -n $debuginfod && $line =~ PID:\ [0-9]+\ Comm: ]]; then | |
| 279 | + debuginfod_get_vmlinux "$line" | |
| 221 | 280 | else |
| 222 | 281 | # Nothing special in this line, show it as is |
| 223 | 282 | echo "$line" |