backtrace和backtrace_symbols函数的使用
在看libdrm库函数的时候想看看哪些函数调用了drmIoctl函数
对drmIoctl做了简单修改,调用了print_trace函数
/**
* Call ioctl, restarting if it is interupted
*/
int
drmIoctl(int fd, unsigned long request, void *arg)
{
int ret;
print_trace();
do {
ret = ioctl(fd, request, arg);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
return ret;
}
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}
下面是运行的效果
使用时要先设置好库的路径,使用如下命令
export LD_RUN_PATH=/usr/local/lib;
或者
export LD_LIBRARY_PATH=/usr/local/lib
编译命令:
gcc -o test opengl1.cpp -lGL -lglut -ldrm
参考:
/*
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the ‘-LLIBDIR’
flag during linking and do at least one of the following:
- add LIBDIR to the ‘LD_LIBRARY_PATH’ environment variable
during execution
- add LIBDIR to the ‘LD_RUN_PATH’ environment variable
during linking
- use the ‘-Wl,-rpath -Wl,LIBDIR’ linker flag
- have your system administrator add LIBDIR to ‘/etc/ld.so.conf’
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
*/
libc库函数手册
https://www.gnu.org/software/libc/manual/html_node/Backtraces.html
上一篇: 记一次python3.7环境安装dlib模块遇到的坑
下一篇: 通过链接如何找到指定位置
推荐阅读
-
PHP中ob_start函数的使用说明_PHP教程
-
Go语言常见哈希函数的使用
-
植物大战僵尸修改器使用方法 PHP __autoload函数(自动载入类文件)的使用方法
-
Python编程使用*解包和itertools.product()求笛卡尔积的方法
-
javascript的数组和常用函数详解_基础知识
-
jquery中eq和get的区别与使用方法_jquery
-
php中ob_start系列函数的使用
-
php通过explode()和list()函数实现字符串的截取
-
我们可以使用Phalanger创建组合.NET和PHP的解决方案
-
php中echo()和print()、require()和include()等易混淆函数的区别