Commit 36b6bcb6 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #13268 from alalek:core_findfile_linux_use_dladdr

parents 5a804e3c 3c49b1db
......@@ -24,6 +24,8 @@
#undef min
#undef max
#undef abs
#elif defined(__linux__)
#include <dlfcn.h> // requires -ldl
#elif defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_MAC
......@@ -123,27 +125,10 @@ static cv::String getModuleLocation(const void* addr)
}
}
#elif defined(__linux__)
std::ifstream fs("/proc/self/maps");
std::string line;
while (std::getline(fs, line, '\n'))
Dl_info info;
if (0 != dladdr(addr, &info))
{
long long int addr_begin = 0, addr_end = 0;
if (2 == sscanf(line.c_str(), "%llx-%llx", &addr_begin, &addr_end))
{
if ((intptr_t)addr >= (intptr_t)addr_begin && (intptr_t)addr < (intptr_t)addr_end)
{
size_t pos = line.rfind(" "); // 2 spaces
if (pos == cv::String::npos)
pos = line.rfind(' '); // 1 spaces
else
pos++;
if (pos == cv::String::npos)
{
CV_LOG_DEBUG(NULL, "Can't parse module path: '" << line << '\'');
}
return line.substr(pos + 1);
}
}
return cv::String(info.dli_fname);
}
#elif defined(__APPLE__)
# if TARGET_OS_MAC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment