| 3346 | #endif |
| 3347 | |
| 3348 | platform::ImageInfo getImageInfo(const void* symbol) { |
| 3349 | Dl_info info; |
| 3350 | platform::ImageInfo imageInfo; |
| 3351 | |
| 3352 | #ifdef __linux__ |
| 3353 | link_map* linkMap = nullptr; |
| 3354 | int res = dladdr1(symbol, &info, (void**)&linkMap, RTLD_DL_LINKMAP); |
| 3355 | #else |
| 3356 | int res = dladdr(symbol, &info); |
| 3357 | #endif |
| 3358 | |
| 3359 | if (res != 0) { |
| 3360 | imageInfo.fileName = info.dli_fname; |
| 3361 | std::string imageFile = basename(info.dli_fname); |
| 3362 | // If we have a client library that doesn't end in the appropriate extension, we will get the wrong debug |
| 3363 | // suffix. This should only be a cosmetic problem, though. |
| 3364 | #ifdef __linux__ |
| 3365 | imageInfo.offset = (void*)linkMap->l_addr; |
| 3366 | if (imageFile.length() >= 3 && imageFile.rfind(".so") == imageFile.length() - 3) { |
| 3367 | imageInfo.symbolFileName = imageFile + "-debug"; |
| 3368 | } |
| 3369 | #else |
| 3370 | imageInfo.offset = info.dli_fbase; |
| 3371 | if (imageFile.length() >= 6 && imageFile.rfind(".dylib") == imageFile.length() - 6) { |
| 3372 | imageInfo.symbolFileName = imageFile + "-debug"; |
| 3373 | } |
| 3374 | #endif |
| 3375 | else { |
| 3376 | imageInfo.symbolFileName = imageFile + ".debug"; |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | return imageInfo; |
| 3381 | } |
no test coverage detected