|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <string.h> |
| 4 | +#include "../callgrind.h" |
| 5 | + |
| 6 | +// Forward declarations |
| 7 | +void lib_function1(void); |
| 8 | +void lib_function2(void); |
| 9 | +void lib_function3(void); |
| 10 | + |
| 11 | +// Simple helper functions to do some work |
| 12 | +int compute_sum(int n) { |
| 13 | + int sum = 0; |
| 14 | + for (int i = 0; i < n; i++) { |
| 15 | + sum += i; |
| 16 | + } |
| 17 | + return sum; |
| 18 | +} |
| 19 | + |
| 20 | +// Functions that call library functions |
| 21 | +void lib_function1(void) { |
| 22 | + // Call strlen (from libc) |
| 23 | + const char *str = "test string"; |
| 24 | + int len = strlen(str); |
| 25 | + printf("String length: %d\n", len); |
| 26 | +} |
| 27 | + |
| 28 | +void lib_function2(void) { |
| 29 | + // Call malloc/free (from libc) |
| 30 | + int *ptr = (int *)malloc(sizeof(int) * 10); |
| 31 | + if (ptr) { |
| 32 | + for (int i = 0; i < 10; i++) { |
| 33 | + ptr[i] = i; |
| 34 | + } |
| 35 | + printf("Allocated and initialized 10 ints\n"); |
| 36 | + free(ptr); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +void lib_function3(void) { |
| 41 | + // Call printf directly |
| 42 | + printf("Direct printf call\n"); |
| 43 | +} |
| 44 | + |
| 45 | +int main(void) { |
| 46 | + printf("Starting plt_sec_test\n"); |
| 47 | + |
| 48 | + // Request callgrind to start collecting data |
| 49 | + CALLGRIND_START_INSTRUMENTATION; |
| 50 | + |
| 51 | + // Call functions that will use PLT/PLT.SEC |
| 52 | + lib_function1(); |
| 53 | + lib_function2(); |
| 54 | + lib_function3(); |
| 55 | + |
| 56 | + // Do some work |
| 57 | + int result = compute_sum(100); |
| 58 | + printf("Sum result: %d\n", result); |
| 59 | + |
| 60 | + // Request callgrind to dump stats |
| 61 | + CALLGRIND_DUMP_STATS; |
| 62 | + |
| 63 | + printf("plt_sec_test completed\n"); |
| 64 | + return 0; |
| 65 | +} |
0 commit comments