Menu

#11 `ev`/`ev?` evaluation issues

1.0
open
nobody
None
2021-08-03
2021-06-22
stdedos
No
  1. if test -z "$a" ; then
  2. if grep -qF "bummer" <<< 'a' ; then
  3. elif [ 'a' != 'b' ] ; then

There seems to be some error with the exit code tracking:

bashdb<6> ev [ ! "${DO_NOT_TRACK:-0}" -eq 0 ]
$? is 0
bashdb<7> ev [ ! "${DO_NOT_TRACK:-0}" -eq 0 ]; echo $?
1
$? is 0

Discussion

  • Rocky Bernstein

    Rocky Bernstein - 2021-06-22

    This is open-source code and bash is pretty simple to debug. Feel free to investigate and put in a patch.

     
  • Roland Christmann

    --- a/command/eval.sh
    +++ b/command/eval.sh
    @@ -99,7 +99,6 @@
         else
            builtin echo -e "$@" >> "$_Dbg_evalfile"
         fi
    -    builtin echo "BASH_ARGV0=$_Dbg_dollar_0" >> "$_Dbg_evalfile"
         if [[ -n "$_Dbg_tty"  ]] ; then
            . "$_Dbg_evalfile" >>"$_Dbg_tty"
         else
    
     

    Last edit: Roland Christmann 2021-07-08
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-08

    This doesn't seem like a proper fix in that it may address one problem but cause another. The purpose of that line is to save the value of $0 so that it can be restored when returning from the debugger.

     
  • Roland Christmann

    Do you have any idea how to solve that ?

     

    Last edit: Roland Christmann 2021-07-08
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-08

    Probably saving and restoring the return code value.

     
  • Roland Christmann

    Sorry but I have no access to the patch section.

    This way the value of $0 is saved and the expression is correctly evaluated because it must be the last line of _$Dbg_evalfilefile.

    --- a/eval.sh   2021-07-09 09:54:45.914323785 +0200
    +++ b/eval.sh   2021-07-09 14:29:51.541083049 +0200
    @@ -71,6 +71,7 @@
     _Dbg_do_eval() {
    
         builtin echo ". ${_Dbg_libdir}/set-d-vars.sh" > "$_Dbg_evalfile"
    +    builtin echo "BASH_ARGV0=\"$_Dbg_dollar_0\"" >> "$_Dbg_evalfile"
         if (( $# == 0 )) ; then
            # FIXME: add parameter to get unhighlighted line, or
            # always save a copy of that in _Dbg_get_source_line
    @@ -99,7 +100,6 @@
         else
            builtin echo -e "$@" >> "$_Dbg_evalfile"
         fi
    -    builtin echo "BASH_ARGV0=\"$_Dbg_dollar_0\"" >> "$_Dbg_evalfile"
         if [[ -n "$_Dbg_tty"  ]] ; then
            . "$_Dbg_evalfile" >>"$_Dbg_tty"
         else
    
     

    Last edit: Roland Christmann 2021-07-12
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-11

    Ok - I agree that this code is bettter. But it doesn't change the behavior of the example at the very beginning.

    It would be great to add a test to show how the current version fails and this revised version fixes that.

     
  • Roland Christmann

    The current version will always return 0
    The expression evaluates the assignment of a variable (BASH_ARGV0 in this case) which is always true.

     
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-11

    Would you please write a test case in that can be run that fails with the current code, and succeeds after this patch is changed.?

     
  • Roland Christmann

    I am learning how to write a test case, it's the first time ...

     

    Last edit: Roland Christmann 2021-07-12
  • Roland Christmann

     

    Last edit: Roland Christmann 2021-07-12
  • Roland Christmann

    move to bug #71

     

    Last edit: Roland Christmann 2021-07-12
  • Roland Christmann

    move to bug #71

     

    Last edit: Roland Christmann 2021-07-12
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-11

    Commits 28d4d2f and 2359ac3 should now have these patches. Thanks!

    Automated tests need to be written sometime before release.

    Also please make each separate bug be separate. This helps track progress of individual bugs. Thanks again.

     
  • Roland Christmann

    before the lib/fns.sh patch :
    /data/projects/bashdb-5.1/test/unit # ./test-eval.sh
    test_eval_subst
    ASSERT:expected:<(( x == 1 ))> but was:<if (( x == 1 )); then>
    ASSERT:expected:<test -z "$x" > but was:<est -z "$x" >
    Ran 1 test. 12 assert(s): 10 passed, 2 failed, 0 skipped.
    FAILED (failures=2)

    after the lib/fns.sh patch :
    /data/projects/bashdb-5.1/test/unit # ./test-eval.sh
    test_eval_subst
    Ran 1 test. 12 assert(s): 12 passed, 0 failed, 0 skipped.
    OK

    Please modify the patch with <tab> instead of spaces for these two lines :</tab>

    +       '<TAB>if (( x == 1 )); then'
    +       'if (( x == 1 ));<TAB>then'
    

    The same patch should also be applied on test-lib-eval.sh.in

    --- a/test-eval.sh.in      2021-07-12 10:02:19.275225203 +0200
    +++ b/test-eval.sh.in      2021-07-12 10:32:45.074288089 +0200
    @@ -8,10 +8,13 @@
         typeset -a texts
         texts=(
            'if (( x == 1 )); then'
    +       '       if (( x == 1 )); then'
    +       'if (( x == 1 ));       then'
            'if (( y == 2 )) ; then'
            'if (( y == 3 )) ;'
            'if (( y == 4 ))'
            'if (( z == 5 ))   '
    +       'if test -z "$x" ; then'
            'return something'
            'elif [[ $x = test1 ]] && [ $? -eq 0 ] ; then'
            'while [[ $x = test2 ]] && [ $? -eq 0 ] ; do'
    @@ -20,10 +23,13 @@
    
         expected=(
            '(( x == 1 ))'
    +       '(( x == 1 ))'
    +       '(( x == 1 ))'
            '(( y == 2 )) '
            '(( y == 3 )) '
            '(( y == 4 ))'
            '(( z == 5 ))   '
    +        'test -z "$x" '
            'echo something'
            '[[ $x = test1 ]] && [ $? -eq 0 ] '
            '[[ $x = test2 ]] && [ $? -eq 0 ] '
    
     
  • Roland Christmann

    I don't see any difference between these two files :

    --- test-eval.sh.in
    +++ test-lib-eval.sh.in
    @@ -67,6 +67,6 @@
     # Make sure $abs_top_srcdir has a trailing slash
     abs_top_srcdir=${abs_top_srcdir%%/}/
     . ${abs_top_srcdir}test/unit/helper.sh
    -. $abs_top_srcdir/lib/fns.sh
    +. ${abs_top_srcdir}/lib/fns.sh
     set -- # reset $# so shunit2 doesn't get confused.
     [[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
    
     
    • Rocky Bernstein

      Rocky Bernstein - 2021-07-13

      Commit 4d33360e8fd75b217963fbafbbfed29bafc19e1f removes this.

       
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-12

    Yes, test-lib-eval.sh.in is the newer, more precise name while test-eval.sh was the older name. The newer name is only found in zshdb for example.

    Thanks - I'll clean this up when I get a chance.

     
  • Roland Christmann

    very nice work, thanks for all.

     
    • Rocky Bernstein

      Rocky Bernstein - 2021-07-13

      As you have noticed, while still serviceable, (and as far as I know it is the only serious debugger for bash ever written), has signs of age.

      It was written before bash had, for example, associative arrays and some of this may still be reflected in library code. I really haven't been keeping up to date bash or with its more recent additions like the introduction of regular expression character classes. (Again, when this was first written there were no regular expressions at all.)

      At this point, that this is kept alive or current at is up to those willing to contribute to it.

      For myself, I rarely have need to use it beyond what is already there.

       
  • stdedos

    stdedos - 2021-07-27

    This was fixed in 28d4d2 and broken (again) with the 9a0bf97 ...

    ev false
    $? is 0
    

    😕

     
  • Roland Christmann

    The debugger is working fine, but unfortunately it doesn't work like you want it to work ...

    test_eval

    1  #!/usr/bin/env bash
    2
    3  a=false
    4  if $a ; then echo true; else echo false; fi
    5  a=true
    6  if $a ; then echo true; else echo false; fi
    

    $ bashdb -- test_eval

    bash debugger, bashdb, release 5.1-1.1.2

    Copyright 2002-2004, 2006-2012, 2014, 2016-2019, 2021 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.

    (test_eval:3):
    3: a=false
    bashdb<0> n
    (test_eval:4):
    4: if $a ; then echo true; else echo false; fi
    bashdb<1> ev?
    eval: $a
    $? is 1
    bashdb<2> n
    (test_eval:4):
    4: if $a ; then echo true; else echo false; fi
    echo false
    bashdb<3> n
    false
    (test_eval:5):
    5: a=true
    bashdb<4> n
    (test_eval:6):
    6: if $a ; then echo true; else echo false; fi
    bashdb<5> ev?
    eval: $a
    $? is 0
    bashdb<6> n
    (test_eval:6):
    6: if $a ; then echo true; else echo false; fi
    echo true
    bashdb<7> q
    bashdb: That's all, folks...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.