我使用-finstrument-functions
生成每个函数调用的进入和退出信息,并使用点来绘制它,就像上面一样。但是,我发现了一个问题,在我的main
函数中,我创建了两个线程,一个叫 driver_TASL,另一个叫 keyBoard_TASK。但在我生成的图片中,似乎我的keyBoard_TASK
被调用了driver_TASK
。应该像这两个 TASK 所调用的main
备注:我不能上传图片,所以我在下面描述它:
在我生成函数调用后,它应该是这样的:
main
称呼driver_TASK
main
称呼keyBoard_TASK
然而,它变成
main
称呼driver_TASK
driver_TASK
称呼keyboard_TASK
为什么keyBoard_TASK
被调用driver_TASK
?main
我认为它应该被称为
在我的源代码中,我把它们写成这样(我在代码中删除了一些打印函数):
int main(/*@ unused @*/int argc, /*@ unused @*/char *argv[]) //comment for lint
{
int res;
pthread_t driver_thread, keyBoard_thread;
void *thread_result;
res = pthread_create(&driver_thread, NULL, driver_TASK, (void *)&_gDriverStatus);
if(res != 0)
{
perror("Thread Creation Failed");
exit(EXIT_FAILURE);
}
sleep(1);
res = pthread_create(&keyBoard_thread, NULL, keyBoard_TASK, (void *)&_gKeyStatus);
if(res != 0)
{
perror("Thread Creation Failed");
exit(EXIT_FAILURE);
}
res = pthread_join(driver_thread, &thread_result);
if(res != 0)
{
perror("Thread Join Failed");
exit(EXIT_FAILURE);
}
res = pthread_join(keyBoard_thread, &thread_result);
if(res != 0)
{
perror("Thread Join Failed");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
我还附上了我的自动点文件,函数调用流程图是pvtace自动生成的
digraph DEMO {
main [shape=rectangle]
driver_TASK [shape=rectangle]
DDI_DRIVER_Probe [shape=rectangle]
_Driver_Clear [shape=ellipse]
_Driver [shape=ellipse]
DRIVER_Probe_Demo [shape=ellipse]
DDI_DRIVER_Init [shape=rectangle]
DRIVER_Init_Demo [shape=rectangle]
_DRIVER_Init_Demo [shape=ellipse]
DDI_DRIVER_Running [shape=rectangle]
DRIVER_Running_Demo [shape=rectangle]
_DRIVER_Running_Demo [shape=ellipse]
keyBoard_TASK [shape=rectangle]
main -> DBG_PrintColor [label="2 calls" fontsize="10"]
main -> driver_TASK [label="1 calls" fontsize="10"] //this is correct
driver_TASK -> DBG_PrintColor [label="6 calls" fontsize="10"]
driver_TASK -> DDI_DRIVER_Probe [label="1 calls" fontsize="10"]
driver_TASK -> DDI_DRIVER_Init [label="1 calls" fontsize="10"]
driver_TASK -> DDI_DRIVER_Running [label="1 calls" fontsize="10"]
driver_TASK -> keyBoard_TASK [label="1 calls" fontsize="10"] //this is not correct
DDI_DRIVER_Probe -> _Driver_Clear [label="1 calls" fontsize="10"]
DDI_DRIVER_Probe -> _Driver [label="1 calls" fontsize="10"]
DDI_DRIVER_Probe -> DRIVER_Probe_Demo [label="1 calls" fontsize="10"]
DDI_DRIVER_Init -> _Driver [label="1 calls" fontsize="10"]
DDI_DRIVER_Init -> DRIVER_Init_Demo [label="1 calls" fontsize="10"]
DRIVER_Init_Demo -> _DRIVER_Init_Demo [label="1 calls" fontsize="10"]
DDI_DRIVER_Running -> _Driver [label="1 calls" fontsize="10"]
DDI_DRIVER_Running -> DRIVER_Running_Demo [label="1 calls" fontsize="10"]
DRIVER_Running_Demo -> _DRIVER_Running_Demo [label="1 calls" fontsize="10"]
keyBoard_TASK -> DBG_PrintColor [label="6 calls" fontsize="10"]
}