I am newbie to clang, and working on parsing of C/C++ code. I am giving below code as input, but not able to find actual function name using clang.
#include <stdio.h>
typedef int (*ExampleCallback)(void* something, int status);
//This will be in a separate file
void moduleAPI_start(ExampleCallback onSomething);
int moduleAPI_run();
static ExampleCallback storedCallback;
void moduleAPI_start(ExampleCallback onSomething)
{
storedCallback = onSomething;
}
int moduleAPI_run()
{
return storedCallback(NULL, '0');
}
//Callback implementing ExampleCallback signature
int myCallback(void* something, int status)
{
return status;
}
int main(void)
{
moduleAPI_start(myCallback);
printf("%d\n", moduleAPI_run());
return 0;
}
My question is, how do I know that, whenever I call moduleAPI_run
, it is actually calling myCallback
via storedCallback
.
In short, how do I get below sequence, so that I can use myCallback
for further processing.
storedCallback->onSomething->myCallback
Note: I have gone through this post, but unable to get clear solution.
Edit: On bigger side, we are trying to solve function pointer identity. We have different functions written with same signature having different purpose (to register appropriate function as callback at run time). With this clang analysis tool, we want to visualize the actual function called.