| Author |
Message |
8-bit

Joined: 03 Apr 2007 Posts: 3016 Location: Oregon
|
Posted: Sun 11 Apr 2010, 13:23 Post subject:
Finding programming errors is hard Subject description: Consider this a rant |
|
When writing a program in bash or gtkdialog3, the programmer sometimes has a bad time with errors as all errors are not shown when running the program from a terminal.
An error is shown. It might be a configuration file input error where the values you think are being passed are not.
It might be something else.
But fix one error and another that was not reported shows up.
I think some users really do not appreciate the effort that goes into writing a program, or for that matter, an OS that just works.
It is not as simple as it seems.
Rant ended.
|
|
Back to top
|
|
 |
DMcCunney
Joined: 02 Feb 2009 Posts: 894
|
Posted: Sun 11 Apr 2010, 14:16 Post subject:
Re: Programming errors Subject description: Consider this a rant |
|
| 8-bit wrote: | | When writing a program in bash or gtkdialog3, the programmer sometimes has a bad time with errors as all errors are not shown when running the program from a terminal. |
Bash programmers may wish to look at this: http://bashdb.sourceforge.net/
______
Dennis
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3016 Location: Oregon
|
Posted: Sun 11 Apr 2010, 17:06 Post subject:
Re: Programming errors Subject description: Consider this a rant |
|
| DMcCunney wrote: | | 8-bit wrote: | | When writing a program in bash or gtkdialog3, the programmer sometimes has a bad time with errors as all errors are not shown when running the program from a terminal. |
Bash programmers may wish to look at this: http://bashdb.sourceforge.net/
______
Dennis |
Maybe I downloaded the wrong file, but when I tried to compile it, it said bash in puppy was not a new enough version.
So I will see if an older version is offered.
|
|
Back to top
|
|
 |
big_bass

