The invention relates to a method and a device for acquiring a thread call stack content. The method includes: creating a file, and the file is written to the default algorithm; obtaining corresponding to the current process ID value; ID value according to the process of executing the preset algorithm to obtain the execution results; remove the execution result from the file, the implementation of the thread corresponding to the call stack the contents of the ID process. The device provided by the embodiment of the invention is realized on the basis of the method described above. The invention does not need the user to view the contents of the stack manually, which is simple and convenient and greatly improves the user experience.
【技术实现步骤摘要】
本专利技术涉及计算机
,具体涉及一种线程调用栈内容获取方法及装置。
技术介绍
线程调用栈是内存中用于保留线程内函数的调用关系、调用过程的装置。例如,一个典型的线程调用栈如下:#00x00001111inCCCC(c=10);#10x00002222inBBBB(b=9);#20x00003333inAAAA(a=8);#30x00004444inmain();当前线程执行到CCCC函数,并且当前线程内的函数执行顺序是main->AAAA->BBBB->CCCC时,如果此时获取到CCCC函数的输入入参数10,则通过线程调用栈看到上述函数的执行过程,且获取函数的状态。现有技术中可以通过backtrace函数获取函数的单个线程的调用栈信息。但是,目前程序大部分采用多线程工作方式,即使程序工作在单线程情况,也可以看作是多线程的一种特殊情况。此时采用backtrace函数则不适用于程序采用多线程工作方式的场合。r>
技术实现思路
...
【技术保护点】
一种线程调用栈内容获取方法,其特征在于,所述方法包括:获取对应于当前程序的进程ID值;创建一个文件,并向该文件内写入预设算法;根据上述进程ID值执行所述预设算法以获取执行结果;从文件中取出所述执行结果,所述执行结果为线程调用栈中对应于进程ID的内容。
【技术特征摘要】
1.一种线程调用栈内容获取方法,其特征在于,所述方法包括:
获取对应于当前程序的进程ID值;
创建一个文件,并向该文件内写入预设算法;
根据上述进程ID值执行所述预设算法以获取执行结果;
从文件中取出所述执行结果,所述执行结果为线程调用栈中对应
于进程ID的内容。
2.根据权利要求1所述的线程调用栈内容获取方法,其特征在于,
所述预设算法包括:
获取所述进程ID值;
扫描所述当前进程中的所有线程;
退出。
3.根据权利要求2所述的线程调用栈内容获取方法,其特征在于,
采用第三方命令行调试工具GDB执行所述预设算法。
4.根据权利要求1所述的线程调用栈内容获取方法,其特征在于,
采用getpid函数获取所述进程ID值。
5.根据权利要求1所述的线程调用栈内容获取方法,其特征在于,
采用popen函数执行所述预设算法以获取执行结果;采用fgets函数从
文件中取出所述执行结果。
6.一种线程调用栈内容获取装置,其特征在于,所述装置包括:
进程ID值获取模块,用于获取对应于当前程序的进程ID值;...
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。