[RFA] Move printing of TLS related error messages to dwarf2loc.c

Kevin Buettner kevinb@redhat.com
Mon Feb 7 23:54:00 GMT 2005


The patch below moves the printing of TLS related errors into
dwarf_expr_tls_address().  At the moment, these errors are being
printed by thread_db_get_thread_local_address(), but if some other
implementation of TLS support were to be added to GDB and mimic the
way in which thread_db_get_thread_local_address() currently works,
we'd end up having two or more sets of TLS error messages.  Thus, this
patch will ensure that a common set of error messages will be used by
all TLS implementations.  In the course of moving the messages from
the linux specific file to the dwarf2loc.c, I tried to adjust the
messages somewhat so that they might make sense for other TLS
implementations as well.

My more immediate goal, however, was to eliminate all but one use of
``objfile'' from thread_db_get_thread_local_address.  Once this patch
goes in, I'll submit a patch which'll pass a target specific
representation of the load module in place of the ``objfile''
parameter.  For the motivation for this, see
http://sources.redhat.com/ml/gdb-patches/2004-12/msg00337.html

And, once that's done, I'll be able to resubmit my support for the
qGetTLSAddr packet.

Okay?

Kevin

	* Makefile.in (dwarf2loc.o, linux-thread-db.o): Add dependencies.
	* exceptions.h (TLS_NO_LIBRARY_SUPPORT_ERROR, TLS_GENERIC_ERROR)
	(TLS_LOAD_MODULE_NOT_FOUND_ERROR, TLS_NOT_ALLOCATED_YET_ERROR):
	New error/exception enums.
	* dwarf2loc.c (exceptions.h): Include.
	(get_thread_local_address_args): New struct.
	(get_thread_local_address): New function.
	(dwarf_expr_tls_address): Invoke target_get_thread_local_address()
	via catch_exception().  Print error messages for TLS related
	exceptions.
	* linux-thread-db.c (thread_db_get_thread_local_address): Throw
	exceptions instead of printing errors.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.696
diff -u -p -r1.696 Makefile.in
--- Makefile.in	28 Jan 2005 06:40:24 -0000	1.696
+++ Makefile.in	7 Feb 2005 20:54:17 -0000
@@ -1873,8 +1873,8 @@ dwarf2-frame.o: dwarf2-frame.c $(defs_h)
 	$(gdb_assert_h) $(gdb_string_h) $(complaints_h) $(dwarf2_frame_h)
 dwarf2loc.o: dwarf2loc.c $(defs_h) $(ui_out_h) $(value_h) $(frame_h) \
 	$(gdbcore_h) $(target_h) $(inferior_h) $(ax_h) $(ax_gdb_h) \
-	$(regcache_h) $(objfiles_h) $(elf_dwarf2_h) $(dwarf2expr_h) \
-	$(dwarf2loc_h) $(gdb_string_h)
+	$(regcache_h) $(objfiles_h) $(exceptions_h) $(elf_dwarf2_h) \
+	$(dwarf2expr_h) $(dwarf2loc_h) $(gdb_string_h)
 dwarf2read.o: dwarf2read.c $(defs_h) $(bfd_h) $(symtab_h) $(gdbtypes_h) \
 	$(objfiles_h) $(elf_dwarf2_h) $(buildsym_h) $(demangle_h) \
 	$(expression_h) $(filenames_h) $(macrotab_h) $(language_h) \
@@ -2149,9 +2149,9 @@ linux-nat.o: linux-nat.c $(defs_h) $(inf
 	$(gdbcmd_h) $(regcache_h) $(elf_bfd_h) $(gregset_h) $(gdbcore_h) \
 	$(gdbthread_h) $(gdb_stat_h)
 linux-thread-db.o: linux-thread-db.c $(defs_h) $(gdb_assert_h) \
-	$(gdb_proc_service_h) $(gdb_thread_db_h) $(bfd_h) $(gdbthread_h) \
-	$(inferior_h) $(symfile_h) $(objfiles_h) $(target_h) $(regcache_h) \
-	$(solib_svr4_h)
+	$(gdb_proc_service_h) $(gdb_thread_db_h) $(bfd_h) $(exceptions_h) \
+	$(gdbthread_h) $(inferior_h) $(symfile_h) $(objfiles_h) $(target_h) \
+	$(regcache_h) $(solib_svr4_h)
 lynx-nat.o: lynx-nat.c $(defs_h) $(frame_h) $(inferior_h) $(target_h) \
 	$(gdbcore_h) $(regcache_h)
 m2-exp.o: m2-exp.c $(defs_h) $(gdb_string_h) $(expression_h) $(language_h) \
Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.18
diff -u -p -r1.18 dwarf2loc.c
--- dwarf2loc.c	9 Nov 2004 14:43:25 -0000	1.18
+++ dwarf2loc.c	7 Feb 2005 20:54:17 -0000
@@ -30,6 +30,7 @@
 #include "ax-gdb.h"
 #include "regcache.h"
 #include "objfiles.h"
+#include "exceptions.h"
 
 #include "elf/dwarf2.h"
 #include "dwarf2expr.h"
@@ -177,6 +178,25 @@ dwarf_expr_frame_base (void *baton, unsi
 	   SYMBOL_NATURAL_NAME (framefunc));
 }
 
