This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB 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]

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


Hi,

The patch below is a rework of one I had previously submitted for
approval by the dwarf readers maintainer.  However, it was recently
pointed out to me that although my patch touches dwarf2loc.c, it
doesn't actually touch anything having to do with the dwarf2 reader. 
Thus, I'm posting an updated patch for comments.

The patch that I originally submitted may be found here:

    http://sources.redhat.com/ml/gdb-patches/2005-02/msg00022.html

The patch below uses the TRY_CATCH mechanism (as requested by Daniel
Jacobowitz).  In the course of updating, I found that
linux-thread-db.c had undergone i18n conversion.  I propogated that
conversion to the messages that (will) now appear in dwarf2loc.c.
I've also made a few other small changes to my original patch which
will hopefully improve readability and make future maintenance easier.
E.g. my original patch made several references to ``inferior_ptid''.
It now only makes one such reference.  If we ever revise this function
to not access this global, having only one reference to fix will likely
make that conversion easier.

The introductory remarks that I had included with my original patch are
as follows:

    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.

These remarks still apply to this reworked patch.

Comments?

	* 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.
	(dwarf_expr_tls_address): Invoke target_get_thread_local_address()
	via TRY_CATCH mechanism.  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.704
diff -u -p -r1.704 Makefile.in
--- Makefile.in	8 Mar 2005 08:59:45 -0000	1.704
+++ Makefile.in	9 Mar 2005 22:23:42 -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) \
@@ -2153,9 +2153,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.22
diff -u -p -r1.22 dwarf2loc.c
--- dwarf2loc.c	28 Feb 2005 17:00:48 -0000	1.22
+++ dwarf2loc.c	9 Mar 2005 22:23:43 -0000
@@ -32,6 +32,7 @@
 #include "ax-gdb.h"
 #include "regcache.h"
 #include "objfiles.h"
+#include "exceptions.h"
 
 #include "elf/dwarf2.h"
 #include "dwarf2expr.h"
@@ -188,9 +189,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);
+    {
+      ptid_t ptid = inferior_ptid;
+      struct objfile *objfile = debaton->objfile;
+      volatile struct exception ex;
+
+      TRY_CATCH (ex, RETURN_MASK_ALL)
+	{
+	  addr = target_get_thead_local_address (ptid, objfile, offset);
+	}
+      /* If an error occurred, print TLS related messages here.  Otherwise,
+         throw the error to some higher catcher.  */
+      if (ex.reason < 0)
+	{
+	  int objfile_is_library = (objfile->flags & OBJF_SHARED);
+
+	  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"), objfile->name);
+	      else
+		error (_("Cannot find executable file `%s' in dynamic"
+		         " linker's load module list"), 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"),
+		       objfile->name, target_pid_to_str (ptid));
+	      else
+		error (_("The inferior has not yet allocated storage for"
+		         " thread-local variables in\n"
+		         "the executable `%s'\n"
+		         "for %s"),
+		       objfile->name, target_pid_to_str (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 (ptid),
+		       objfile->name, ex.message);
+	      else
+		error (_("Cannot find thread-local storage for %s, "
+		         "executable file %s:\n%s"),
+		       target_pid_to_str (ptid),
+		       objfile->name, ex.message);
+	      break;
+	    default:
+	      throw_exception (ex);
+	      break;
+	    }
+	}
+    }
   /* 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.12
diff -u -p -r1.12 exceptions.h
--- exceptions.h	9 Mar 2005 17:52:54 -0000	1.12
+++ exceptions.h	9 Mar 2005 22:23:43 -0000
@@ -56,6 +56,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.4
diff -u -p -r1.4 linux-thread-db.c
--- linux-thread-db.c	12 Feb 2005 00:39:20 -0000	1.4
+++ linux-thread-db.c	9 Mar 2005 22:23:43 -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


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