1. Introduction
•Logging (i.e., inserting print
statements or using logging
libraries to output information
about the program's state at
various points in the execution) is
commonly used by programmers
to debug their programs
•In addition, there are specific tools
(like GDB or Valgrind) for
debugging
Systems Architecture - 7. Debugging tools for C programs 4
#include <stdio.h>
int divide(int a, int b) {
printf("Entering divide function with a = %d, b = %d\n", a, b);
if (b == 0) {
fputs(stderr, "Error: Division by zero encountered.");
return 0;
}
int result = a / b;
printf("Division successful, result = %d\n", result);
return result;
}
int main() {
puts("* * * Program started * * *");
int x = 10;
int y = 2;
printf("Attempting to divide %d by %d\n", x, y);
int result1 = divide(x, y);
printf("Result of %d / %d = %d\n", x, y, result1);
puts("* * * Program ended * * *");
return 0;
}
* * * Program started * * *
Attempting to divide 10 by 2
Entering divide function with a = 10, b = 2
Division successful, result = 5
Result of 10 / 2 = 5
* * * Program ended * * *