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
+ 50
7
Compare changes
  • Side-by-side
  • Inline
  • df532d37
    Add symbols checking to inspect-library · df532d37
    RyuzakiKK authored
    Right now we expect to receive a list of version@symbol appended as
    argument to the inspect-library launch parameters.
    
    For unversioned symbols the syntax is Base@symbol.
    
    Probably once we decide a definitive syntax we should document it
    somewhere.
+ 50
7
@@ -32,6 +32,8 @@
#include <dlfcn.h>
#include <link.h>
#define BASE "Base"
void clean_exit (void *handle);
int
@@ -39,20 +41,23 @@ main (int argc,
char **argv)
{
const char *soname;
const char *version;
const char *symbol;
void *handle = NULL;
/* 4096 should be the standard PATH_MAX */
char library_path[4096];
struct link_map *dep_map = NULL;
const int SYMBOL_START = 2;
if (argc != 2)
if (argc < 2)
{
g_warning ("Expected exactly one SONAME as argument.\n");
g_warning ("Expected one SONAME as argument.\n");
return 1;
}
soname = argv[1];
g_print ("{\n");
g_print (" \"%s\": {\n", soname);
g_print (" \"%s\": {", soname);
handle = dlopen (soname, RTLD_LAZY);
if (handle == NULL)
{
@@ -66,7 +71,45 @@ main (int argc,
clean_exit (handle);
return 1;
}
g_print (" \"path\": \"%s\",\n", library_path);
g_print ("\n \"path\": \"%s\",\n", library_path);
g_print (" \"missing_symbols\": [");
for (int i = SYMBOL_START; i < argc; i++)
{
version = strsep(&argv[i], "@");
symbol = strsep(&argv[i], "@");
if (symbol == NULL)
{
g_warning ("Probably the version@symbol pair is mispelled.");
g_print ("\n ]");
clean_exit (handle);
return 1;
}
if (strcmp (version, BASE) == 0)
{
if (dlsym (handle, symbol) == NULL)
{
if (i == SYMBOL_START)
g_print ("\n \"%s\"", symbol);
else
g_print (",\n \"%s\"", symbol);
}
}
else
{
if (dlvsym (handle, symbol, version) == NULL)
{
if (i == SYMBOL_START)
g_print ("\n \"%s/%s\"", version, symbol);
else
g_print (",\n \"%s/%s\"", version, symbol);
}
}
}
g_print ("\n ]");
if (dlinfo (handle, RTLD_DI_LINKMAP, &dep_map) != 0)
{
@@ -75,7 +118,7 @@ main (int argc,
return 1;
}
g_print (" \"dependencies\": [");
g_print (",\n \"dependencies\": [");
if (dep_map != NULL)
{
g_print ("\n \"%s\"", dep_map->l_name);
@@ -87,7 +130,7 @@ main (int argc,
g_print (",\n \"%s\"", dep_map->l_name);
}
g_print ("\n ]\n }\n");
g_print ("\n ]\n }");
clean_exit (handle);
return 0;
@@ -99,5 +142,5 @@ clean_exit (void *handle)
if (handle != NULL)
dlclose (handle);
g_print ("}\n");
g_print ("\n}\n");
}
Loading