This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangyang-variable-monitor/testcase/userstack.c

66 lines
1.5 KiB
C
Raw Normal View History

2023-11-21 04:43:30 -05:00
#include <stdio.h>
2023-12-04 22:49:57 -05:00
// #include <libunwind.h>
2023-11-21 04:43:30 -05:00
#include <unistd.h>
void customFunction1(int n);
void customFunction2(int n);
void customFunction3(int n);
2023-11-22 21:14:15 -05:00
// Call this function to get a backtrace.
2023-12-04 22:49:57 -05:00
// void backtrace() {
// unw_cursor_t cursor;
// unw_context_t context;
2023-11-22 21:14:15 -05:00
2023-12-04 22:49:57 -05:00
// // Initialize cursor to current frame for local unwinding.
// unw_getcontext(&context);
// unw_init_local(&cursor, &context);
2023-11-22 21:14:15 -05:00
2023-12-04 22:49:57 -05:00
// // Unwind frames one by one, going up the frame stack.
// while (unw_step(&cursor) > 0) {
// unw_word_t offset, pc;
// unw_get_reg(&cursor, UNW_REG_IP, &pc);
// if (pc == 0) {
// break;
// }
// printf("0x%lx:", pc);
2023-11-22 21:14:15 -05:00
2023-12-04 22:49:57 -05:00
// char sym[256];
// if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
// printf(" (%s+0x%lx)\n", sym, offset);
// } else {
// printf(" -- error: unable to obtain symbol name for this frame\n");
// }
// }
// }
2023-11-22 21:14:15 -05:00
2023-11-21 04:43:30 -05:00
void customFunction1(int n) {
if(n <= 0) {
printf("End of recursion\n");
2023-11-22 21:14:15 -05:00
// output backtrace
printf("pid: %d\n", getpid());
2023-12-04 22:49:57 -05:00
// backtrace();
2023-11-21 04:43:30 -05:00
while (1) {
2023-11-22 21:14:15 -05:00
sleep(1);
2023-11-21 04:43:30 -05:00
} // never return, keep stack
return;
} else {
printf("Calling customFunction2\n");
customFunction2(n-1);
}
}
void customFunction2(int n) {
printf("Calling customFunction3\n");
customFunction3(n);
}
void customFunction3(int n) {
printf("Calling customFunction1\n");
customFunction1(n);
}
int main() {
customFunction1(10);
return 0;
}