From 89ce01fed3a906e209e756285b3f3516d95ebbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vivek=20Das=C2=A0Mohapatra?= <vivek@collabora.co.uk> Date: Tue, 4 Jul 2017 17:27:23 +0100 Subject: [PATCH] Add debug showing link map contents inside and outside the capsule --- capsule/capsule-dlmopen.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/capsule/capsule-dlmopen.c b/capsule/capsule-dlmopen.c index 947854deb..64263ca03 100644 --- a/capsule/capsule-dlmopen.c +++ b/capsule/capsule-dlmopen.c @@ -210,6 +210,36 @@ static int install_wrappers ( void *dl_handle, return replacements; } +// dump the link map info for the given dl handle (NULL = default) +static void +dump_link_map( void *dl_handle ) +{ + struct link_map *map; + void *handle; + + if( !dl_handle ) + handle = dlopen( NULL, RTLD_LAZY|RTLD_NOLOAD ); + else + handle = dl_handle; + + if( dlinfo( handle, RTLD_DI_LINKMAP, &map ) != 0 ) + { + DEBUG( DEBUG_CAPSULE, "failed to access link_map for handle %p-%p: %s", + dl_handle, handle, dlerror() ); + return; + } + + // be kind, rewind the link map: + while( map->l_prev ) + map = map->l_prev; + + fprintf( stderr, "(dl-handle %s", dl_handle ? "CAPSULE" : "DEFAULT" ); + for( struct link_map *m = map; m; m = m->l_next ) + fprintf( stderr, "\n [%p] %s [%p]\n", + m->l_prev, m->l_name, m->l_next ); + fprintf( stderr, ")\n" ); +} + // ========================================================================== void * capsule_dlmopen (const char *dso, @@ -297,6 +327,11 @@ capsule_dlmopen (const char *dso, // load the stack of DSOs we need: ret = ld_libs_load( &ldlibs, namespace, 0, errcode ); + if( debug_flags & DEBUG_CAPSULE ) + { + dump_link_map( ret ); + dump_link_map( NULL ); + } if( !ret ) goto cleanup; -- GitLab