Finding programming errors is hard

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

Finding programming errors is hard

#1 Post by 8-bit »

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.

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

Re: Programming errors

#2 Post by DMcCunney »

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

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

Re: Programming errors

#3 Post by 8-bit »

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.

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

Re: Programming errors

#4 Post by big_bass »

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 :shock: yes it is work but you gotta love it

make a dragN drop script for testing

Code: Select all

#!/bin/bash
xterm -geometry 100x10+10+20 -e sh -x "$@"



also you could also do this overkill but sometimes you need it

Code: Select all

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
Last edited by big_bass on Fri 30 Apr 2010, 17:45, edited 2 times in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#5 Post by sunburnt »

It works... Now it doesn`t work... Oooooooo, where have I experienced that before? :lol:

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#6 Post by Pizzasgood »

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.
[size=75]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[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#7 Post by 8-bit »

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.

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

#8 Post by RetroTechGuy »

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.

User avatar
Sit Heel Speak
Posts: 2595
Joined: Fri 31 Mar 2006, 03:22
Location: downwind

#9 Post by Sit Heel Speak »

#!/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

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#10 Post by sunburnt »

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...

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#11 Post by DMcCunney »

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

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#12 Post by technosaurus »

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)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#13 Post by Pizzasgood »

You can scroll (even on the raw commandline w/o X) by pressing Shift and the Page Up or Page Down buttons. Useful sometimes.
[size=75]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[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
prehistoric
Posts: 1744
Joined: Tue 23 Oct 2007, 17:34

combining error output, "state"

#14 Post by prehistoric »

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.

Code: Select all

2>&1
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.

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

Re: combining error output, "state"

#15 Post by RetroTechGuy »

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.

Code: Select all

2>&1
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

Post Reply