我按照本手册使用bashdb:
http://archive09.linux.com/articles/153383.html#commentthis
当我使用bashdb来bt脚本时:

#!/bin/bash

version="0.01";

fibonacci() {
    n=${1:?If you want the nth fibonacci number, you must supply n as the first parameter.}
    if [ $n -le 1 ]; then
    echo $n
    else
    l=`fibonacci $((n-1))`
    r=`fibonacci $((n-2))`
    echo $((l + r))
    fi
}

for i in `seq 1 10`
do
  result=$(fibonacci $i)
  echo "i=$i result=$result"
done

下面是调试的细节:
kaiwii@ubuntu:~/shell_test$bash——调试器./fibonacci.sh
bashdb调试器,4.2-0.6版
Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

(/home/kaiwii/shell_test/fibonacci.sh:3):
3:  version="0.01";
bashdb<0> bt
->0 in file `./fibonacci.sh' at line 3
##1 main() called from file `./fibonacci.sh' at line 0
bashdb<1> next
(/home/kaiwii/shell_test/fibonacci.sh:16):
16: for i in `seq 1 10`
bashdb<2> list
 11:        r=`fibonacci $((n-2))`
 12:        echo $((l + r))
 13:        fi
 14:    }
 15:
 16: => for i in `seq 1 10`
 17:    do
 18:      result=$(fibonacci $i)
 19:      echo "i=$i result=$result"
 20:    done
bashdb<3> next
(/home/kaiwii/shell_test/fibonacci.sh:18):
18:   result=$(fibonacci $i)
bashdb<4> break fibonacci
Breakpoint 1 set in file /home/kaiwii/shell_test/fibonacci.sh, line 5.
bashdb<5> continue
i=1 result=1
i=2 result=1
i=3 result=2
i=4 result=3
i=5 result=5
i=6 result=8
i=7 result=13
i=8 result=21
i=9 result=34
i=10 result=55

我的问题是当我使用这个命令时,在使用完这个命令后继续,打破斐波那契
,它确实会在方法fibonacci的开头停止,但会退出脚本。

最佳答案

这是bashdb(4.2-0.8及以下版本)在处理“break”命令时的一个错误。
“next”命令设置一个标志,告诉bash跳过函数,而“break”命令没有清除这个标志。
git sources修复,所以如果你能使用它,这是修复的一种方法。
另一种方法是找到bashdb/lib/break.sh的安装位置(假设它在/usr/share/lib/bashdb/lib/break.sh中),并将下面的补丁保存在/tmp/bashdb.patch

--- bashdb/lib/break.sh
+++ bashdb/lib/break.sh
@@ -218,6 +218,11 @@ _Dbg_set_brkpt() {
     typeset dq_source_file
     dq_source_file=$(_Dbg_esc_dq "$source_file")
     typeset dq_condition=$(_Dbg_esc_dq "$condition")
+
+    # Make sure we are not skipping over functions.
+    _Dbg_old_set_opts="$_Dbg_old_set_opts -o functrace"
+    _Dbg_write_journal_eval "_Dbg_old_set_opts='$_Dbg_old_set_opts'"
+
     _Dbg_write_journal_eval "_Dbg_brkpt_line[$_Dbg_brkpt_max]=$lineno"
     _Dbg_write_journal_eval "_Dbg_brkpt_file[$_Dbg_brkpt_max]=\"$dq_source_file\""
     _Dbg_write_journal "_Dbg_brkpt_cond[$_Dbg_brkpt_max]=\"$dq_condition\""

然后作为根运行:
 # cd /usr/share/lib
 # patch -p0 < /tmp/bashdb.patch

关于linux - 如何在bashdb中使断点工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9580772/

10-10 17:52