As we seen in previous post “Understanding Very Minimal C Program and its execution in Ubuntu Linux” , we tried to understand the basic minimum C program. Here we will try to understand, how its actually getting executed, when we tried to run this program with debugging tool ltrace as below, ltrace is a “A library call tracer”,. ltrace is a program that simply runs the specified command until it exits.
Command line execution
gcc -o program_for_ltrace program_for_ltrace.c $ ltrace ./program_for_ltrace $ ltrace ./program_for_ltrace __libc_start_main(0x804840b, 1, 0xbf885c54, 0x8048480 <unfinished ...=""> printf("Sum of i & j is : %d\n", 35Sum of i & j is : 35 ) = 21 printf("sqrtof of 225 is : %d\n", 15sqrtof of 225 is : 15 ) = 22 +++ exited (status 0) +++ </unfinished> -c option in ltrace decode low-level symbol names into user-level names. $ ltrace -c ./program_for_ltrace Sum of i & j is : 35 sqrtof of 225 is : 15 % time seconds usecs/call calls function ------ ----------- ----------- --------- -------------------- 100.00 0.000577 288 2 printf ------ ----------- ----------- --------- -------------------- 100.00 0.000577 2 total For other command line arguments to try, check using “ltrace –help”Implementation details
It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls executed by the program. $ vim program_for_ltrace.c #include <stdio.h> #include <math.h> int main(int argc, char **argv) { int i=10, j=25, sqrtof=0; printf("Sum of i and j is : %d\n", i+j); sqrtof = sqrt(225.0); printf("sqrtof of 225 is : %d\n", sqrtof); return 0; } $ gcc -o program_for_ltrace program_for_ltrace.c $ ltrace ./program_for_ltrace $ ltrace ./program_for_ltrace __libc_start_main(0x804840b, 1, 0xbf885c54, 0x8048480 <unfinished ...=""> printf("Sum of i & j is : %d\n", 35Sum of i & j is : 35 ) = 21 printf("sqrtof of 225 is : %d\n", 15sqrtof of 225 is : 15 ) = 22 +++ exited (status 0) +++ </unfinished> -c option in ltrace decode low-level symbol names into user-level names. $ ltrace -c ./program_for_ltrace Sum of i & j is : 35 sqrtof of 225 is : 15 % time seconds usecs/call calls function ------ ----------- ----------- --------- -------------------- 100.00 0.000577 288 2 printf ------ ----------- ----------- --------- -------------------- 100.00 0.000577 2 total For other command line arguments to try, check using “ltrace –help”
Gotchas and common issues
Permission checks - verify user access rights and sudo privileges before executing system-level operations.
Environment configuration - double-check path variables and dependency versions to prevent runtime failures.
Backup safeguards - maintain configuration backups before applying system or database modifications.
Following these steps ensures clean configuration and reliable execution for understanding execution and debugging of c program using ltrace.
Comments and corrections