为什么 tcmalloc 不打印通过 dlopen 提供的函数名称
Why tcmalloc don't print function name, which provided via dlopen
我有下一个项目:main.cpp
#include <iostream>
#include <cstddef>
#include <dlfcn.h>
int main()
{
void* handle = dlopen("./shared_libs/libshared.so", RTLD_LAZY);
if (NULL == handle)
{
std::cerr << "Cannot open library: " << dlerror() << 'n';
return -1;
}
typedef int (*foo_t)(const std::size_t);
foo_t foo = reinterpret_cast<foo_t>(dlsym(handle, "foo"));
const char* dlsym_error = dlerror();
if (dlsym_error)
{
std::cerr << "Cannot load symbol 'foo': " << dlsym_error << 'n';
dlclose(handle);
return -2;
}
std::cout << "call foo" << std::endl;
foo(10);
dlclose(handle);
return 0;
}
shared.cpp:
#include <cstddef>
#include <iostream>
extern "C"
{
int foo(const std::size_t size)
{
int b = size / size;
int* a = new int[size];
std::cout << "leaky code here" << std::endl;
}
}
和Makefile:
all:
g++ -fPIC -g -c shared.cpp
g++ -shared -o shared_libs/libshared.so -g shared.o
g++ -L shared_libs/ -g main.cpp -ldl
我使用tcmalloc调试这个测试程序,它动态加载libshared.so:foo并执行它。run命令:LD_PRELOAD=/usr/local/lib/libtcmalloc.so HEAPCHECK=正常/a.out
最大的1次泄漏:
- 使用本地文件/a.out
- 从以下位置分配的1个对象中有40个字节泄漏:
- @7fe3460bd9ba 0x00007fe3460bd9ba
- @400b43主
- @7月346c33日__图书馆_开始_分钟
- @400999_启动
- @0(_I)
为什么我在foo函数中得到地址0x00007fe3460bd9ba而不是行?请帮助
附言:我试着用gdb和LD_PRELOAD=/tcmalloc.so,但我得到:"有人正在ptrace()攻击我们;将自行关闭关闭perftools堆泄漏检查"
尝试删除dlclose调用。
堆检查器&分析程序无法处理卸载的共享对象。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 共享库 SIGSEGV 在 dlopen 上 / 静态初始化时调用@plt函数
- 当*.so使用其他*.so中的函数时,如何使用dlopen和dlsym
- 如何使用dlopen()和dlsym()调用.so文件中的函数
- 为什么 tcmalloc 不打印通过 dlopen 提供的函数名称
- 对于不支持RTLD_DEEPBIND的平台,是否有替代 dlopen() 函数中 dlopen() 函数中的标志RTLD_DEEPBIND?