+struct get_thread_local_address_args
+{
+  ptid_t ptid;
+  struct objfile *objfile;
+  CORE_ADDR offset;
+  CORE_ADDR retval;
+};
+
+/* Wrapper for target_get_thread_local_address.  */
+static void
+get_thread_local_address (struct ui_out *uiout, void *args)
+{
+  struct get_thread_local_address_args *a = args;
+
+  a->retval = target_get_thread_local_address (a->ptid,
+                                               a->objfile,
+					       a->offset);
+}
+
 /* Using the objfile specified in BATON, find the address for the
    current thread's thread-local storage with offset OFFSET.  */
 static CORE_ADDR
@@ -186,9 +206,66 @@ dwarf_expr_tls_address (void *baton, COR
   CORE_ADDR addr;
 
   if (target_get_thread_local_address_p ())
-    addr = target_get_thread_local_address (inferior_ptid,
-					    debaton->objfile,
-					    offset);
+    {
+      struct get_thread_local_address_args args;
+      struct exception ex;
+      int objfile_is_library = (debaton->objfile->flags & OBJF_SHARED);
+
+      args.ptid = inferior_ptid;
+      args.objfile = debaton->objfile;
+      args.offset = offset;
+
+      ex = catch_exception (uiout, get_thread_local_address, &args,
+                            RETURN_MASK_ALL);
+      if (ex.reason < 0)
+	{
+	  switch (ex.error)
+	    {
+	    case TLS_NO_LIBRARY_SUPPORT_ERROR:
+	      error ("Cannot find thread-local variables in this thread library.");
+	      break;
+	    case TLS_LOAD_MODULE_NOT_FOUND_ERROR:
+	      if (objfile_is_library)
+		error ("Cannot find shared library `%s' in dynamic"
+		       " linker's load module list", debaton->objfile->name);
+	      else
+		error ("Cannot find executable file `%s' in dynamic"
+		       " linker's load module list", debaton->objfile->name);
+	      break;
+	    case TLS_NOT_ALLOCATED_YET_ERROR:
+	      if (objfile_is_library)
+		error ("The inferior has not yet allocated storage for"
+		       " thread-local variables in\n"
+		       "the shared library `%s'\n"
+		       "for %s",
+		       debaton->objfile->name, target_pid_to_str (args.ptid));
+	      else
+		error ("The inferior has not yet allocated storage for"
+		       " thread-local variables in\n"
+		       "the executable `%s'\n"
+		       "for %s",
+		       debaton->objfile->name, target_pid_to_str (args.ptid));
+	      break;
+	    case TLS_GENERIC_ERROR:
+	      if (objfile_is_library)
+		error ("Cannot find thread-local storage for %s, "
+		       "shared library %s:\n%s",
+		       target_pid_to_str (args.ptid),
+		       debaton->objfile->name, ex.message);
+	      else
+		error ("Cannot find thread-local storage for %s, "
+		       "executable file %s:\n%s",
+		       target_pid_to_str (args.ptid),
+		       debaton->objfile->name, ex.message);
+	      break;
+	    default:
+	      throw_exception (ex);
+	      break;
+	    }
+	}
+      else
+	addr = args.retval;
+    }
   /* It wouldn't be wrong here to try a gdbarch method, too; finding
      TLS is an ABI-specific thing.  But we don't do that yet.  */
   else
Index: exceptions.h
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.h,v
retrieving revision 1.10
diff -u -p -r1.10 exceptions.h
--- exceptions.h	19 Jan 2005 21:15:43 -0000	1.10
+++ exceptions.h	7 Feb 2005 20:54:17 -0000
@@ -52,6 +52,22 @@ enum errors {
      exception.message.  */
   GENERIC_ERROR,
   NOT_FOUND_ERROR,
+
+  /* Thread library lacks support necessary for finding thread local
+     storage.  */
+  TLS_NO_LIBRARY_SUPPORT_ERROR,
+
+  /* Load module not found while attempting to find thread local storage.  */
+  TLS_LOAD_MODULE_NOT_FOUND_ERROR,
+
+  /* Thread local storage has not been allocated yet.  */
+  TLS_NOT_ALLOCATED_YET_ERROR,
+
+  /* Something else went wrong while attempting to find thread local
+     storage.  The ``struct exception'' message field provides more
+     detail.  */
+  TLS_GENERIC_ERROR,
+
   /* Add more errors here.  */
   NR_ERRORS
 };
Index: linux-thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-thread-db.c,v
retrieving revision 1.2
diff -u -p -r1.2 linux-thread-db.c
--- linux-thread-db.c	8 Dec 2004 15:10:30 -0000	1.2
+++ linux-thread-db.c	7 Feb 2005 20:54:17 -0000
@@ -27,6 +27,7 @@
 #include "gdb_thread_db.h"
 
 #include "bfd.h"
+#include "exceptions.h"
 #include "gdbthread.h"
 #include "inferior.h"
 #include "symfile.h"
@@ -1238,7 +1239,6 @@ thread_db_get_thread_local_address (ptid
 {
   if (is_thread (ptid))
     {
-      int objfile_is_library = (objfile->flags & OBJF_SHARED);
       td_err_e err;
       void *address;
       CORE_ADDR lm;
@@ -1246,7 +1246,12 @@ thread_db_get_thread_local_address (ptid
 
       /* glibc doesn't provide the needed interface.  */
       if (!td_thr_tls_get_addr_p)
-	error ("Cannot find thread-local variables in this thread library.");
+	{
+	  struct exception e 
+	    = { RETURN_ERROR, TLS_NO_LIBRARY_SUPPORT_ERROR, 0 };
+
+	  throw_exception (e);
+	}
 
       /* Get the address of the link map for this objfile.  */
       lm = svr4_fetch_objfile_link_map (objfile);
@@ -1254,12 +1259,10 @@ thread_db_get_thread_local_address (ptid
       /* Whoops, we couldn't find one. Bail out.  */
       if (!lm)
 	{
-	  if (objfile_is_library)
-	    error ("Cannot find shared library `%s' link_map in dynamic"
-		   " linker's module list", objfile->name);
-	  else
-	    error ("Cannot find executable file `%s' link_map in dynamic"
-		   " linker's module list", objfile->name);
+	  struct exception e
+	    = { RETURN_ERROR, TLS_LOAD_MODULE_NOT_FOUND_ERROR, 0 };
+
+	  throw_exception (e);
 	}
 
       /* Get info about the thread.  */
@@ -1277,34 +1280,21 @@ thread_db_get_thread_local_address (ptid
 	  /* Now, if libthread_db provided the initialization image's
 	     address, we *could* try to build a non-lvalue value from
 	     the initialization image.  */
-	  if (objfile_is_library)
-	    error ("The inferior has not yet allocated storage for"
-		   " thread-local variables in\n"
-		   "the shared library `%s'\n"
-		   "for the thread %ld",
-		   objfile->name, (long) GET_THREAD (ptid));
-	  else
-	    error ("The inferior has not yet allocated storage for"
-		   " thread-local variables in\n"
-		   "the executable `%s'\n"
-		   "for the thread %ld",
-		   objfile->name, (long) GET_THREAD (ptid));
+
+	  struct exception e
+	    = { RETURN_ERROR, TLS_NOT_ALLOCATED_YET_ERROR, 0 };
+
+	  throw_exception (e);
 	}
 #endif
 
       /* Something else went wrong.  */
       if (err != TD_OK)
 	{
-	  if (objfile_is_library)
-	    error ("Cannot find thread-local storage for thread %ld, "
-		   "shared library %s:\n%s",
-		   (long) GET_THREAD (ptid),
-		   objfile->name, thread_db_err_str (err));
-	  else
-	    error ("Cannot find thread-local storage for thread %ld, "
-		   "executable file %s:\n%s",
-		   (long) GET_THREAD (ptid),
-		   objfile->name, thread_db_err_str (err));
+	  struct exception e
+	    = { RETURN_ERROR, TLS_GENERIC_ERROR, thread_db_err_str (err) };
+
+	  throw_exception (e);
 	}
 
       /* Cast assuming host == target.  Joy.  */
@@ -1312,10 +1302,15 @@ thread_db_get_thread_local_address (ptid
     }
 
   if (target_beneath->to_get_thread_local_address)
-    return target_beneath->to_get_thread_local_address (ptid, objfile,
-							offset);
+    return target_beneath->to_get_thread_local_address (ptid, objfile, offset);
+  else
+    {
+      struct exception e
+	= { RETURN_ERROR, TLS_GENERIC_ERROR,
+	    "TLS not supported on this target" };
 
-  error ("Cannot find thread-local values on this target.");
+      throw_exception (e);
+    }
 }
 
 static void



More information about the Gdb-patches mailing list