Joined: 13 Aug 2007 Posts: 1736
|
Posted: Sun 11 Apr 2010, 17:25 Post subject:
Re: Programming errors Subject description: Consider this a rant |
|
| 8-bit wrote: | | DMcCunney wrote: | | 8-bit wrote: | | When writing a program in bash or gtkdialog3, the programmer sometimes has a bad time with errors as all errors are not shown when running the program from a terminal. |
Bash programmers may wish to look at this: http://bashdb.sourceforge.net/
______
Dennis |
Maybe I downloaded the wrong file, but when I tried to compile it, it said bash in puppy was not a new enough version.
So I will see if an older version is offered. |
I compiled it awhile ago I think back on puppy 3.01
I havent used it since then
I just write in small sections at a time and echo out stuff to verify things
and with every edit make a new file so you can always go back to where it worked
I just wrote a package management tool I studied how it worked for months... before writing one line of code yes it is work but you gotta love it
make a dragN drop script for testing
| Code: |
#!/bin/bash
xterm -geometry 100x10+10+20 -e sh -x "$@" |
also you could also do this overkill but sometimes you need it
| Code: |
rxvt -geometry 90x30+650+40 -e /usr/bin/strace /usr/share/doc/gtkdialog3/examples/01.00-button |
where /usr/share/doc/gtkdialog3/examples/01.00-button
could be a bash script gtkdialog or whatever executble
Joe
_________________ slackware 14
Last edited by big_bass on Fri 30 Apr 2010, 13:45; edited 2 times in total
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4006 Location: Arizona, U.S.A.
|
Posted: Sun 11 Apr 2010, 17:28 Post subject:
|
|
It works... Now it doesn`t work... Oooooooo, where have I experienced that before?
|
|
Back to top
|
|
 |
Pizzasgood

Joined: 04 May 2005 Posts: 6270 Location: Knoxville, TN, USA
|
Posted: Mon 12 Apr 2010, 14:22 Post subject:
|
|
You can use the set -x command to enable debug mode (and set +x to disable it). Alternately, to enable it for the entire script, add the -x to the shebang, ala #!/bin/sh -x
That way the program will automatically echo some information about each command before it is executed, and expands all variables. That can help with figuring out what's going on.
_________________ Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib

|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3016 Location: Oregon
|
Posted: Mon 12 Apr 2010, 14:28 Post subject:
|
|
Thank you Pizzasgood!
Now that is a very useful piece of information.
One problem though.
Most of the time, that info is displayed and disappears before you can grasp it.
I will try it though.
|
|
Back to top
|
|
 |
RetroTechGuy

Joined: 15 Dec 2009 Posts: 2301 Location: USA
|
Posted: Mon 12 Apr 2010, 15:00 Post subject:
|
|
| 8-bit wrote: | Thank you Pizzasgood!
Now that is a very useful piece of information.
One problem though.
Most of the time, that info is displayed and disappears before you can grasp it.
I will try it though. |
You're working on the command line? Can you not scroll backwards with the mouse roller? (there is no scroll bar on the side, but it will roll back with the scroll function -- under 4.3.1, anyway).
I often expand the rxvt window to full screen, so it limits the number of wrapped lines.
You could alternatively redirect the errors to a log file of some sort.
|
|
Back to top
|
|
 |
Sit Heel Speak

Joined: 30 Mar 2006 Posts: 2595 Location: downwind
|
Posted: Mon 12 Apr 2010, 15:36 Post subject:
|
|
#!/bin/sh -e
makes the script halt on error and return to the command prompt.
Perhaps you could combine the two, i.e.
#!/bin/sh -e -x
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4006 Location: Arizona, U.S.A.
|
Posted: Mon 12 Apr 2010, 15:47 Post subject:
|
|
I`ve use Bash debugging, but so often you need to know the output or value of something.
Nothing replaces the good old "echo" command for really knowing what`s going on...
In Visual Basic you can "swipe highlight" a variable, equation, or an entire line to get it`s value.
And of course Basic`s : break, line watch, and stepping control. A "posh" environment...
|
|
Back to top
|
|
 |
DMcCunney
Joined: 02 Feb 2009 Posts: 894
|
Posted: Mon 12 Apr 2010, 20:04 Post subject:
|
|
| 8-bit wrote: | Thank you Pizzasgood!
Now that is a very useful piece of information.
One problem though.
Most of the time, that info is displayed and disappears before you can grasp it.
I will try it though. |
If bash write error messages to standard error, "sh -x script 2> error.log" should capture the error messages.
Alternatively, "sh -x script | tee script.log" should capture the output in script.log as well as showing it on screen.
______
Dennis
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Mon 12 Apr 2010, 20:25 Post subject:
|
|
if you want a gui if there are errors you can check if "`cat error.log`" != "" and then display it with Xdialog --infobox ...or something similar (xmessage, yafsplash...) the only problem is some commands that use stderr instead of stdout (ffmpeg comes to mind if I recall correctly)
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Pizzasgood

Joined: 04 May 2005 Posts: 6270 Location: Knoxville, TN, USA
|
Posted: Tue 13 Apr 2010, 19:33 Post subject:
|
|
You can scroll (even on the raw commandline w/o X) by pressing Shift and the Page Up or Page Down buttons. Useful sometimes.
_________________ Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib

|
|
Back to top
|
|
 |
prehistoric

Joined: 23 Oct 2007 Posts: 1210
|
Posted: Wed 14 Apr 2010, 09:00 Post subject:
combining error output, "state" |
|
| technosaurus wrote: | | ...the only problem is some commands that use stderr instead of stdout (ffmpeg comes to mind if I recall correctly) | If you want the error and standard output to be combined for debugging, you can, of course, append this to the command.
Although I am no longer actively programming, aging has taught me, by reducing my working memory, that errors in state-based reasoning are behind many bugs like those discussed here. If you are dealing with simple machines with a single program counter directly executing straight-forward machine code, the idea of state seems pretty simple. The x86 series is no longer so simple, even without complicated systems software.
By the time you get to distributed systems where different parts of the state are at different places, and accessed at different times, the concept of state is no longer simple. I have witnessed a room full of PhDs arguing about what one object in a distributed system "knew" about the state of another object. It sounded a lot like arguments about what is "really going on" in quantum mechanics and relativity.
Beware of code that places great demands on this kind of memory and understanding.
|
|
Back to top
|
|
 |
RetroTechGuy

Joined: 15 Dec 2009 Posts: 2301 Location: USA
|
Posted: Wed 14 Apr 2010, 17:18 Post subject:
Re: combining error output, "state" |
|
| prehistoric wrote: | | technosaurus wrote: | | ...the only problem is some commands that use stderr instead of stdout (ffmpeg comes to mind if I recall correctly) | If you want the error and standard output to be combined for debugging, you can, of course, append this to the command.
Although I am no longer actively programming, aging has taught me, by reducing my working memory, that errors in state-based reasoning are behind many bugs like those discussed here. If you are dealing with simple machines with a single program counter directly executing straight-forward machine code, the idea of state seems pretty simple. The x86 series is no longer so simple, even without complicated systems software.
By the time you get to distributed systems where different parts of the state are at different places, and accessed at different times, the concept of state is no longer simple. I have witnessed a room full of PhDs arguing about what one object in a distributed system "knew" about the state of another object. It sounded a lot like arguments about what is "really going on" in quantum mechanics and relativity.
Beware of code that places great demands on this kind of memory and understanding. |
Thanks Prehistoric. That jogged my memory... Which helped me find these:
http://www.linuxsa.org.au/tips/io-redirection.html
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
|
|
Back to top
|
|
 |
|