Flevo CFD

Quick Debugging of Programs in Linux

In Linux, to inspect what a program is doing, which files it is accessing, etc., and overall, to debug it to identify where the issue lies, you can use GDB (GNU Debugger) and strace.

The following command is generally used for launching your program

1
gdb -ex r --args {program name} {program argument} {program argument} ...

For example

1
2
gdb -ex r --args python3.6 main.py
gdb -ex r --args mysql -uroot -proot

Here, -ex executes a GDB command, and we specify r to run the program until it encounters an error or a breakpoint.

--args indicates that the variables after the program name should be passed as arguments to the program. If the program does not take any arguments, you can omit this switch.

Another useful program is strace which shows the system calls that program does

1
strace python main.py