Skip to content
Snippets Groups Projects

Add inspect-library helper

Merged Ludovico de Nittis requested to merge wip/denittis/inspect-library into master
1 file
+ 15
14
Compare changes
  • Side-by-side
  • Inline
+ 15
14
@@ -48,6 +48,7 @@ main (int argc,
const char *symbol;
void *handle = NULL;
struct link_map *dep_map = NULL;
struct link_map *the_library = NULL;
FILE *fp;
char *line = NULL;
size_t len = 0;
@@ -72,13 +73,13 @@ main (int argc,
}
/* Using RTLD_DI_LINKMAP insted of RTLD_DI_ORIGIN we don't need to worry
* about allocating a big enough array for the path. */
if (dlinfo (handle, RTLD_DI_LINKMAP, &dep_map) != 0 || dep_map == NULL)
if (dlinfo (handle, RTLD_DI_LINKMAP, &the_library) != 0 || the_library == NULL)
{
fprintf (stderr, "Unable to obtain the path: %s\n", dlerror ());
clean_exit (handle);
return 1;
}
printf ("\n \"path\": \"%s\",\n", dep_map->l_name);
printf ("\n \"path\": \"%s\",\n", the_library->l_name);
printf (" \"missing_symbols\": [");
if (argc == 3)
@@ -145,26 +146,26 @@ main (int argc,
}
printf ("\n ]");
dep_map = the_library;
/* Some loaded libraries may be before our handle.
* To list them all we move the pointer at the beginning. */
while (dep_map != NULL && dep_map->l_prev != NULL)
dep_map = dep_map->l_prev;
printf (",\n \"dependencies\": [");
/* Some entries don't have a name. We move the pointer to the
* first element that has one. */
while (dep_map != NULL && strcmp (dep_map->l_name, "") == 0)
dep_map = dep_map->l_next;
if (dep_map != NULL)
{
printf ("\n \"%s\"", dep_map->l_name);
dep_map = dep_map->l_next;
}
first = true;
for (; dep_map != NULL; dep_map = dep_map->l_next)
{
if (strcmp (dep_map->l_name, "") != 0)
if (dep_map == the_library || strcmp (dep_map->l_name, "") == 0)
continue;
if (first)
{
printf ("\n \"%s\"", dep_map->l_name);
first = false;
}
else
printf (",\n \"%s\"", dep_map->l_name);
}
Loading