Skip to content
Snippets Groups Projects

Add inspect-library helper

Merged Ludovico de Nittis requested to merge wip/denittis/inspect-library into master
2 files
+ 23
22
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 22
21
@@ -28,7 +28,8 @@
* JSON with the path and the dependencies of the requested library.
*/
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <link.h>
@@ -51,29 +52,29 @@ main (int argc,
if (argc < 2)
{
g_warning ("Expected one SONAME as argument.\n");
fprintf (stderr, "Expected one SONAME as argument.\n");
return 1;
}
soname = argv[1];
g_print ("{\n");
g_print (" \"%s\": {", soname);
printf ("{\n");
printf (" \"%s\": {", soname);
handle = dlopen (soname, RTLD_LAZY);
if (handle == NULL)
{
g_warning ("Unable to find the library: %s\n", dlerror ());
fprintf (stderr, "Unable to find the library: %s\n", dlerror ());
clean_exit (handle);
return 1;
}
if (dlinfo (handle, RTLD_DI_ORIGIN, library_path) != 0)
{
g_warning ("Unable to obtain the path: %s\n", dlerror ());
fprintf (stderr, "Unable to obtain the path: %s\n", dlerror ());
clean_exit (handle);
return 1;
}
g_print ("\n \"path\": \"%s\",\n", library_path);
printf ("\n \"path\": \"%s\",\n", library_path);
g_print (" \"missing_symbols\": [");
printf (" \"missing_symbols\": [");
for (int i = SYMBOL_START; i < argc; i++)
{
version = strsep(&argv[i], "@");
@@ -81,8 +82,8 @@ main (int argc,
if (symbol == NULL)
{
g_warning ("Probably the version@symbol pair is mispelled.");
g_print ("\n ]");
fprintf (stderr, "Probably the version@symbol pair is mispelled.");
printf ("\n ]");
clean_exit (handle);
return 1;
}
@@ -92,9 +93,9 @@ main (int argc,
if (dlsym (handle, symbol) == NULL)
{
if (i == SYMBOL_START)
g_print ("\n \"%s\"", symbol);
printf ("\n \"%s\"", symbol);
else
g_print (",\n \"%s\"", symbol);
printf (",\n \"%s\"", symbol);
}
}
else
@@ -102,35 +103,35 @@ main (int argc,
if (dlvsym (handle, symbol, version) == NULL)
{
if (i == SYMBOL_START)
g_print ("\n \"%s/%s\"", version, symbol);
printf ("\n \"%s/%s\"", version, symbol);
else
g_print (",\n \"%s/%s\"", version, symbol);
printf (",\n \"%s/%s\"", version, symbol);
}
}
}
g_print ("\n ]");
printf ("\n ]");
if (dlinfo (handle, RTLD_DI_LINKMAP, &dep_map) != 0)
{
g_warning ("Unable to obtain the dependencies list: %s\n", dlerror ());
fprintf (stderr, "Unable to obtain the dependencies list: %s\n", dlerror ());
clean_exit (handle);
return 1;
}
g_print (",\n \"dependencies\": [");
printf (",\n \"dependencies\": [");
if (dep_map != NULL)
{
g_print ("\n \"%s\"", dep_map->l_name);
printf ("\n \"%s\"", dep_map->l_name);
dep_map = dep_map->l_next;
}
for (; dep_map != NULL; dep_map = dep_map->l_next)
{
g_print (",\n \"%s\"", dep_map->l_name);
printf (",\n \"%s\"", dep_map->l_name);
}
g_print ("\n ]\n }");
printf ("\n ]\n }");
clean_exit (handle);
return 0;
@@ -142,5 +143,5 @@ clean_exit (void *handle)
if (handle != NULL)
dlclose (handle);
g_print ("\n}\n");
printf ("\n}\n");
}
Loading