I am looking for a way to keep a track of all the functions that are called when I run an application on the gem5 simulator. For example, there is this code test.c:
#include <stdio.h>
int main(){
FILE *fp;
char c[] = "hello";
char buffer[100];
fp = fopen("Working.txt", "w+");
fwrite(c, 1, 5, fp);
fseek(fp,0,SEEK_SET);
fread(buffer, 1, 5, fp);
printf("%s \n",buffer);
fclose(fp);
return(0);
}
I compiled it to a binary and I basically want to track all the functions that are called when I use fopen, fwrite, fseek, fread, printf, fclose, and return
.
Taking fread
as an example, if fread() -> foo() -> bar() -> bar2() ... -> do_syscall_64()
, is the function call flow that calls the syscall in the end I want to track all of those functions.
I have already tried using gem5's debug mode using the --debug-flags
option (eg. command: build/X86/gem5.opt --debug-flags=Stack --debug-file=test_Stack.out configs/example/se.py --cpu-type=DerivO3CPU --caches --mem-type=DDR4_2400_8x8 --mem-size=8GB --cmd=./test
) and tried a bunch of flags including SyscallAll
, Stack
, and StackDist
.
While the SyscallAll
Flag just prints the syscalls that are being called at tick N, the other two debug flags print nothing at all.
Am I doing something wrong there? Is there even a way to print the user call stack inside gem5? Or can I do a custom implementation? Any help is appreciated.