Created
February 1, 2019 23:51
-
-
Save alanc/2f8c8170f8976b9fbf6b04676b765cd4 to your computer and use it in GitHub Desktop.
How to tell which library a function is from
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dlfcn.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) | |
{ | |
void *sym; | |
Dl_info_t dlip; | |
sym = dlsym(RTLD_PROBE, "malloc"); | |
if (sym == NULL) { | |
perror("dlsym failed"); | |
exit(1); | |
} | |
if (dladdr(sym, &dlip) == 0) { | |
perror("dladdr failed"); | |
exit(1); | |
} | |
printf("malloc: 0x%x in %s\n", sym, dlip.dli_fname); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment