Debugging errors in our programs with strace
Translation of the original in Catalan. Read it in: CatalàCastellano
However much we defend the stability of our Linux systems, we have to be honest. Sometimes there is also the odd program that drives you to _____. In a few words, you are at the command line, you type the name of the program and suddenly it gives us back the command line without any message or anything at all. Or for those who use the X's, they run an icon and it says nothing at all....
Well, for these cases and many others linux gives us solutions that without being expert programmers we can provide. Solutions that often, not to say almost always, can be carried out without programming anything.
In my case this week mozilla drove me crazy, I didn't know why, I ran the mozilla mail and it starts loading and reading and there you go waiting and the process left the scheduling list and nothing was loading :(
So I got down to it, of course, the first thing was to check that there isn't any broken dependency of the binary. How do you do that with the command: ldd!!! even if you don't understand anything don't worry, if something doesn't work you will notice ;) because I would say that there is some dependency not found, which is the most important thing.
If that is correct the next thing could be to run strace. Basically what this program allows us to do is to trace the calls to the operating system that the software we run is making. The command line I like to use is:
strace -f -o nomfitxer.log programa
-f: if the program launches children in its execution process we will follow them all.
-o: redirects the output to a log file that we will examine later
programa: the executable of the program that is failing for us.
To understand strace you already have to know a little about programming and the internal structure of the operating system. But not too much either. Because 90% of the errors that normally occur are due to some file that is being opened and is not there or is failing. Therefore, the only thing we will have to look at in the always very long log file, will be the lines that try to open files (open) and the orders that try to read contents of files that have been opened (read).
If we look for all that we will see that normally there are erroneous function returns (-1) or erroneous status signals from the operating system towards the processes in execution (SIGV_TERM, SIGV_STOP, etc).
Well, with this the only thing I have done is surely to confuse you even more and fill your head with things that maybe don't even ring a bell, or that you no longer even remember, from when you were taught them at university. Anyway relax, I don't want to leave you like this, all this was the excuse to pass you a really cool mini-tutorial that I found reading the news on sourceforge, in fact the tutorial deals with the library problems of kde but you can apply it to any Linux program: