Debug a Program

Debug with terminal / console.
Linux about errors in the windows informs us very rarely. If you want to see what hurts the program you have to run it from the terminal/console a corresponding command.

Example:

$ ./blockattack_nonet.i386 ./blockattack_nonet.i386: error while loading shared libraries: libphysfs-1.0.so.0: cannot open shared object file: No such file or directory
 * I walk to the directory of the application.
 * I open terminal here.
 * I open application

This error says: application cannot find libphysfs-1.0.so.0 file. Now you can try searching for the answer or help on the forum http://www.pclinuxos.com/forum/index.php/board,19.0.html

We can try use command or search in google what package provide this library.

Command: apt-cache searchfile name_file

[gg@localhost ~]$ apt-cache searchfile libphysfs libphysfs-devel-2.0.3-1pclos2013: /usr/lib/libphysfs.so  libphysfs1.0-1.0.1-2pclos2007: /usr/lib/libphysfs-1.0.so.1 libphysfs1.0-1.0.1-2pclos2007: /usr/lib/libphysfs-1.0.so.1.0.0 libphysfs2-2.0.3-1pclos2013: /usr/lib/libphysfs.so.1 libphysfs2-2.0.3-1pclos2013: /usr/lib/libphysfs.so.2.0.3

Now we know two things.
 * 1) This lib should be in package libphysfs
 * 2) libphysfs package have files in /usr/lib/

On 64 bit systems this command maybe not will work very well, probably "index" package is stopped for repository, so I created own script apt3.sh, maybe help you. https://github.com/tele1/REPO

If missing lib exist in this package your problem is probably solved, you can install package and application should working. But in this case this library with this name not exist.

So if we don't have package with missed lib, we need install it. ( In this case, latest is libphysfs2-2.0.3-1pclos2013 )

But app still does not work because there is no needed file. Most similar files are:
 * libphysfs.so.2.0.3
 * libphysfs.so.1
 * libphysfs.so

You can try redirect application from libphysfs-1.0.so.0 to libphysfs.so.2.0.3
 * How do this ?

Try create symbolic link (click link if you don't know what it is) In this case.

cd /usr/lib ln -s libphysfs.so.2.0.3 libphysfs-1.0.so.0

Tips: Sometimes you need read documentation on package website which files link. ( example search home page physfs ) ( not lib-physfs, because lib is only suggestion --> " this is only library " )
 * If lib exist in old package but not in new,

Ok, In this case this application now working. :)

But what we can do if have installed missed lib ( with the same name ) but application don't working ? :(

You can try use strace or ltrace tool

Debug with strace command.
strace or ltrace -> this is very simple but useful debugging tool working in terminal, if you see from terminal error about missing dependencies / libs.


 * If you want use this tool you need install this first.

How use ?

Example: [gg@localhost ~]$ strace -e open firefox open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 open("/lib/i686/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3 open("/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3 open("/lib/i686/librt.so.1", O_RDONLY|O_CLOEXEC) = 3 open("/usr/lib/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3 open("/lib/i686/libm.so.6", O_RDONLY|O_CLOEXEC) = 3 . . . Now you know what libs in this example firefox use, and where this libs firefox looking. You can compare this with result "apt-cache searchfile" and if application looking lib in another place, you can create symbolic link to redirect lib.

How use this output with grep ?
Example: $ strace -e open firefox 2>&1 | grep font open("/usr/lib/libfontconfig.so.1", O_RDONLY|O_CLOEXEC) = 4 open("/usr/lib/libfontconfig.so.1.8.0", O_RDONLY) = 4 2>&1 this is redirection output you can more find about redirection in google, in bash tutorials, example http://www.tldp.org/LDP/abs/html/io-redirection.html

Other example: $ strace -y /usr/bin/firefox 2>&1 | grep acces | grep -v search | grep plugins access("/home/user_name/.mozilla/firefox/dqh2nb5k.default-1441864569209/plugins", F_OK) = -1 ENOENT (No such file or directory) access("/home/user_name/.mozilla/plugins", F_OK) = -1 ENOENT (No such file or directory) access("/usr/lib64/firefox/browser/plugins", F_OK) = -1 ENOENT (No such file or directory) access("/usr/lib/mozilla/plugins", F_OK) = 0

This example show paths where firefox searching plugins. This example working for firefox-41.0.2, in older firefox worked strace -e open firefox

Check on new user account.

 * Try create user account, and login to new user account, then try run program.
 * If program working, problem exist in settings in old user account.
 * You can try find and delete this settings file and reboot computer, or use new user account.

Useful link for KDE users: https://forum.kde.org/viewtopic.php?f=14&t=38828

Missing / empty icons.
try change theme, try change icons in system (sometimes package icons do not contain everything)

Useful commands.
How find name installed package.

You can check from Synaptic (Package Manager) You can also sometimes from shortcuts and from terminal, for example how find firefox $ rpm -qa | grep firefox firefox-41.0.2-1pclos2015

How list files from package.
$ rpm -ql firefox | grep "bin" /usr/bin/firefox /usr/bin/mozffremote /usr/bin/mozilla-firefox /usr/lib64/firefox/firefox-bin rpm -ql show all files from package, grep show from this output only lines which contain word "bin". You can list package like this, if you have installed.

How find package which provide path.
$ rpm -qf /usr/lib/os-probes/mounted/90linux-distro os-prober-1.65-2pclos2015 Some paths / files are not owned by any package, because sometimes packages contain commands which create files or folders and rpm not provide this paths.