diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2010-01-26 09:57:14 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2010-01-26 09:57:14 +0000 |
commit | 856449d0e56dc45cf354e62810ce65feaeacedf9 (patch) | |
tree | fdd7e3b600cc53a4906fa415ae45a168bd1a802a /drivers | |
parent | 4276bdd18c3d3e1552c08c7b3636dfd5a733cf63 (diff) |
xpp_debug: a helper script to use debugging parameters with names.
(not intended to be installed)
git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@7964 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers')
-rwxr-xr-x | drivers/dahdi/xpp/xpp_debug | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/drivers/dahdi/xpp/xpp_debug b/drivers/dahdi/xpp/xpp_debug new file mode 100755 index 0000000..a3b7047 --- /dev/null +++ b/drivers/dahdi/xpp/xpp_debug @@ -0,0 +1,110 @@ +#! /bin/sh +# +# xpp_debug: Turn on/off debugging flags via /sys/module/*/parameters/debug +# + +modules="xpp xpp_usb xpd_fxs xpd_fxo xpd_bri xpd_pri" +dbg_names="DEFAULT PCM LEDS SYNC SIGNAL PROC REGS DEVICES COMMANDS" + +usage() { + echo 1>&2 "Usage: $0 [module_name] [[-]flags...]" + echo 1>&2 " module_name => $modules" + echo 1>&2 " flags => NONE $dbg_names ANY" + echo 1>&2 "" + echo 1>&2 " Example: $0 xpp ANY -PCM -LEDS" + echo 1>&2 "" +} + +sysfs_name() { + f='' + if [ -f "/sys/module/$1/parameters/debug" ]; then + f="/sys/module/$1/parameters/debug" + elif [ -f "/sys/module/$1/debug" ]; then + f="/sys/module/$1/debug" + fi + echo "$f" +} + +sysfs_value() { + f=`sysfs_name "$1"` + if [ "$f" != "" ]; then + cat "$f" + fi +} + +show_debug() { + usage + for i in $modules + do + f=`sysfs_name "$i"` + if [ -f "$f" ]; then + val=`cat $f` + j=0 + list='' + for n in $dbg_names + do + if (( val & (1 << j) )) + then + list="$list $n" + fi + let j++ + done + if [ "$list" = "" ]; then + list=' NONE' + fi + echo "$i $list" + fi + done +} + +calc_debug() { + val="$1" + shift + for wanted in $* + do + j=0 + found=0 + for n in $dbg_names + do + if [ "$wanted" = "$n" ]; then + (( val |= (1 << j) )) + found=1 + elif [ "$wanted" = -"$n" ]; then + (( val &= ~(1 << j) )) + found=1 + elif [ "$wanted" = "ANY" ]; then + (( val = ~0 )) + found=1 + elif [ "$wanted" = -"ANY" -o "$wanted" = "NONE" ]; then + (( val = 0 )) + found=1 + fi + let j++ + done + if [ "$found" -eq 0 ]; then + echo >&2 "$0: Unkown debug flag '$wanted'" + exit 1 + fi + done + echo $val +} + +if [ "$#" = 0 ]; then + show_debug + exit 0 +fi + +module="$1" +shift + +if ! echo "$modules" | grep -w "$module" > /dev/null; then + echo >&2 "$0: Unkown module $module" + exit 1 +fi + +oldval=`sysfs_value "$module"` +val=`calc_debug "$oldval" $*` +file=`sysfs_name $module` + +echo "$val" > "$file" +show_debug |