This is the mail archive of the rda@sources.redhat.com mailing list for the rda project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Print diagnostics related to thread initialization failures


I've just committed the patch below.

	* thread-db.c (lookup_sym): New function.
	(thread_db_open): Print diagnostic message for failed dlopen()
	call.  Call lookup_sym() which will print diagnostic for failed
	dlsym() call.

Index: thread-db.c
===================================================================
RCS file: /cvs/src/src/rda/unix/thread-db.c,v
retrieving revision 1.2
diff -u -p -r1.2 thread-db.c
--- thread-db.c	7 Feb 2003 23:03:09 -0000	1.2
+++ thread-db.c	20 Apr 2004 20:32:04 -0000
@@ -740,6 +740,23 @@ thread_db_setgregs (const td_thrhandle_t
   return thread_db_set_regset (&gregset_cache, th, gregset);
 }
 
+/* Call dlsym() to find the address of a symbol.  If symbol lookup fails,
+   print the reason to stderr.  */
+
+static void *
+lookup_sym (void *dlhandle, char *symbol)
+{
+  void *addr;
+
+  addr = dlsym (dlhandle, symbol);
+
+  if (addr == NULL)
+    fprintf (stderr, "Symbol lookup of %s failed: %s\n",
+	     symbol, dlerror ());
+
+  return addr;
+}
+
 /* Function: thread_db_dlopen
    Attach to the libthread_db library.  
    This function does all the dynamic library stuff (dlopen, dlsym).
@@ -755,45 +772,49 @@ thread_db_dlopen (void)
 #endif
 
   if ((dlhandle = dlopen (LIBTHREAD_DB_SO, RTLD_NOW)) == NULL)
-    return -1;		/* fail */
+    {
+      fprintf (stderr, "Unable to open %s: %s\n",
+               LIBTHREAD_DB_SO, dlerror ());
+      return -1;		/* fail */
+    }
 
   /* Initialize pointers to the dynamic library functions we will use.
    */
 
-  if ((td_init_p = dlsym (dlhandle, "td_init")) == NULL)
+  if ((td_init_p = lookup_sym (dlhandle, "td_init")) == NULL)
     return -1;		/* fail */
 
-  if ((td_ta_new_p = dlsym (dlhandle, "td_ta_new")) == NULL)
+  if ((td_ta_new_p = lookup_sym (dlhandle, "td_ta_new")) == NULL)
     return -1;		/* fail */
 
-  if ((td_ta_delete_p = dlsym (dlhandle, "td_ta_delete")) == NULL)
+  if ((td_ta_delete_p = lookup_sym (dlhandle, "td_ta_delete")) == NULL)
     return -1;		/* fail */
 
-  if ((td_ta_map_id2thr_p = dlsym (dlhandle, "td_ta_map_id2thr")) == NULL)
+  if ((td_ta_map_id2thr_p = lookup_sym (dlhandle, "td_ta_map_id2thr")) == NULL)
     return -1;		/* fail */
 
-  if ((td_ta_map_lwp2thr_p = dlsym (dlhandle, "td_ta_map_lwp2thr")) == NULL)
+  if ((td_ta_map_lwp2thr_p = lookup_sym (dlhandle, "td_ta_map_lwp2thr")) == NULL)
     return -1;		/* fail */
 
-  if ((td_ta_thr_iter_p = dlsym (dlhandle, "td_ta_thr_iter")) == NULL)
+  if ((td_ta_thr_iter_p = lookup_sym (dlhandle, "td_ta_thr_iter")) == NULL)
     return -1;		/* fail */
 
-  if ((td_thr_validate_p = dlsym (dlhandle, "td_thr_validate")) == NULL)
+  if ((td_thr_validate_p = lookup_sym (dlhandle, "td_thr_validate")) == NULL)
     return -1;		/* fail */
 
-  if ((td_thr_get_info_p = dlsym (dlhandle, "td_thr_get_info")) == NULL)
+  if ((td_thr_get_info_p = lookup_sym (dlhandle, "td_thr_get_info")) == NULL)
     return -1;		/* fail */
 
-  if ((td_thr_getfpregs_p = dlsym (dlhandle, "td_thr_getfpregs")) == NULL)
+  if ((td_thr_getfpregs_p = lookup_sym (dlhandle, "td_thr_getfpregs")) == NULL)
     return -1;		/* fail */
 
-  if ((td_thr_getgregs_p = dlsym (dlhandle, "td_thr_getgregs")) == NULL)
+  if ((td_thr_getgregs_p = lookup_sym (dlhandle, "td_thr_getgregs")) == NULL)
     return -1;		/* fail */
 
-  if ((td_thr_setfpregs_p = dlsym (dlhandle, "td_thr_setfpregs")) == NULL)
+  if ((td_thr_setfpregs_p = lookup_sym (dlhandle, "td_thr_setfpregs")) == NULL)
     return -1;		/* fail */
 
-  if ((td_thr_setgregs_p = dlsym (dlhandle, "td_thr_setgregs")) == NULL)
+  if ((td_thr_setgregs_p = lookup_sym (dlhandle, "td_thr_setgregs")) == NULL)
     return -1;		/* fail */
 
   /* These are not essential.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]