Menu

#43 Run/Restart brings up bashdb source instead of the script source when used after "set args"

v1.0_(example)
open
nobody
None
5
2016-12-10
2016-12-10
No

Considering the following simple script called ".drive-find-gd" which accepts a parameter, searches for a special folder & prints it::

#!/bin/bash
folder=$1

cd $folder
while [[ "$(pwd)" != / ]]
do
        if [[ -n $(find . -name  ".gd") ]]; then
                echo "$(pwd)"
                break
        else
                cd ..
        fi
done

Loading it and running it without "set args ..."

bashdb /usr/bin/.drive-find-gd 
bash debugger, bashdb, release 4.4-0.92
...
(/usr/bin/.drive-find-gd:55):
55: folder=$1
bashdb<0> l
 53:    #!/bin/bash
 54:    
 55: => folder=$1
 56:    
 57:    cd $folder
 58:    
 59:    while [[ "$(pwd)" != / ]]
bashdb<1> run
Restarting with: /bin/bashdb /usr/bin/.drive-find-gd 
/usr/share/share/bashdb/command/run.sh: line 78: cd: too many arguments
...
(/usr/bin/.drive-find-gd:55):
55: folder=$1
bashdb<0> l
 53:    #!/bin/bash
 54:    
 55: => folder=$1
 56:    
 57:    cd $folder
 58:    
 59:    while [[ "$(pwd)" != / ]]

As we can see, the same right script has been loaded: ".drive-find-gd"
Now, if we call "set args ..." inside the same script:

bashdb<0> l
 53:    #!/bin/bash
 54:    
 55: => folder=$1
 56:    
 57:    cd $folder
 58:    
 59:    while [[ "$(pwd)" != / ]]
bashdb<1> set args "/home/actionmystique"
bashdb<2> run
***Restarting with: /bin/bashdb /home/actionmystique*** 
/usr/share/share/bashdb/command/run.sh: line 78: cd: too many arguments
bash debugger, bashdb, release 4.4-0.92
...
/bin/bashdb: line 96: .: /home/actionmystique: is a directory
(/bin/bashdb:1):
1:  #!/bin/bash
bashdb<0> l
  1: => #!/bin/bash
  2:    # -*- shell-script -*-
  3:    # Top-level debugger program. This program may be initially invoked.
  4:    #
  5:    #   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 
  6:    #   2009, 2010, 2011 Rocky Bernstein <rocky@gnu.org>
  7:    #
  8:    #   This program is free software; you can redistribute it and/or
  9:    #   modify it under the terms of the GNU General Public License as
 10:    #   published by the Free Software Foundation; either version 2, or

As we can see here, run restarts the wrong script "Restarting with: /bin/bashdb /home/actionmystique" instead of 'Restarting with: /bin/bashdb /usr/bin/.drive-find-gd".
The issue seems obvious: bashdb replaces the original script name (/usr/bin/.drive-find-gd) by the argument entered in "set args": /home/actionmystique which is not a script but a path in this example.
Since bashdb realizes that "/home/actionmystique" is not a script but a folder, it triggers an internal error and it restarts at its first instruction.

Discussion

  • Rocky Bernstein

    Rocky Bernstein - 2016-12-10

    I think what is going on here is that bashdb needs to figure out where the split between the debugged program and its arguments lie. If it is invoked via bashdb, the script name lies after any bashdb optioons.

    However if the debugger was invoked via bash --debugger that is not the case.

    I probably won't have time address this in the near term. If you want to try to fix this you'd look at flle bashdb/command/run.sh which would include out a new variable like script_name in exec_cmd_prefix and in setting _Dbg_script_args in bashdb.in.

     
  • Rocky Bernstein

    Rocky Bernstein - 2016-12-10

    A workaround for now is to include the script name in set args when it was invoked via bashdb.

     
  • Jean-christophe Manciot

    Thanks for the workaround.

     

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.