1*1f5207b7SJohn Levon#!/bin/bash 2*1f5207b7SJohn Levon 3*1f5207b7SJohn Levoncontext=6 4*1f5207b7SJohn Levonwhile true ; do 5*1f5207b7SJohn Levon if [ "$1" = "-C" ] ; then 6*1f5207b7SJohn Levon shift 7*1f5207b7SJohn Levon context=$1 8*1f5207b7SJohn Levon shift 9*1f5207b7SJohn Levon continue 10*1f5207b7SJohn Levon fi 11*1f5207b7SJohn Levon if [ "$1" = "-k" ] ; then 12*1f5207b7SJohn Levon shift 13*1f5207b7SJohn Levon mode=kernel 14*1f5207b7SJohn Levon continue 15*1f5207b7SJohn Levon fi 16*1f5207b7SJohn Levon if [ "$1" = "-b" ] ; then 17*1f5207b7SJohn Levon shift 18*1f5207b7SJohn Levon nobreak=yes 19*1f5207b7SJohn Levon continue 20*1f5207b7SJohn Levon fi 21*1f5207b7SJohn Levon break 22*1f5207b7SJohn Levondone 23*1f5207b7SJohn Levon 24*1f5207b7SJohn Levon 25*1f5207b7SJohn Levonfile=$1 26*1f5207b7SJohn Levonif [[ "$file" = "" ]] ; then 27*1f5207b7SJohn Levon echo "Usage: $0 [-C <lines>] [-b] [-k] <file with smatch messages>" 28*1f5207b7SJohn Levon echo " -C <lines>: Print <lines> of context" 29*1f5207b7SJohn Levon echo " -b : Ignore unreachable break statements" 30*1f5207b7SJohn Levon echo " -k : Ignore some kernel defines" 31*1f5207b7SJohn Levon exit 1 32*1f5207b7SJohn Levonfi 33*1f5207b7SJohn Levon 34*1f5207b7SJohn Levonkernel_ignore_functions="DLM_ASSERT 35*1f5207b7SJohn LevonBT_SI_SM_RETURN 36*1f5207b7SJohn LevonBT_STATE_CHANGE 37*1f5207b7SJohn LevonPARSE_ERROR1 38*1f5207b7SJohn LevonPARSE_ERROR 39*1f5207b7SJohn LevonCMDINSIZE 40*1f5207b7SJohn LevonPROCESS_SYSTEM_PARAM 41*1f5207b7SJohn LevonRETURN_STATUS 42*1f5207b7SJohn Levonar9170_regwrite_result 43*1f5207b7SJohn Levonmodule_put_and_exit 44*1f5207b7SJohn LevonSEG32 45*1f5207b7SJohn LevonCASE_PIPExTRE 46*1f5207b7SJohn Levon" 47*1f5207b7SJohn Levon 48*1f5207b7SJohn Levongrep 'ignoring unreachable' $file | cut -d ' ' -f1 | while read loc; do 49*1f5207b7SJohn Levon code_file=$(echo $loc | cut -d ':' -f 1) 50*1f5207b7SJohn Levon line=$(echo $loc | cut -d ':' -f 2) 51*1f5207b7SJohn Levon 52*1f5207b7SJohn Levon if [ "$mode" = "kernel" ] ; then 53*1f5207b7SJohn Levon # BUG() is sometimes defined away on embedded systems 54*1f5207b7SJohn Levon if tail -n +$(($line - 1)) $code_file | head -n 1 | \ 55*1f5207b7SJohn Levon egrep -qw '(BUG|BT_STATE_CHANGE)' ; then 56*1f5207b7SJohn Levon continue; 57*1f5207b7SJohn Levon fi 58*1f5207b7SJohn Levon skip=0 59*1f5207b7SJohn Levon line_txt=$(tail -n +$(($line)) $code_file | head -n 1) 60*1f5207b7SJohn Levon for func in $kernel_ignore_functions ; do 61*1f5207b7SJohn Levon if echo "$line_txt" | egrep -qw $func ; then 62*1f5207b7SJohn Levon skip=1 63*1f5207b7SJohn Levon break 64*1f5207b7SJohn Levon fi 65*1f5207b7SJohn Levon done 66*1f5207b7SJohn Levon if [ "$skip" == 1 ] ; then 67*1f5207b7SJohn Levon continue 68*1f5207b7SJohn Levon fi 69*1f5207b7SJohn Levon fi 70*1f5207b7SJohn Levon 71*1f5207b7SJohn Levon if [ "$nobreak" = "yes" ] ; then 72*1f5207b7SJohn Levon if tail -n +$(($line)) $code_file | head -n 1 | grep -qw 'break' ; then 73*1f5207b7SJohn Levon continue; 74*1f5207b7SJohn Levon fi 75*1f5207b7SJohn Levon 76*1f5207b7SJohn Levon fi 77*1f5207b7SJohn Levon echo "=========================================================" 78*1f5207b7SJohn Levon echo $code_file:$line 79*1f5207b7SJohn Levon tail -n +$(($line - ($context - 1))) $code_file | head -n $(($context - 1)) 80*1f5207b7SJohn Levon echo "---------------------------------------------------------" 81*1f5207b7SJohn Levon tail -n +${line} $code_file | head -n $context 82*1f5207b7SJohn Levondone 83*1f5207b7SJohn Levon 84