Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFC: Ignore TLS symbols for non-TLS programs
@ 2006-08-25 13:43 Jan Kratochvil
  2006-08-25 16:43 ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Kratochvil @ 2006-08-25 13:43 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 978 bytes --]

Hi,

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337

currently for trivia nonthreaded helloworld with no debug info up to -ggdb2 you
will get:
	(gdb) p errno 
	Cannot access memory at address 0x8 

* with -ggdb3 "errno" gets resolved as _macro_ and the resulting
  "(*__errno_location ())" expression is always fine.

* with -ggdb2 and less "errno" in fact does not exist anywhere as it was
  compiled to "(*__errno_location ())" and the macro definition is not present.
  Unfortunately gdb will find the TLS symbol and it will try to access it but
  as the program has been compiled without -lpthread the TLS base register
  (%gs on i386) is not setup and it will result in:
  	Cannot access memory at address 0x8

IMO the right way is to ignore TLS symbols for inferiors without activated
threading.  Patch attached.

Also attached suggestion patch how to deal with the most common "errno" symbol
for the most common under-ggdb3 compiled programs.


Regards,
Jan

[-- Attachment #2: gdb-6.5-bz185337-tls-ignore-symbols-without-startup.patch --]
[-- Type: text/plain, Size: 4378 bytes --]

Index: gdb/minsyms.c
===================================================================
RCS file: /cvs/src/src/gdb/minsyms.c,v
retrieving revision 1.46
diff -u -p -r1.46 minsyms.c
--- gdb/minsyms.c	19 Jul 2006 02:17:23 -0000	1.46
+++ gdb/minsyms.c	25 Aug 2006 01:42:27 -0000
@@ -50,6 +50,7 @@
 #include "demangle.h"
 #include "value.h"
 #include "cp-abi.h"
+#include "target.h"
 
 /* Accumulate the minimal symbols for each objfile in bunches of BUNCH_SIZE.
    At the end, copy them all into one newly allocated location on an objfile's
@@ -202,10 +203,18 @@ lookup_minimal_symbol (const char *name,
 		     you want to test the linkage names with strcmp,
 		     do that.  If you want to test the natural names
 		     with strcmp_iw, use SYMBOL_MATCHES_NATURAL_NAME.  */
-		  if (strcmp (DEPRECATED_SYMBOL_NAME (msymbol), (name)) == 0
+		  if ((strcmp (DEPRECATED_SYMBOL_NAME (msymbol), (name)) == 0
 		      || (SYMBOL_DEMANGLED_NAME (msymbol) != NULL
 			  && strcmp_iw (SYMBOL_DEMANGLED_NAME (msymbol),
 					(name)) == 0))
+		  /* Ignore TLS based symbols if inferior does not run in
+		     threaded mode.
+		     https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
+		     Otherwise we would resolve glibc TLS `errno' even for
+		     nonthreaded programs without any TLS base set.  */
+		      && ((SYMBOL_BFD_SECTION (msymbol)->flags
+			   & SEC_THREAD_LOCAL) == 0
+			  || target_get_thread_local_address_p()))
 		    {
                     switch (MSYMBOL_TYPE (msymbol))
                       {
Index: gdb/testsuite/gdb.threads/tls-nopthread.c
===================================================================
RCS file: gdb/testsuite/gdb.threads/tls-nopthread.c
diff -N gdb/testsuite/gdb.threads/tls-nopthread.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.threads/tls-nopthread.c	25 Aug 2006 01:42:52 -0000
@@ -0,0 +1,10 @@
+/* Test accessing TLS based variable without -lpthread / TLS setup.  */
+
+#include <pthread.h>
+
+__thread int thread_local = 42;
+
+int main(void)
+{
+  return 0;
+}
Index: gdb/testsuite/gdb.threads/tls-nopthread.exp
===================================================================
RCS file: gdb/testsuite/gdb.threads/tls-nopthread.exp
diff -N gdb/testsuite/gdb.threads/tls-nopthread.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.threads/tls-nopthread.exp	25 Aug 2006 01:42:52 -0000
@@ -0,0 +1,56 @@
+# tls.exp -- Expect script to test thread-local storage without TLS setup
+# Copyright (C) 2006 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+set testfile tls-nopthread
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if [istarget "*-*-linux"] then {
+    set target_cflags "-D_MIT_POSIX_THREADS"
+} else {
+    set target_cflags ""
+}
+
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+if ![runto_main] then {
+   fail "Can't run to main"
+   return 0
+}
+
+# formerly   no debug: Cannot access memory at address 0x0
+# formerly with debug: Cannot find thread-local variables on this target
+# patched    no debug: Address of symbol "thread_local" is unknown.
+#                   OR No symbol table is loaded.  Use the "file" command.
+# patched  with debug: Cannot find thread-local variables on this target
+gdb_test "p thread_local" {.*Address of symbol "thread_local" is unknown..*|.*No symbol table is loaded.  Use the "file" command..*} "thread local storage"
+
+# Done!
+#
+gdb_exit
+
+return 0

[-- Attachment #3: gdb-6.5-bz185337-missing-errno-suggestion.patch --]
[-- Type: text/plain, Size: 923 bytes --]

Index: gdb/c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.35
diff -u -p -r1.35 c-exp.y
--- gdb/c-exp.y	2 Aug 2006 03:13:20 -0000	1.35
+++ gdb/c-exp.y	25 Aug 2006 01:42:21 -0000
@@ -719,8 +719,13 @@ variable:	name_not_typename
 			      else if (!have_full_symbols () && !have_partial_symbols ())
 				error ("No symbol table is loaded.  Use the \"file\" command.");
 			      else
-				error ("No symbol \"%s\" in current context.",
-				       copy_name ($1.stoken));
+			        {
+				  /* https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337  */
+				  if (strcmp (arg, "errno") == 0)
+				    warning ("You should use symbol \"(*__errno_location ())\" or"
+					     " compile the program with `gcc -ggdb3' or `gcc -pthread'.");
+				  error ("No symbol \"%s\" in current context.", arg);
+			        }
 			    }
 			}
 	;

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RFC: Access TLS symbols without DWARF debuginfo
@ 2006-08-25 13:48     ` Jan Kratochvil
  2006-08-25 20:02       ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Kratochvil @ 2006-08-25 13:48 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 750 bytes --]

Hi,

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337

currently if you have threaded (-lpthread) program compiled without debuginfo
"-g" and you try to access TLS symbol you will get:
	(gdb) print thread_local
	Cannot access memory at address 0x0

as gdb tries to resolve TLS-offset as absolute memory reference.

In fact it occurs if you try to access "errno" on -lpthread program with
debuginfo lower than -ggdb3.

Attached patch implements accessing them without the debuginfo suggestions as
not always such associatet debuginfo is available.  It checks for
	SYMBOL_BFD_SECTION (msymbol)->flags & SEC_THREAD_LOCAL
symbols, implements for them new `UNOP_MEMVAL_TLS' and reuses for them former
`dwarf_expr_tls_address'.



Regards,
Jan.

[-- Attachment #2: gdb-6.5-bz185337-resolve-tls-without-debuginfo.patch --]
[-- Type: text/plain, Size: 24159 bytes --]

Index: gdb/dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.33
diff -u -p -r1.33 dwarf2loc.c
--- gdb/dwarf2loc.c	17 Dec 2005 22:33:59 -0000	1.33
+++ gdb/dwarf2loc.c	25 Aug 2006 01:42:22 -0000
@@ -189,86 +189,8 @@ static CORE_ADDR
 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
 {
   struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
-  volatile CORE_ADDR addr = 0;
 
-  if (target_get_thread_local_address_p ()
-      && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
-    {
-      ptid_t ptid = inferior_ptid;
-      struct objfile *objfile = debaton->objfile;
-      volatile struct gdb_exception ex;
-
-      TRY_CATCH (ex, RETURN_MASK_ALL)
-	{
-	  CORE_ADDR lm_addr;
-	  
-	  /* Fetch the load module address for this objfile.  */
-	  lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
-	                                                   objfile);
-	  /* If it's 0, throw the appropriate exception.  */
-	  if (lm_addr == 0)
-	    throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
-			 _("TLS load module not found"));
-
-	  addr = target_get_thread_local_address (ptid, lm_addr, 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
-    error (_("Cannot find thread-local variables on this target"));
-
-  return addr;
+  return target_translate_tls_address (debaton->objfile, offset);
 }
 
 /* Evaluate a location description, starting at DATA and with length
Index: gdb/eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.63
diff -u -p -r1.63 eval.c
--- gdb/eval.c	25 Jul 2006 04:24:50 -0000	1.63
+++ gdb/eval.c	25 Aug 2006 01:42:24 -0000
@@ -2019,6 +2019,18 @@ evaluate_subexp_standard (struct type *e
 	return value_at_lazy (exp->elts[pc + 1].type,
 			      value_as_address (arg1));
 
+    case UNOP_MEMVAL_TLS:
+      (*pos) += 3;
+      arg1 = evaluate_subexp (expect_type, exp, pos, noside);
+      if (noside == EVAL_SKIP)
+	goto nosideret;
+      if (noside == EVAL_AVOID_SIDE_EFFECTS)
+	return value_zero (exp->elts[pc + 2].type, lval_memory);
+      else
+	return value_at_lazy_tls (exp->elts[pc + 2].type,
+				  value_as_address (arg1),
+				  exp->elts[pc + 1].objfile);
+
     case UNOP_PREINCREMENT:
       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
Index: gdb/expprint.c
===================================================================
RCS file: /cvs/src/src/gdb/expprint.c,v
retrieving revision 1.24
diff -u -p -r1.24 expprint.c
--- gdb/expprint.c	7 Aug 2006 03:30:54 -0000	1.24
+++ gdb/expprint.c	25 Aug 2006 01:42:25 -0000
@@ -31,6 +31,7 @@
 #include "target.h"
 #include "gdb_string.h"
 #include "block.h"
+#include "objfiles.h"
 
 #ifdef HAVE_CTYPE_H
 #include <ctype.h>
@@ -414,6 +415,33 @@ print_subexp_standard (struct expression
 	fputs_filtered (")", stream);
       return;
 
+    case UNOP_MEMVAL_TLS:
+      (*pos) += 3;
+      if ((int) prec > (int) PREC_PREFIX)
+	fputs_filtered ("(", stream);
+      if (TYPE_CODE (exp->elts[pc + 2].type) == TYPE_CODE_FUNC &&
+	  exp->elts[pc + 4].opcode == OP_LONG)
+	{
+	  /* We have a minimal symbol fn, probably.  It's encoded
+	     as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
+	     Swallow the OP_LONG (including both its opcodes); ignore
+	     its type; print the value in the type of the MEMVAL.  */
+	  (*pos) += 4;
+	  val = value_at_lazy (exp->elts[pc + 2].type,
+			       (CORE_ADDR) exp->elts[pc + 6].longconst);
+	  value_print (val, stream, 0, Val_no_prettyprint);
+	}
+      else
+	{
+	  fputs_filtered ("{", stream);
+	  type_print (exp->elts[pc + 2].type, "", stream, 0);
+	  fputs_filtered ("} ", stream);
+	  print_subexp (exp, pos, stream, PREC_PREFIX);
+	}
+      if ((int) prec > (int) PREC_PREFIX)
+	fputs_filtered (")", stream);
+      return;
+
     case BINOP_ASSIGN_MODIFY:
       opcode = exp->elts[pc + 1].opcode;
       (*pos) += 2;
@@ -694,6 +722,8 @@ op_name_standard (enum exp_opcode opcode
       return "UNOP_CAST";
     case UNOP_MEMVAL:
       return "UNOP_MEMVAL";
+    case UNOP_MEMVAL_TLS:
+      return "UNOP_MEMVAL_TLS";
     case UNOP_NEG:
       return "UNOP_NEG";
     case UNOP_LOGICAL_NOT:
@@ -999,6 +1029,16 @@ dump_subexp_body_standard (struct expres
       fprintf_filtered (stream, ")");
       elt = dump_subexp (exp, stream, elt + 2);
       break;
+    case UNOP_MEMVAL_TLS:
+      fprintf_filtered (stream, "TLS type @");
+      gdb_print_host_address (exp->elts[elt + 1].type, stream);
+      fprintf_filtered (stream, " (__thread /* \"%s\" */ ",
+                        (exp->elts[elt].objfile == NULL ? "(null)"
+			 : exp->elts[elt].objfile->name));
+      type_print (exp->elts[elt + 1].type, NULL, stream, 0);
+      fprintf_filtered (stream, ")");
+      elt = dump_subexp (exp, stream, elt + 3);
+      break;
     case OP_TYPE:
       fprintf_filtered (stream, "Type @");
       gdb_print_host_address (exp->elts[elt].type, stream);
Index: gdb/expression.h
===================================================================
RCS file: /cvs/src/src/gdb/expression.h,v
retrieving revision 1.18
diff -u -p -r1.18 expression.h
--- gdb/expression.h	17 Dec 2005 22:33:59 -0000	1.18
+++ gdb/expression.h	25 Aug 2006 01:42:26 -0000
@@ -234,6 +234,13 @@ enum exp_opcode
        following subexpression.  */
     UNOP_MEMVAL,
 
+    /* UNOP_MEMVAL_TLS is followed by a `struct objfile' pointer in the next
+       exp_element and a type pointer in the following exp_element.
+       With another UNOP_MEMVAL_TLS at the end, this makes four exp_elements.
+       It casts the contents of the word offsetted by the value of the
+       following subexpression from the TLS specified by `struct objfile'.  */
+    UNOP_MEMVAL_TLS,
+
     /* UNOP_... operate on one value from a following subexpression
        and replace it with a result.  They take no immediate arguments.  */
 
@@ -360,6 +367,7 @@ union exp_element
     struct type *type;
     struct internalvar *internalvar;
     struct block *block;
+    struct objfile *objfile;
   };
 
 struct expression
Index: gdb/parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.53
diff -u -p -r1.53 parse.c
--- gdb/parse.c	6 Jul 2006 14:00:48 -0000	1.53
+++ gdb/parse.c	25 Aug 2006 01:42:29 -0000
@@ -53,6 +53,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "source.h"
+#include "objfiles.h"
 
 /* Standard set of definitions for printing, dumping, prefixifying,
  * and evaluating expressions.  */
@@ -219,6 +220,15 @@ write_exp_elt_block (struct block *b)
 }
 
 void
+write_exp_elt_objfile (struct objfile *objfile)
+{
+  union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
+  tmp.objfile = objfile;
+  write_exp_elt (tmp);
+}
+
+void
 write_exp_elt_longcst (LONGEST expelt)
 {
   union exp_element tmp;
@@ -378,6 +388,9 @@ write_exp_bitstring (struct stoken str)
 static struct type *msym_text_symbol_type;
 static struct type *msym_data_symbol_type;
 static struct type *msym_unknown_symbol_type;
+static struct type *msym_text_tls_symbol_type;
+static struct type *msym_data_tls_symbol_type;
+static struct type *msym_unknown_tls_symbol_type;
 
 void
 write_exp_msymbol (struct minimal_symbol *msymbol, 
@@ -385,6 +398,8 @@ write_exp_msymbol (struct minimal_symbol
 		   struct type *data_symbol_type)
 {
   CORE_ADDR addr;
+  int tls = SYMBOL_BFD_SECTION (msymbol)->flags & SEC_THREAD_LOCAL;
+  enum exp_opcode opcode = tls ? UNOP_MEMVAL_TLS : UNOP_MEMVAL;
 
   write_exp_elt_opcode (OP_LONG);
   /* Let's make the type big enough to hold a 64-bit address.  */
@@ -397,27 +412,49 @@ write_exp_msymbol (struct minimal_symbol
 
   write_exp_elt_opcode (OP_LONG);
 
-  write_exp_elt_opcode (UNOP_MEMVAL);
+  write_exp_elt_opcode (opcode);
+
+  if (opcode == UNOP_MEMVAL_TLS)
+    {
+      bfd *bfd = SYMBOL_BFD_SECTION (msymbol)->owner;
+      struct objfile *ofp;
+
+      ALL_OBJFILES (ofp)
+	if (ofp->obfd == bfd)
+	  break;
+      write_exp_elt_objfile (ofp);
+    }
+
   switch (msymbol->type)
     {
     case mst_text:
     case mst_file_text:
     case mst_solib_trampoline:
-      write_exp_elt_type (msym_text_symbol_type);
+      if (tls)
+	write_exp_elt_type (msym_text_tls_symbol_type);
+      else
+	write_exp_elt_type (msym_text_symbol_type);
       break;
 
     case mst_data:
     case mst_file_data:
     case mst_bss:
     case mst_file_bss:
-      write_exp_elt_type (msym_data_symbol_type);
+      if (tls)
+	write_exp_elt_type (msym_data_tls_symbol_type);
+      else
+	write_exp_elt_type (msym_data_symbol_type);
       break;
 
     default:
-      write_exp_elt_type (msym_unknown_symbol_type);
+      if (tls)
+	write_exp_elt_type (msym_unknown_tls_symbol_type);
+      else
+	write_exp_elt_type (msym_unknown_symbol_type);
       break;
     }
-  write_exp_elt_opcode (UNOP_MEMVAL);
+
+  write_exp_elt_opcode (opcode);
 }
 \f
 /* Recognize tokens that start with '$'.  These include:
@@ -904,6 +941,11 @@ operator_length_standard (struct express
       args = 1;
       break;
 
+    case UNOP_MEMVAL_TLS:
+      oplen = 4;
+      args = 1;
+      break;
+
     case UNOP_ABS:
     case UNOP_CAP:
     case UNOP_CHR:
@@ -1341,6 +1383,17 @@ build_parse (void)
     init_type (TYPE_CODE_INT, 1, 0,
 	       "<variable (not text or data), no debug info>",
 	       NULL);
+
+  msym_text_tls_symbol_type =
+    init_type (TYPE_CODE_FUNC, 1, 0, "<TLS-based text variable, no debug info>", NULL);
+  TYPE_TARGET_TYPE (msym_text_tls_symbol_type) = builtin_type_int;
+  msym_data_tls_symbol_type =
+    init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
+	       "<TLS-based data variable, no debug info>", NULL);
+  msym_unknown_tls_symbol_type =
+    init_type (TYPE_CODE_INT, 1, 0,
+	       "<TLS-based variable (not text or data), no debug info>",
+	       NULL);
 }
 
 /* This function avoids direct calls to fprintf 
Index: gdb/parser-defs.h
===================================================================
RCS file: /cvs/src/src/gdb/parser-defs.h,v
retrieving revision 1.20
diff -u -p -r1.20 parser-defs.h
--- gdb/parser-defs.h	17 Dec 2005 22:34:01 -0000	1.20
+++ gdb/parser-defs.h	25 Aug 2006 01:42:30 -0000
@@ -131,6 +131,8 @@ extern void write_exp_bitstring (struct 
 
 extern void write_exp_elt_block (struct block *);
 
+extern void write_exp_elt_objfile (struct objfile *objfile);
+
 extern void write_exp_msymbol (struct minimal_symbol *,
 			       struct type *, struct type *);
 
Index: gdb/target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.124
diff -u -p -r1.124 target.c
--- gdb/target.c	16 Aug 2006 18:31:03 -0000	1.124
+++ gdb/target.c	25 Aug 2006 01:42:38 -0000
@@ -39,6 +39,7 @@
 #include "regcache.h"
 #include "gdb_assert.h"
 #include "gdbcore.h"
+#include "exceptions.h"
 
 static void target_info (char *, int);
 
@@ -755,6 +756,92 @@ pop_target (void)
   internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
 }
 
+/* Using the objfile specified in BATON, find the address for the
+   current thread's thread-local storage with offset OFFSET.  */
+CORE_ADDR
+target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
+{
+  volatile CORE_ADDR addr = 0;
+
+  if (target_get_thread_local_address_p ()
+      && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
+    {
+      ptid_t ptid = inferior_ptid;
+      volatile struct gdb_exception ex;
+
+      TRY_CATCH (ex, RETURN_MASK_ALL)
+	{
+	  CORE_ADDR lm_addr;
+	  
+	  /* Fetch the load module address for this objfile.  */
+	  lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
+	                                                   objfile);
+	  /* If it's 0, throw the appropriate exception.  */
+	  if (lm_addr == 0)
+	    throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
+			 _("TLS load module not found"));
+
+	  addr = target_get_thread_local_address (ptid, lm_addr, 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
+    error (_("Cannot find thread-local variables on this target"));
+
+  return addr;
+}
+
 #undef	MIN
 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
 
Index: gdb/target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.87
diff -u -p -r1.87 target.h
--- gdb/target.h	15 Aug 2006 18:46:25 -0000	1.87
+++ gdb/target.h	25 Aug 2006 01:42:40 -0000
@@ -1131,6 +1131,9 @@ extern void target_preopen (int);
 
 extern void pop_target (void);
 
+extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
+					       CORE_ADDR offset);
+
 /* Struct section_table maps address ranges to file sections.  It is
    mostly used with BFD files, but can be used without (e.g. for handling
    raw disks, or files not in formats handled by BFD).  */
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.164
diff -u -p -r1.164 valops.c
--- gdb/valops.c	13 Jul 2006 04:31:42 -0000	1.164
+++ gdb/valops.c	25 Aug 2006 01:42:43 -0000
@@ -501,7 +501,8 @@ value_at (struct type *type, CORE_ADDR a
 /* Return a lazy value with type TYPE located at ADDR (cf. value_at).  */
 
 struct value *
-value_at_lazy (struct type *type, CORE_ADDR addr)
+value_at_lazy_tls (struct type *type, CORE_ADDR addr,
+		   struct objfile *tls_objfile)
 {
   struct value *val;
 
@@ -512,11 +513,19 @@ value_at_lazy (struct type *type, CORE_A
 
   VALUE_LVAL (val) = lval_memory;
   VALUE_ADDRESS (val) = addr;
+  if (tls_objfile != NULL)
+    set_value_tls_objfile (val, tls_objfile);
   set_value_lazy (val, 1);
 
   return val;
 }
 
+struct value *
+value_at_lazy (struct type *type, CORE_ADDR addr)
+{
+  return value_at_lazy_tls (type, addr, NULL);
+}
+
 /* Called only from the value_contents and value_contents_all()
    macros, if the current data for a variable needs to be loaded into
    value_contents(VAL).  Fetches the data from the user's process, and
@@ -538,7 +547,17 @@ value_fetch_lazy (struct value *val)
 
   struct type *type = value_type (val);
   if (length)
-    read_memory (addr, value_contents_all_raw (val), length);
+    {
+      struct objfile *tls_objfile = value_tls_objfile (val);
+
+      if (tls_objfile != NULL)
+	{
+	  /* `target_translate_tls_address' uses `inferior_ptid'.  */
+	  addr = target_translate_tls_address (tls_objfile, addr);
+	}
+
+      read_memory (addr, value_contents_all_raw (val), length);
+    }
 
   set_value_lazy (val, 0);
   return 0;
@@ -596,6 +615,7 @@ value_assign (struct value *toval, struc
 	CORE_ADDR changed_addr;
 	int changed_len;
         gdb_byte buffer[sizeof (LONGEST)];
+	struct objfile *tls_objfile = value_tls_objfile (toval);
 
 	if (value_bitsize (toval))
 	  {
@@ -624,6 +644,13 @@ value_assign (struct value *toval, struc
 	    dest_buffer = value_contents (fromval);
 	  }
 
+	if (tls_objfile != NULL)
+	  {
+	    /* `target_translate_tls_address' uses `inferior_ptid'.  */
+	    changed_addr = target_translate_tls_address (tls_objfile,
+							 changed_addr);
+	  }
+
 	write_memory (changed_addr, dest_buffer, changed_len);
 	if (deprecated_memory_changed_hook)
 	  deprecated_memory_changed_hook (changed_addr, changed_len);
Index: gdb/value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.36
diff -u -p -r1.36 value.c
--- gdb/value.c	31 Mar 2006 10:36:18 -0000	1.36
+++ gdb/value.c	25 Aug 2006 01:42:47 -0000
@@ -158,6 +158,9 @@ struct value
      actually exist in the program.  */
   char optimized_out;
 
+  /* TLS owner.  */
+  struct objfile *tls_objfile;
+
   /* Actual contents of the value.  For use of this value; setting it
      uses the stuff above.  Not valid if lazy is nonzero.  Target
      byte-order.  We force it to be aligned properly for any possible
@@ -230,6 +233,7 @@ allocate_value (struct type *type)
   VALUE_REGNUM (val) = -1;
   val->lazy = 0;
   val->optimized_out = 0;
+  val->tls_objfile = NULL;
   val->embedded_offset = 0;
   val->pointed_to_offset = 0;
   val->modifiable = 1;
@@ -344,6 +348,18 @@ set_value_lazy (struct value *value, int
   value->lazy = val;
 }
 
+struct objfile *
+value_tls_objfile (struct value *value)
+{
+  return value->tls_objfile;
+}
+
+void
+set_value_tls_objfile (struct value *value, struct objfile *tls_objfile)
+{
+  value->tls_objfile = tls_objfile;
+}
+
 const gdb_byte *
 value_contents (struct value *value)
 {
Index: gdb/value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.92
diff -u -p -r1.92 value.h
--- gdb/value.h	13 Jul 2006 04:31:42 -0000	1.92
+++ gdb/value.h	25 Aug 2006 01:42:48 -0000
@@ -154,6 +154,10 @@ extern void set_value_embedded_offset (s
 extern int value_lazy (struct value *);
 extern void set_value_lazy (struct value *value, int val);
 
+extern struct objfile *value_tls_objfile (struct value *value);
+extern void set_value_tls_objfile (struct value *value,
+				   struct objfile *tls_objfile);
+
 /* value_contents() and value_contents_raw() both return the address
    of the gdb buffer used to hold a copy of the contents of the lval.
    value_contents() is used when the contents of the buffer are needed
@@ -277,6 +281,8 @@ extern struct value *value_from_double (
 extern struct value *value_from_string (char *string);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
+extern struct value *value_at_lazy_tls (struct type *type, CORE_ADDR addr,
+					struct objfile *tls_objfile);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
 
 extern struct value *value_from_register (struct type *type, int regnum,
Index: gdb/testsuite/gdb.threads/tls-nodebug.c
===================================================================
RCS file: gdb/testsuite/gdb.threads/tls-nodebug.c
diff -N gdb/testsuite/gdb.threads/tls-nodebug.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.threads/tls-nodebug.c	25 Aug 2006 01:42:52 -0000
@@ -0,0 +1,10 @@
+/* Test accessing TLS based variable without any debug info compiled.  */
+
+#include <pthread.h>
+
+__thread int thread_local = 42;
+
+int main(void)
+{
+  return 0;
+}
Index: gdb/testsuite/gdb.threads/tls-nodebug.exp
===================================================================
RCS file: gdb/testsuite/gdb.threads/tls-nodebug.exp
diff -N gdb/testsuite/gdb.threads/tls-nodebug.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.threads/tls-nodebug.exp	25 Aug 2006 01:42:52 -0000
@@ -0,0 +1,52 @@
+# tls.exp -- Expect script to test thread-local storage without debuginfo
+# Copyright (C) 2006 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+set testfile tls-nodebug
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if [istarget "*-*-linux"] then {
+    set target_cflags "-D_MIT_POSIX_THREADS"
+} else {
+    set target_cflags ""
+}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+if ![runto_main] then {
+   fail "Can't run to main"
+   return 0
+}
+
+# Formerly: Cannot access memory at address 0x0
+gdb_test "p thread_local" "= 42" "thread local storage"
+
+# Done!
+#
+gdb_exit
+
+return 0

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Ignore TLS symbols for non-TLS programs
  2006-08-25 13:43 RFC: Ignore TLS symbols for non-TLS programs Jan Kratochvil
@ 2006-08-25 16:43 ` Daniel Jacobowitz
  2006-08-26 11:56   ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-08-25 16:43 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

First a general note: please include changelogs with patches.  Also in
the minor feedback area, updates to included files need to be reflected
in Makefile.in, and URLs to Red Hat's bugzilla are not appropriate for
the FSF GDB; if you want to describe the problem, just do so.

On Fri, Aug 25, 2006 at 04:13:11AM +0200, Jan Kratochvil wrote:
> * with -ggdb2 and less "errno" in fact does not exist anywhere as it was
>   compiled to "(*__errno_location ())" and the macro definition is not present.
>   Unfortunately gdb will find the TLS symbol and it will try to access it but
>   as the program has been compiled without -lpthread the TLS base register
>   (%gs on i386) is not setup and it will result in:
>   	Cannot access memory at address 0x8

That can't be correct.  Every program using glibc references errno.
If the program can access it, then GDB ought to be able to also.
In this case, libc.so.6 exports a dynamic TLS symbol named errno.

Did you try this with the patch you posted earlier to access TLS
without debug info?

> --- gdb/minsyms.c	19 Jul 2006 02:17:23 -0000	1.46
> +++ gdb/minsyms.c	25 Aug 2006 01:42:27 -0000
> @@ -50,6 +50,7 @@
>  #include "demangle.h"
>  #include "value.h"
>  #include "cp-abi.h"
> +#include "target.h"

This violates the abstraction layers.  We're reading the symbols from
a file.  Why should it matter what target we're connected to?  In fact,
we probably aren't connected to a target yet.  Decisions about what we
can access should only be made when we want to access it.

> +/* Test accessing TLS based variable without -lpthread / TLS setup.  */
> +
> +#include <pthread.h>
> +
> +__thread int thread_local = 42;
> +
> +int main(void)
> +{
> +  return 0;
> +}

It would be legal for main to return the value of thread_local, even
though it is not linked to pthread.c.

Oh, and you don't actually need <pthread.h> for this.

> +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {

Did you try this?  [] should give you a TCL syntax error.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo
  2006-08-25 13:48     ` RFC: Access TLS symbols without DWARF debuginfo Jan Kratochvil
@ 2006-08-25 20:02       ` Daniel Jacobowitz
  2006-08-28 18:27         ` RFC: Access TLS symbols without DWARF debuginfo v2 Jan Kratochvil
  2006-10-10  3:22         ` RFC: Access TLS symbols without DWARF debuginfo Daniel Jacobowitz
  0 siblings, 2 replies; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-08-25 20:02 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

On Fri, Aug 25, 2006 at 04:13:04AM +0200, Jan Kratochvil wrote:
> Hi,
> 
> https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
> 
> currently if you have threaded (-lpthread) program compiled without debuginfo
> "-g" and you try to access TLS symbol you will get:
> 	(gdb) print thread_local
> 	Cannot access memory at address 0x0
> 
> as gdb tries to resolve TLS-offset as absolute memory reference.
> 
> In fact it occurs if you try to access "errno" on -lpthread program with
> debuginfo lower than -ggdb3.
> 
> Attached patch implements accessing them without the debuginfo suggestions as
> not always such associatet debuginfo is available.  It checks for
> 	SYMBOL_BFD_SECTION (msymbol)->flags & SEC_THREAD_LOCAL
> symbols, implements for them new `UNOP_MEMVAL_TLS' and reuses for them former
> `dwarf_expr_tls_address'.

Thanks for doing this.  It's a good idea, and the first step to not
needing libthread_db to do this - in most cases the gdbarch vector
should have enough knowledge.  And overall the patch looks very nice.

The same general comments apply as to your other patch, e.g. about a
ChangeLog.

Could you explain why you added a new kind of value for this?  I'd have
thought that when we wanted the address of the symbol, we should be
able to resolve it.  So instead of value_at_lazy_tls, we would resolve
the address using the target.  Expressions persist between threads and
executions, but values shouldn't.  That should simplify the code a
little.


-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Ignore TLS symbols for non-TLS programs
  2006-08-25 16:43 ` Daniel Jacobowitz
@ 2006-08-26 11:56   ` Daniel Jacobowitz
  2006-08-25 13:48     ` RFC: Access TLS symbols without DWARF debuginfo Jan Kratochvil
  0 siblings, 1 reply; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-08-26 11:56 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches

On Thu, Aug 24, 2006 at 11:43:01PM -0400, Daniel Jacobowitz wrote:
> On Fri, Aug 25, 2006 at 04:13:11AM +0200, Jan Kratochvil wrote:
> > * with -ggdb2 and less "errno" in fact does not exist anywhere as it was
> >   compiled to "(*__errno_location ())" and the macro definition is not present.
> >   Unfortunately gdb will find the TLS symbol and it will try to access it but
> >   as the program has been compiled without -lpthread the TLS base register
> >   (%gs on i386) is not setup and it will result in:
> >   	Cannot access memory at address 0x8
> 
> That can't be correct.  Every program using glibc references errno.
> If the program can access it, then GDB ought to be able to also.
> In this case, libc.so.6 exports a dynamic TLS symbol named errno.
> 
> Did you try this with the patch you posted earlier to access TLS
> without debug info?

Oh, I see now - that's not enough, you'd also need to implement direct
DTV lookup in GDB since libthread_db probably can't cope.  And that
might require some fiddling with e.g. the remote protocol, too, to get
at the result of ps_get_thread_area.  Anyway, this is doable, just
a bit of work.

With your other patch, I hope this would get a more appropriate error,
like "can't access thread local data"?

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* RFC: Access TLS symbols without DWARF debuginfo v2
  2006-08-25 20:02       ` Daniel Jacobowitz
@ 2006-08-28 18:27         ` Jan Kratochvil
  2006-08-28 21:02           ` Jim Blandy
  2006-10-10  3:22         ` RFC: Access TLS symbols without DWARF debuginfo Daniel Jacobowitz
  1 sibling, 1 reply; 15+ messages in thread
From: Jan Kratochvil @ 2006-08-28 18:27 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 9034 bytes --]

Hi,

attached a single unifying/dropping patch those 3 patches before.


2006-08-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2loc.c (dwarf_expr_tls_address): Code moved out to
	`target_translate_tls_address'.
	* target.c (target_translate_tls_address): Moved here.
	Provided warnings for TLS `errno' on non-TLS targets.
	* target.h (target_translate_tls_address): Moved here.
	* eval.c (evaluate_subexp_standard): New `UNOP_MEMVAL_TLS'.
	* expprint.c (print_subexp_standard): New `UNOP_MEMVAL_TLS'.
	(op_name_standard): New `UNOP_MEMVAL_TLS'.
	(dump_subexp_body_standard): New `UNOP_MEMVAL_TLS'.
	* expression.h (enum exp_opcode): New `UNOP_MEMVAL_TLS'.
	(union exp_element): New `objfile' type.
	* parse.c (write_exp_elt_objfile): New `objfile' setter.
	(write_exp_msymbol): Support new `UNOP_MEMVAL_TLS'.
	(msym_text_tls_symbol_type, msym_data_tls_symbol_type,
	msym_unknown_tls_symbol_type, build_parse): New TLS types.
	(operator_length_standard): New `UNOP_MEMVAL_TLS'.
	* parser-defs.h (write_exp_elt_objfile): New `objfile' setter.
	* valops.c (value_at_lazy): Pass control to `value_at_lazy_tls'.
	(value_at_lazy_tls): Provide TLS `struct objfile *' storage.
	(value_fetch_lazy): Resolve TLS `struct objfile *' storage.
	(value_assign): Resolve TLS `struct objfile *' storage.
	* value.c (struct value, allocate_value, value_tls_objfile,
	set_value_tls_objfile): Provide TLS `struct objfile *' storage.
	* value.h (value_tls_objfile, set_value_tls_objfile,
	value_at_lazy_tls): Provide TLS `struct objfile *' storage.
	* Makefile.in: Updated dependencies.

2006-08-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.threads/tls-nodebug.c: New file, test TLS symbols on gcc -s.
	* gdb.threads/tls-nodebug.exp: New file, test TLS symbols on gcc -s.


On Fri, 25 Aug 2006 05:43:01 +0200, Daniel Jacobowitz wrote:
> First a general note: please include changelogs with patches.

Forgot again, last time, sorry.  Isn't there some tool to generate this
changelog type templates from the diff?


> Also in the minor feedback area, updates to included files need to be
> reflected in Makefile.in, and URLs to Red Hat's bugzilla are not appropriate
> for the FSF GDB; if you want to describe the problem, just do so.

Thanks for info, to be followed.
Personal info: That gnatsweb is just unusable, move to Bugzilla, please.


> On Fri, Aug 25, 2006 at 04:13:11AM +0200, Jan Kratochvil wrote:
> > * with -ggdb2 and less "errno" in fact does not exist anywhere as it was
> >   compiled to "(*__errno_location ())" and the macro definition is not present.
> >   Unfortunately gdb will find the TLS symbol and it will try to access it but
> >   as the program has been compiled without -lpthread the TLS base register
> >   (%gs on i386) is not setup and it will result in:
> >   	Cannot access memory at address 0x8
> 
> That can't be correct.  Every program using glibc references errno.
> If the program can access it, then GDB ought to be able to also.
> In this case, libc.so.6 exports a dynamic TLS symbol named errno.

If I compile code with or without -pthread (on Fedora Core 5) "errno" is never
found in the target (dynamic) executable.  "errno" is there only with -ggdb3 as:
	DW_MACINFO_define - lineno : 47 macro : errno (*__errno_location ())

Unaware why %gs is not being used in the user code.
%gs-using "errno.h" is available only during glibc compilation.  I get only:

8048915:       e8 1e fc ff ff          call   8048538 <__errno_location@plt>
804891a:       8b 00                   mov    (%eax),%eax
804891c:       89 04 24                mov    %eax,(%esp)


> Did you try this with the patch you posted earlier to access TLS
> without debug info?

Both patches were developed together.  Still that
	RFC: Ignore TLS symbols for non-TLS programs
		gdb-6.5-bz185337-missing-errno-suggestion.patch
had been mostly obsolete by the other one and deprecated after your comments.


> > +++ gdb/minsyms.c	25 Aug 2006 01:42:27 -0000
...
> > +#include "target.h"
> 
> This violates the abstraction layers.  We're reading the symbols from
> a file.  Why should it matter what target we're connected to?  In fact,
> we probably aren't connected to a target yet.  Decisions about what we
> can access should only be made when we want to access it.

You are right, rewritten by your advice.  I had a problem delaying it before as
the TLS `errno' for non-TLS inferior detection had to be written differently.

The trailing part of `target_translate_tls_address' now already contains
	gdb-6.5-bz185337-missing-errno-suggestion.patch


> > +/* Test accessing TLS based variable without -lpthread / TLS setup.  */
> > +
> > +#include <pthread.h>
> > +
> > +__thread int thread_local = 42;
> > +
> > +int main(void)
> > +{
> > +  return 0;
> > +}
> 
> It would be legal for main to return the value of thread_local, even
> though it is not linked to pthread.c.

Sorry but I do not understand a reason to do so.


> Oh, and you don't actually need <pthread.h> for this.

Removed.

> > +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
> 
> Did you try this?  [] should give you a TCL syntax error.

It works, empty command produces empty string.
gdb-unified by '$options', though - thanks.


On Fri, 25 Aug 2006 15:43:16 +0200, Daniel Jacobowitz wrote:
> On Fri, Aug 25, 2006 at 04:13:04AM +0200, Jan Kratochvil wrote:
...
> > Attached patch implements accessing them without the debuginfo suggestions as
> > not always such associatet debuginfo is available.  It checks for
> > 	SYMBOL_BFD_SECTION (msymbol)->flags & SEC_THREAD_LOCAL
> > symbols, implements for them new `UNOP_MEMVAL_TLS' and reuses for them former
> > `dwarf_expr_tls_address'.
...
> Could you explain why you added a new kind of value for this?  I'd have
> thought that when we wanted the address of the symbol, we should be
> able to resolve it.  So instead of value_at_lazy_tls, we would resolve
> the address using the target.  Expressions persist between threads and
> executions, but values shouldn't.  That should simplify the code a
> little.

Sorry, I probably do not have such high overview of the code - what code would
you patch to "resolve the address using the target"?

The following text is probably useless:

% I just did not see there any target-specific code needing to be modified
% as former `dwarf_expr_tls_address' covers it nice.
% 
% I am aware the TLS-resolving should be done as late as possible as
% linux-thread-db.c providing its target_get_thread_local_address_p () may be
% initialized very late.
% 
% The latest possible time is `value_at_lazy_tls' but there is no longer
% available `struct objfile *' for `target_translate_tls_address'.
% So I had to pass such information somehow to `value_at_lazy_tls'.
% 
% The target info is `struct objfile *' for `target_translate_tls_address'.
% The source info is `bfd *' in `write_exp_msymbol'.
% I could store `bfd *' (`SYMBOL_BFD_SECTION (msymbol)->owner')
% or `int' (`SYMBOL_BFD_SECTION (msymbol)->owner->id')
% or `struct objfile *' (resolved from `bfd *').
% 
% I chose `struct objfile *', so I had to extend `struct value' to store it.
% I would have to extend `struct value' by some field anyway.
% I also had to extend `union exp_element' to store the new type there.
% I would have to extend `union exp_element' even for `bfd *',
% only in the case of chosen `bfd.id' `union exp_element' could be reused.
% 
% I do not find much difference how to store this additional information,
% I just did not find a way how to deal without it.


On Fri, 25 Aug 2006 15:47:50 +0200, Daniel Jacobowitz wrote:
> On Thu, Aug 24, 2006 at 11:43:01PM -0400, Daniel Jacobowitz wrote:
> > On Fri, Aug 25, 2006 at 04:13:11AM +0200, Jan Kratochvil wrote:
> > > * with -ggdb2 and less "errno" in fact does not exist anywhere as it was
> > >   compiled to "(*__errno_location ())" and the macro definition is not present.
> > >   Unfortunately gdb will find the TLS symbol and it will try to access it but
> > >   as the program has been compiled without -lpthread the TLS base register
> > >   (%gs on i386) is not setup and it will result in:
> > >   	Cannot access memory at address 0x8
> > 
> > That can't be correct.  Every program using glibc references errno.
> > If the program can access it, then GDB ought to be able to also.
> > In this case, libc.so.6 exports a dynamic TLS symbol named errno.
> > 
> > Did you try this with the patch you posted earlier to access TLS
> > without debug info?
> 
> Oh, I see now - that's not enough, you'd also need to implement direct
> DTV lookup in GDB since libthread_db probably can't cope.  And that
> might require some fiddling with e.g. the remote protocol, too, to get
> at the result of ps_get_thread_area.  Anyway, this is doable, just
> a bit of work.
> 
> With your other patch, I hope this would get a more appropriate error,
> like "can't access thread local data"?

I hope this is no longer to be resolved as this patch got dropped.
Sorry but I do not understand `DTV'.



Regads,
Jan

[-- Attachment #2: gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch --]
[-- Type: text/plain, Size: 26355 bytes --]

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.840
diff -u -p -r1.840 Makefile.in
--- Makefile.in	22 Aug 2006 19:08:31 -0000	1.840
+++ Makefile.in	25 Aug 2006 19:55:35 -0000
@@ -1977,7 +1977,7 @@ exec.o: exec.c $(defs_h) $(frame_h) $(in
 	$(xcoffsolib_h) $(observer_h)
 expprint.o: expprint.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
 	$(value_h) $(language_h) $(parser_defs_h) $(user_regs_h) $(target_h) \
-	$(gdb_string_h) $(block_h)
+	$(gdb_string_h) $(block_h) $(objfiles_h)
 fbsd-nat.o: fbsd-nat.c $(defs_h) $(gdbcore_h) $(inferior_h) $(regcache_h) \
 	$(regset_h) $(gdb_assert_h) $(gdb_string_h) $(elf_bfd_h) \
 	$(fbsd_nat_h)
@@ -2422,7 +2422,7 @@ osabi.o: osabi.c $(defs_h) $(gdb_assert_
 parse.o: parse.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(frame_h) $(expression_h) $(value_h) $(command_h) $(language_h) \
 	$(f_lang_h) $(parser_defs_h) $(gdbcmd_h) $(symfile_h) $(inferior_h) \
-	$(doublest_h) $(gdb_assert_h) $(block_h) $(source_h)
+	$(doublest_h) $(gdb_assert_h) $(block_h) $(source_h) $(objfiles_h)
 p-exp.o: p-exp.c $(defs_h) $(gdb_string_h) $(expression_h) $(value_h) \
 	$(parser_defs_h) $(language_h) $(p_lang_h) $(bfd_h) $(symfile_h) \
 	$(objfiles_h) $(block_h)
@@ -2750,7 +2750,8 @@ symtab.o: symtab.c $(defs_h) $(symtab_h)
 	$(gdb_stat_h) $(cp_abi_h) $(observer_h)
 target.o: target.c $(defs_h) $(gdb_string_h) $(target_h) $(gdbcmd_h) \
 	$(symtab_h) $(inferior_h) $(bfd_h) $(symfile_h) $(objfiles_h) \
-	$(gdb_wait_h) $(dcache_h) $(regcache_h) $(gdb_assert_h) $(gdbcore_h)
+	$(gdb_wait_h) $(dcache_h) $(regcache_h) $(gdb_assert_h) $(gdbcore_h) \
+	$(exceptions_h)
 thread.o: thread.c $(defs_h) $(symtab_h) $(frame_h) $(inferior_h) \
 	$(environ_h) $(value_h) $(target_h) $(gdbthread_h) $(exceptions_h) \
 	$(command_h) $(gdbcmd_h) $(regcache_h) $(gdb_h) $(gdb_string_h) \
Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.33
diff -u -p -r1.33 dwarf2loc.c
--- dwarf2loc.c	17 Dec 2005 22:33:59 -0000	1.33
+++ dwarf2loc.c	25 Aug 2006 19:55:36 -0000
@@ -189,86 +189,8 @@ static CORE_ADDR
 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
 {
   struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
-  volatile CORE_ADDR addr = 0;
 
-  if (target_get_thread_local_address_p ()
-      && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
-    {
-      ptid_t ptid = inferior_ptid;
-      struct objfile *objfile = debaton->objfile;
-      volatile struct gdb_exception ex;
-
-      TRY_CATCH (ex, RETURN_MASK_ALL)
-	{
-	  CORE_ADDR lm_addr;
-	  
-	  /* Fetch the load module address for this objfile.  */
-	  lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
-	                                                   objfile);
-	  /* If it's 0, throw the appropriate exception.  */
-	  if (lm_addr == 0)
-	    throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
-			 _("TLS load module not found"));
-
-	  addr = target_get_thread_local_address (ptid, lm_addr, 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
-    error (_("Cannot find thread-local variables on this target"));
-
-  return addr;
+  return target_translate_tls_address (debaton->objfile, offset);
 }
 
 /* Evaluate a location description, starting at DATA and with length
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.63
diff -u -p -r1.63 eval.c
--- eval.c	25 Jul 2006 04:24:50 -0000	1.63
+++ eval.c	25 Aug 2006 19:55:38 -0000
@@ -2019,6 +2019,18 @@ evaluate_subexp_standard (struct type *e
 	return value_at_lazy (exp->elts[pc + 1].type,
 			      value_as_address (arg1));
 
+    case UNOP_MEMVAL_TLS:
+      (*pos) += 3;
+      arg1 = evaluate_subexp (expect_type, exp, pos, noside);
+      if (noside == EVAL_SKIP)
+	goto nosideret;
+      if (noside == EVAL_AVOID_SIDE_EFFECTS)
+	return value_zero (exp->elts[pc + 2].type, lval_memory);
+      else
+	return value_at_lazy_tls (exp->elts[pc + 2].type,
+				  value_as_address (arg1),
+				  exp->elts[pc + 1].objfile);
+
     case UNOP_PREINCREMENT:
       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
Index: expprint.c
===================================================================
RCS file: /cvs/src/src/gdb/expprint.c,v
retrieving revision 1.24
diff -u -p -r1.24 expprint.c
--- expprint.c	7 Aug 2006 03:30:54 -0000	1.24
+++ expprint.c	25 Aug 2006 19:55:39 -0000
@@ -31,6 +31,7 @@
 #include "target.h"
 #include "gdb_string.h"
 #include "block.h"
+#include "objfiles.h"
 
 #ifdef HAVE_CTYPE_H
 #include <ctype.h>
@@ -414,6 +415,33 @@ print_subexp_standard (struct expression
 	fputs_filtered (")", stream);
       return;
 
+    case UNOP_MEMVAL_TLS:
+      (*pos) += 3;
+      if ((int) prec > (int) PREC_PREFIX)
+	fputs_filtered ("(", stream);
+      if (TYPE_CODE (exp->elts[pc + 2].type) == TYPE_CODE_FUNC &&
+	  exp->elts[pc + 4].opcode == OP_LONG)
+	{
+	  /* We have a minimal symbol fn, probably.  It's encoded
+	     as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address).
+	     Swallow the OP_LONG (including both its opcodes); ignore
+	     its type; print the value in the type of the MEMVAL.  */
+	  (*pos) += 4;
+	  val = value_at_lazy (exp->elts[pc + 2].type,
+			       (CORE_ADDR) exp->elts[pc + 6].longconst);
+	  value_print (val, stream, 0, Val_no_prettyprint);
+	}
+      else
+	{
+	  fputs_filtered ("{", stream);
+	  type_print (exp->elts[pc + 2].type, "", stream, 0);
+	  fputs_filtered ("} ", stream);
+	  print_subexp (exp, pos, stream, PREC_PREFIX);
+	}
+      if ((int) prec > (int) PREC_PREFIX)
+	fputs_filtered (")", stream);
+      return;
+
     case BINOP_ASSIGN_MODIFY:
       opcode = exp->elts[pc + 1].opcode;
       (*pos) += 2;
@@ -694,6 +722,8 @@ op_name_standard (enum exp_opcode opcode
       return "UNOP_CAST";
     case UNOP_MEMVAL:
       return "UNOP_MEMVAL";
+    case UNOP_MEMVAL_TLS:
+      return "UNOP_MEMVAL_TLS";
     case UNOP_NEG:
       return "UNOP_NEG";
     case UNOP_LOGICAL_NOT:
@@ -999,6 +1029,16 @@ dump_subexp_body_standard (struct expres
       fprintf_filtered (stream, ")");
       elt = dump_subexp (exp, stream, elt + 2);
       break;
+    case UNOP_MEMVAL_TLS:
+      fprintf_filtered (stream, "TLS type @");
+      gdb_print_host_address (exp->elts[elt + 1].type, stream);
+      fprintf_filtered (stream, " (__thread /* \"%s\" */ ",
+                        (exp->elts[elt].objfile == NULL ? "(null)"
+			 : exp->elts[elt].objfile->name));
+      type_print (exp->elts[elt + 1].type, NULL, stream, 0);
+      fprintf_filtered (stream, ")");
+      elt = dump_subexp (exp, stream, elt + 3);
+      break;
     case OP_TYPE:
       fprintf_filtered (stream, "Type @");
       gdb_print_host_address (exp->elts[elt].type, stream);
Index: expression.h
===================================================================
RCS file: /cvs/src/src/gdb/expression.h,v
retrieving revision 1.18
diff -u -p -r1.18 expression.h
--- expression.h	17 Dec 2005 22:33:59 -0000	1.18
+++ expression.h	25 Aug 2006 19:55:40 -0000
@@ -234,6 +234,13 @@ enum exp_opcode
        following subexpression.  */
     UNOP_MEMVAL,
 
+    /* UNOP_MEMVAL_TLS is followed by a `struct objfile' pointer in the next
+       exp_element and a type pointer in the following exp_element.
+       With another UNOP_MEMVAL_TLS at the end, this makes four exp_elements.
+       It casts the contents of the word offsetted by the value of the
+       following subexpression from the TLS specified by `struct objfile'.  */
+    UNOP_MEMVAL_TLS,
+
     /* UNOP_... operate on one value from a following subexpression
        and replace it with a result.  They take no immediate arguments.  */
 
@@ -360,6 +367,7 @@ union exp_element
     struct type *type;
     struct internalvar *internalvar;
     struct block *block;
+    struct objfile *objfile;
   };
 
 struct expression
Index: parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.53
diff -u -p -r1.53 parse.c
--- parse.c	6 Jul 2006 14:00:48 -0000	1.53
+++ parse.c	25 Aug 2006 19:55:41 -0000
@@ -53,6 +53,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "source.h"
+#include "objfiles.h"
 
 /* Standard set of definitions for printing, dumping, prefixifying,
  * and evaluating expressions.  */
@@ -219,6 +220,15 @@ write_exp_elt_block (struct block *b)
 }
 
 void
+write_exp_elt_objfile (struct objfile *objfile)
+{
+  union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
+  tmp.objfile = objfile;
+  write_exp_elt (tmp);
+}
+
+void
 write_exp_elt_longcst (LONGEST expelt)
 {
   union exp_element tmp;
@@ -378,6 +388,9 @@ write_exp_bitstring (struct stoken str)
 static struct type *msym_text_symbol_type;
 static struct type *msym_data_symbol_type;
 static struct type *msym_unknown_symbol_type;
+static struct type *msym_text_tls_symbol_type;
+static struct type *msym_data_tls_symbol_type;
+static struct type *msym_unknown_tls_symbol_type;
 
 void
 write_exp_msymbol (struct minimal_symbol *msymbol, 
@@ -385,6 +398,8 @@ write_exp_msymbol (struct minimal_symbol
 		   struct type *data_symbol_type)
 {
   CORE_ADDR addr;
+  int tls = SYMBOL_BFD_SECTION (msymbol)->flags & SEC_THREAD_LOCAL;
+  enum exp_opcode opcode = tls ? UNOP_MEMVAL_TLS : UNOP_MEMVAL;
 
   write_exp_elt_opcode (OP_LONG);
   /* Let's make the type big enough to hold a 64-bit address.  */
@@ -397,27 +412,49 @@ write_exp_msymbol (struct minimal_symbol
 
   write_exp_elt_opcode (OP_LONG);
 
-  write_exp_elt_opcode (UNOP_MEMVAL);
+  write_exp_elt_opcode (opcode);
+
+  if (opcode == UNOP_MEMVAL_TLS)
+    {
+      bfd *bfd = SYMBOL_BFD_SECTION (msymbol)->owner;
+      struct objfile *ofp;
+
+      ALL_OBJFILES (ofp)
+	if (ofp->obfd == bfd)
+	  break;
+      write_exp_elt_objfile (ofp);
+    }
+
   switch (msymbol->type)
     {
     case mst_text:
     case mst_file_text:
     case mst_solib_trampoline:
-      write_exp_elt_type (msym_text_symbol_type);
+      if (tls)
+	write_exp_elt_type (msym_text_tls_symbol_type);
+      else
+	write_exp_elt_type (msym_text_symbol_type);
       break;
 
     case mst_data:
     case mst_file_data:
     case mst_bss:
     case mst_file_bss:
-      write_exp_elt_type (msym_data_symbol_type);
+      if (tls)
+	write_exp_elt_type (msym_data_tls_symbol_type);
+      else
+	write_exp_elt_type (msym_data_symbol_type);
       break;
 
     default:
-      write_exp_elt_type (msym_unknown_symbol_type);
+      if (tls)
+	write_exp_elt_type (msym_unknown_tls_symbol_type);
+      else
+	write_exp_elt_type (msym_unknown_symbol_type);
       break;
     }
-  write_exp_elt_opcode (UNOP_MEMVAL);
+
+  write_exp_elt_opcode (opcode);
 }
 \f
 /* Recognize tokens that start with '$'.  These include:
@@ -904,6 +941,11 @@ operator_length_standard (struct express
       args = 1;
       break;
 
+    case UNOP_MEMVAL_TLS:
+      oplen = 4;
+      args = 1;
+      break;
+
     case UNOP_ABS:
     case UNOP_CAP:
     case UNOP_CHR:
@@ -1341,6 +1383,17 @@ build_parse (void)
     init_type (TYPE_CODE_INT, 1, 0,
 	       "<variable (not text or data), no debug info>",
 	       NULL);
+
+  msym_text_tls_symbol_type =
+    init_type (TYPE_CODE_FUNC, 1, 0, "<TLS-based text variable, no debug info>", NULL);
+  TYPE_TARGET_TYPE (msym_text_tls_symbol_type) = builtin_type_int;
+  msym_data_tls_symbol_type =
+    init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
+	       "<TLS-based data variable, no debug info>", NULL);
+  msym_unknown_tls_symbol_type =
+    init_type (TYPE_CODE_INT, 1, 0,
+	       "<TLS-based variable (not text or data), no debug info>",
+	       NULL);
 }
 
 /* This function avoids direct calls to fprintf 
Index: parser-defs.h
===================================================================
RCS file: /cvs/src/src/gdb/parser-defs.h,v
retrieving revision 1.20
diff -u -p -r1.20 parser-defs.h
--- parser-defs.h	17 Dec 2005 22:34:01 -0000	1.20
+++ parser-defs.h	25 Aug 2006 19:55:41 -0000
@@ -131,6 +131,8 @@ extern void write_exp_bitstring (struct 
 
 extern void write_exp_elt_block (struct block *);
 
+extern void write_exp_elt_objfile (struct objfile *objfile);
+
 extern void write_exp_msymbol (struct minimal_symbol *,
 			       struct type *, struct type *);
 
Index: target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.124
diff -u -p -r1.124 target.c
--- target.c	16 Aug 2006 18:31:03 -0000	1.124
+++ target.c	25 Aug 2006 19:55:43 -0000
@@ -39,6 +39,7 @@
 #include "regcache.h"
 #include "gdb_assert.h"
 #include "gdbcore.h"
+#include "exceptions.h"
 
 static void target_info (char *, int);
 
@@ -755,6 +756,103 @@ pop_target (void)
   internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
 }
 
+/* Using the objfile specified in BATON, find the address for the
+   current thread's thread-local storage with offset OFFSET.  */
+CORE_ADDR
+target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
+{
+  volatile CORE_ADDR addr = 0;
+
+  if (target_get_thread_local_address_p ()
+      && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
+    {
+      ptid_t ptid = inferior_ptid;
+      volatile struct gdb_exception ex;
+
+      TRY_CATCH (ex, RETURN_MASK_ALL)
+	{
+	  CORE_ADDR lm_addr;
+	  
+	  /* Fetch the load module address for this objfile.  */
+	  lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
+	                                                   objfile);
+	  /* If it's 0, throw the appropriate exception.  */
+	  if (lm_addr == 0)
+	    throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
+			 _("TLS load module not found"));
+
+	  addr = target_get_thread_local_address (ptid, lm_addr, 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
+    {
+      struct minimal_symbol *msymbol;
+
+      msymbol = lookup_minimal_symbol ("errno", NULL, NULL);
+      if (msymbol != NULL
+	  && SYMBOL_VALUE_ADDRESS (msymbol) == offset
+	  && SYMBOL_BFD_SECTION (msymbol)->owner == objfile->obfd)
+	error (_("TLS symbol `errno' not resolved for non-TLS program."
+		 " You should use symbol \"(*__errno_location ())\" or"
+		 " compile the program with `gcc -ggdb3' or `gcc -pthread'."));
+      error (_("Cannot find thread-local variables on this target"));
+    }
+
+  return addr;
+}
+
 #undef	MIN
 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
 
Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.87
diff -u -p -r1.87 target.h
--- target.h	15 Aug 2006 18:46:25 -0000	1.87
+++ target.h	25 Aug 2006 19:55:44 -0000
@@ -1131,6 +1131,9 @@ extern void target_preopen (int);
 
 extern void pop_target (void);
 
+extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
+					       CORE_ADDR offset);
+
 /* Struct section_table maps address ranges to file sections.  It is
    mostly used with BFD files, but can be used without (e.g. for handling
    raw disks, or files not in formats handled by BFD).  */
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.164
diff -u -p -r1.164 valops.c
--- valops.c	13 Jul 2006 04:31:42 -0000	1.164
+++ valops.c	25 Aug 2006 19:55:46 -0000
@@ -501,7 +501,8 @@ value_at (struct type *type, CORE_ADDR a
 /* Return a lazy value with type TYPE located at ADDR (cf. value_at).  */
 
 struct value *
-value_at_lazy (struct type *type, CORE_ADDR addr)
+value_at_lazy_tls (struct type *type, CORE_ADDR addr,
+		   struct objfile *tls_objfile)
 {
   struct value *val;
 
@@ -512,11 +513,19 @@ value_at_lazy (struct type *type, CORE_A
 
   VALUE_LVAL (val) = lval_memory;
   VALUE_ADDRESS (val) = addr;
+  if (tls_objfile != NULL)
+    set_value_tls_objfile (val, tls_objfile);
   set_value_lazy (val, 1);
 
   return val;
 }
 
+struct value *
+value_at_lazy (struct type *type, CORE_ADDR addr)
+{
+  return value_at_lazy_tls (type, addr, NULL);
+}
+
 /* Called only from the value_contents and value_contents_all()
    macros, if the current data for a variable needs to be loaded into
    value_contents(VAL).  Fetches the data from the user's process, and
@@ -538,7 +547,17 @@ value_fetch_lazy (struct value *val)
 
   struct type *type = value_type (val);
   if (length)
-    read_memory (addr, value_contents_all_raw (val), length);
+    {
+      struct objfile *tls_objfile = value_tls_objfile (val);
+
+      if (tls_objfile != NULL)
+	{
+	  /* `target_translate_tls_address' uses `inferior_ptid'.  */
+	  addr = target_translate_tls_address (tls_objfile, addr);
+	}
+
+      read_memory (addr, value_contents_all_raw (val), length);
+    }
 
   set_value_lazy (val, 0);
   return 0;
@@ -596,6 +615,7 @@ value_assign (struct value *toval, struc
 	CORE_ADDR changed_addr;
 	int changed_len;
         gdb_byte buffer[sizeof (LONGEST)];
+	struct objfile *tls_objfile = value_tls_objfile (toval);
 
 	if (value_bitsize (toval))
 	  {
@@ -624,6 +644,13 @@ value_assign (struct value *toval, struc
 	    dest_buffer = value_contents (fromval);
 	  }
 
+	if (tls_objfile != NULL)
+	  {
+	    /* `target_translate_tls_address' uses `inferior_ptid'.  */
+	    changed_addr = target_translate_tls_address (tls_objfile,
+							 changed_addr);
+	  }
+
 	write_memory (changed_addr, dest_buffer, changed_len);
 	if (deprecated_memory_changed_hook)
 	  deprecated_memory_changed_hook (changed_addr, changed_len);
Index: value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.36
diff -u -p -r1.36 value.c
--- value.c	31 Mar 2006 10:36:18 -0000	1.36
+++ value.c	25 Aug 2006 19:55:47 -0000
@@ -158,6 +158,9 @@ struct value
      actually exist in the program.  */
   char optimized_out;
 
+  /* TLS owner.  */
+  struct objfile *tls_objfile;
+
   /* Actual contents of the value.  For use of this value; setting it
      uses the stuff above.  Not valid if lazy is nonzero.  Target
      byte-order.  We force it to be aligned properly for any possible
@@ -230,6 +233,7 @@ allocate_value (struct type *type)
   VALUE_REGNUM (val) = -1;
   val->lazy = 0;
   val->optimized_out = 0;
+  val->tls_objfile = NULL;
   val->embedded_offset = 0;
   val->pointed_to_offset = 0;
   val->modifiable = 1;
@@ -344,6 +348,18 @@ set_value_lazy (struct value *value, int
   value->lazy = val;
 }
 
+struct objfile *
+value_tls_objfile (struct value *value)
+{
+  return value->tls_objfile;
+}
+
+void
+set_value_tls_objfile (struct value *value, struct objfile *tls_objfile)
+{
+  value->tls_objfile = tls_objfile;
+}
+
 const gdb_byte *
 value_contents (struct value *value)
 {
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.92
diff -u -p -r1.92 value.h
--- value.h	13 Jul 2006 04:31:42 -0000	1.92
+++ value.h	25 Aug 2006 19:55:48 -0000
@@ -154,6 +154,10 @@ extern void set_value_embedded_offset (s
 extern int value_lazy (struct value *);
 extern void set_value_lazy (struct value *value, int val);
 
+extern struct objfile *value_tls_objfile (struct value *value);
+extern void set_value_tls_objfile (struct value *value,
+				   struct objfile *tls_objfile);
+
 /* value_contents() and value_contents_raw() both return the address
    of the gdb buffer used to hold a copy of the contents of the lval.
    value_contents() is used when the contents of the buffer are needed
@@ -277,6 +281,8 @@ extern struct value *value_from_double (
 extern struct value *value_from_string (char *string);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
+extern struct value *value_at_lazy_tls (struct type *type, CORE_ADDR addr,
+					struct objfile *tls_objfile);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
 
 extern struct value *value_from_register (struct type *type, int regnum,
Index: testsuite/gdb.threads/tls-nodebug.c
===================================================================
RCS file: testsuite/gdb.threads/tls-nodebug.c
diff -N testsuite/gdb.threads/tls-nodebug.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.threads/tls-nodebug.c	25 Aug 2006 19:55:48 -0000
@@ -0,0 +1,8 @@
+/* Test accessing TLS based variable without any debug info compiled.  */
+
+__thread int thread_local = 42;
+
+int main(void)
+{
+  return 0;
+}
Index: testsuite/gdb.threads/tls-nodebug.exp
===================================================================
RCS file: testsuite/gdb.threads/tls-nodebug.exp
diff -N testsuite/gdb.threads/tls-nodebug.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.threads/tls-nodebug.exp	25 Aug 2006 19:55:49 -0000
@@ -0,0 +1,52 @@
+# tls.exp -- Expect script to test thread-local storage without debuginfo
+# Copyright (C) 2006 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+set testfile tls-nodebug
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if [istarget "*-*-linux"] then {
+    set target_cflags "-D_MIT_POSIX_THREADS"
+} else {
+    set target_cflags ""
+}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $options] != "" } {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+if ![runto_main] then {
+   fail "Can't run to main"
+   return 0
+}
+
+# Formerly: Cannot access memory at address 0x0
+gdb_test "p thread_local" "= 42" "thread local storage"
+
+# Done!
+#
+gdb_exit
+
+return 0

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo v2
  2006-08-28 18:27         ` RFC: Access TLS symbols without DWARF debuginfo v2 Jan Kratochvil
@ 2006-08-28 21:02           ` Jim Blandy
  2006-08-29 11:41             ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Jim Blandy @ 2006-08-28 21:02 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Daniel Jacobowitz, gdb-patches

Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> Forgot again, last time, sorry.  Isn't there some tool to generate this
> changelog type templates from the diff?

If you write one, let me know.  :)


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo v2
  2006-08-28 21:02           ` Jim Blandy
@ 2006-08-29 11:41             ` Daniel Jacobowitz
  2006-10-09 20:20               ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-08-29 11:41 UTC (permalink / raw)
  To: Jim Blandy; +Cc: Jan Kratochvil, gdb-patches

On Mon, Aug 28, 2006 at 11:08:11AM -0700, Jim Blandy wrote:
> Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> > Forgot again, last time, sorry.  Isn't there some tool to generate this
> > changelog type templates from the diff?
> 
> If you write one, let me know.  :)

Several exit, I think.  I'm pretty sure I originally got this from
Diego Novillo, and then maybe fixed a bug in it.  Or this might be one
I didn't get from Diego; I didn't leave myself any notes about it :-)

#!/usr/bin/perl

use strict;

my $file = shift @ARGV;
open FILE, $file;

my $dfile;
my $ldfile;
my $ltext;

$ldfile = "";
$ltext = "";
while (<FILE>)
{
  chomp;
  if (/^--- ([^\t]+)\t/) {
    $dfile = $1;
  } elsif (/^@@.*@@ (.*)$/) {
    my $text = $1;
    if ($text !~ /^struct /) {
      $text =~ s/ *\(.*$//;
      $text =~ s/.*  *//;
    }
    next if $text eq $ltext;
    if ($dfile ne $ldfile) {
      print "\t* $dfile ";
      $ldfile = $dfile;
    } else {
      print "\t";
    }
    print "($text):\n";
    $ltext = $text;
  }
}

close OUT;


-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo v2
  2006-08-29 11:41             ` Daniel Jacobowitz
@ 2006-10-09 20:20               ` Daniel Jacobowitz
  0 siblings, 0 replies; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-10-09 20:20 UTC (permalink / raw)
  To: Jim Blandy, Jan Kratochvil, gdb-patches

On Mon, Aug 28, 2006 at 02:27:30PM -0400, Daniel Jacobowitz wrote:
> On Mon, Aug 28, 2006 at 11:08:11AM -0700, Jim Blandy wrote:
> > Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> > > Forgot again, last time, sorry.  Isn't there some tool to generate this
> > > changelog type templates from the diff?
> > 
> > If you write one, let me know.  :)
> 
> Several exit, I think.  I'm pretty sure I originally got this from

"exist"

> Diego Novillo, and then maybe fixed a bug in it.  Or this might be one
> I didn't get from Diego; I didn't leave myself any notes about it :-)

I just stumbled over this message... in fact, I attached a hacky one I
wrote myself last time.  The one I got from Diego, and then fixed bugs
in, is actually much nicer.

#!/usr/bin/perl
# $Id: mklog,v 1.3 2006-10-05 19:43:40 drow Exp $
#
# This script parses a .diff file generated with 'diff -up' or 'diff -cp'
# and writes a skeleton ChangeLog file to stdout. It does not try to be
# very smart when parsing function names, but it produces a reasonable
# approximation.

# Change these settings to reflect your profile. 
$name = "Daniel Jacobowitz";
$addr = "dan\@codesourcery.com";
$date = `date +%Y-%m-%d`; chop ($date);


#-----------------------------------------------------------------------------
# Program starts here. You should not need to edit anything below this
# line.
#-----------------------------------------------------------------------------
if ( $#ARGV != 0 ) {
    $prog = `basename $0`; chop ($prog);
    print "usage: $prog file.diff\n\n";
    print "Adds a ChangeLog template to the start of file.diff\n";
    print "It assumes that file.diff has been created with -up or -cp.\n";
    exit 1;
}

$diff = $ARGV[0];
$dir = `dirname $diff`; chop ($dir);
$base = `basename $diff`; chop ($base);
$cl = `mktemp /tmp/$base.XXXXXX` || exit 1; chop ($cl);
$hdrline = "$date  $name  <$addr>";

open (CLFILE, ">$cl") or die "Could not open file $cl for writing";

print CLFILE "$hdrline\n\n";

# For every file in the .diff print all the function names in ChangeLog
# format.
$bof = 0;
open (DFILE, $diff) or die "Could not open file $diff for reading";
while (<DFILE>) {
    # Check if we found a new file.
    if (/^Index: (.*)$/) {
	# If we have not seen any function names in the previous file (ie,
	# $bof == 1), we just write out a ':' before starting the next
	# file.
	if ($bof == 1) {
	    print CLFILE ":\n";
	}
	$filename = $1;
	print CLFILE "\t* $filename";
	$bof = 1;
    }

    # If we find a new function, print it in brackets.  Special case if
    # this is the first function in a file.  
    #
    # Note that we don't try too hard to find good matches.  This should
    # return a superset of the actual set of functions in the .diff file.
    #
    # The first two patterns work with context diff files (diff -c). The
    # third pattern works with unified diff files (diff -u).

    my $linestart = "[-a-zA-Z0-9_.]+";
    if (/^\*\*\*\*\*\** ($linestart)/
        || /^[\-\+\!] ($linestart)[ \t]*\(.*/
	|| /^@@ .* @@ ($linestart)/)
      {
	$fn = $1;
	if ($seen_names{$fn} == 0) {
	    # If this is the first function in the file, we display it next
	    # to the filename, so we need an extra space before the opening
	    # brace.
	    if ($bof) {
		print CLFILE " ";
		$bof = 0;
	    } else {
		print CLFILE "\t";
	    }

	    print CLFILE "($fn):\n";
	    $seen_names{$fn} = 1;
	}
    }
}

# If we have not seen any function names (ie, $bof == 1), we just
# write out a ':'. This happens when there is only one file with no
# functions.
if ($bof == 1) {
    print CLFILE ":\n";
}

print CLFILE "\n";
close (DFILE);

# Concatenate the ChangeLog template and the original .diff file.
system ("cat $diff >>$cl && mv $cl $diff") == 0
    or die "Could not add the ChangeLog entry to $diff";

exit 0;

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo
  2006-08-25 20:02       ` Daniel Jacobowitz
  2006-08-28 18:27         ` RFC: Access TLS symbols without DWARF debuginfo v2 Jan Kratochvil
@ 2006-10-10  3:22         ` Daniel Jacobowitz
  2006-10-10  4:25           ` Eli Zaretskii
  1 sibling, 1 reply; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-10-10  3:22 UTC (permalink / raw)
  To: Jan Kratochvil, gdb-patches; +Cc: Eli Zaretskii

On Fri, Aug 25, 2006 at 09:43:16AM -0400, Daniel Jacobowitz wrote:
> Thanks for doing this.  It's a good idea, and the first step to not
> needing libthread_db to do this - in most cases the gdbarch vector
> should have enough knowledge.  And overall the patch looks very nice.
> 
> The same general comments apply as to your other patch, e.g. about a
> ChangeLog.
> 
> Could you explain why you added a new kind of value for this?  I'd have
> thought that when we wanted the address of the symbol, we should be
> able to resolve it.  So instead of value_at_lazy_tls, we would resolve
> the address using the target.  Expressions persist between threads and
> executions, but values shouldn't.  That should simplify the code a
> little.

I never saw a response to this question, and the patch got folded into
one of your other big changes.  Combining patches makes it harder to
review them, so I didn't get back to this until now.

I've committed the attached, based on your patch.  I simplified it in a
couple of places.  We don't need to worry about thread-local function
symbols, and evaluating the address earlier saves any changes to the
value infrastructure.

Thanks again for submitting this, and the testcase.

Eli, this patch added support for printing thread local (__thread)
variables in files without debugging information, on platforms where we
could already do it with debugging information.  I'm undecided on
whether that's NEWS-worthy.  What do you think?

I am going to keep reviewing patches, as I can find the time, but my
time to do so is limited; I really need help from the other maintainers
of GDB, and of course the better quality a patch the easier it is to
review :-)  Jan, I'll try to look at some more of yours later.

-- 
Daniel Jacobowitz
CodeSourcery

2006-10-09  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Daniel Jacobowitz  <dan@codesourcery.com>

	* Makefile.in (expprint.o, parse.o, target.o): Update.
	* dwarf2loc.c (dwarf_expr_tls_address): Move body to
	target_translate_tls_address.  Call it.
	* eval.c (evaluate_subexp_standard): Handle UNOP_MEMVAL_TLS.
	* expprint.c (print_subexp_standard): Likewise.
	(op_name_standard, dump_subexp_body_standard): Likewise.
	* expression.h (enum exp_opcode): Add UNOP_MEMVAL_TLS.
	(union exp_element): Add objfile.
	* parse.c (write_exp_elt_objfile): New function.
	(msym_tls_symbol_type): New.
	(write_exp_msymbol): Handle TLS.
	(operator_length_standard): Handle UNOP_MEMVAL_TLS.
	(build_parse): Initialize msym_tls_symbol_type.
	* parser-defs.h (write_exp_elt_objfile): New prototype.
	* target.c (target_translate_tls_address): New.
	* target.h (target_translate_tls_address): Add prototype.

2006-10-09  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.threads/tls-nodebug.c, gdb.threads/tls-nodebug.exp: New test.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.845
diff -u -p -r1.845 Makefile.in
--- Makefile.in	5 Oct 2006 19:42:31 -0000	1.845
+++ Makefile.in	9 Oct 2006 22:25:17 -0000
@@ -1982,7 +1982,7 @@ exec.o: exec.c $(defs_h) $(frame_h) $(in
 	$(xcoffsolib_h) $(observer_h)
 expprint.o: expprint.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
 	$(value_h) $(language_h) $(parser_defs_h) $(user_regs_h) $(target_h) \
-	$(gdb_string_h) $(block_h)
+	$(gdb_string_h) $(block_h) $(objfiles_h)
 fbsd-nat.o: fbsd-nat.c $(defs_h) $(gdbcore_h) $(inferior_h) $(regcache_h) \
 	$(regset_h) $(gdb_assert_h) $(gdb_string_h) $(elf_bfd_h) \
 	$(fbsd_nat_h)
@@ -2429,7 +2429,7 @@ osabi.o: osabi.c $(defs_h) $(gdb_assert_
 parse.o: parse.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(frame_h) $(expression_h) $(value_h) $(command_h) $(language_h) \
 	$(f_lang_h) $(parser_defs_h) $(gdbcmd_h) $(symfile_h) $(inferior_h) \
-	$(doublest_h) $(gdb_assert_h) $(block_h) $(source_h)
+	$(doublest_h) $(gdb_assert_h) $(block_h) $(source_h) $(objfiles_h)
 p-exp.o: p-exp.c $(defs_h) $(gdb_string_h) $(expression_h) $(value_h) \
 	$(parser_defs_h) $(language_h) $(p_lang_h) $(bfd_h) $(symfile_h) \
 	$(objfiles_h) $(block_h)
@@ -2757,7 +2757,8 @@ symtab.o: symtab.c $(defs_h) $(symtab_h)
 	$(gdb_stat_h) $(cp_abi_h) $(observer_h)
 target.o: target.c $(defs_h) $(gdb_string_h) $(target_h) $(gdbcmd_h) \
 	$(symtab_h) $(inferior_h) $(bfd_h) $(symfile_h) $(objfiles_h) \
-	$(gdb_wait_h) $(dcache_h) $(regcache_h) $(gdb_assert_h) $(gdbcore_h)
+	$(gdb_wait_h) $(dcache_h) $(regcache_h) $(gdb_assert_h) $(gdbcore_h) \
+	$(exceptions_h)
 target-memory.o: target-memory.c $(defs_h) $(vec_h) $(target_h) \
 	$(memory_map_h) $(gdb_assert_h)
 thread.o: thread.c $(defs_h) $(symtab_h) $(frame_h) $(inferior_h) \
Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.33
diff -u -p -r1.33 dwarf2loc.c
--- dwarf2loc.c	17 Dec 2005 22:33:59 -0000	1.33
+++ dwarf2loc.c	9 Oct 2006 22:25:17 -0000
@@ -189,86 +189,8 @@ static CORE_ADDR
 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
 {
   struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
-  volatile CORE_ADDR addr = 0;
 
-  if (target_get_thread_local_address_p ()
-      && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
-    {
-      ptid_t ptid = inferior_ptid;
-      struct objfile *objfile = debaton->objfile;
-      volatile struct gdb_exception ex;
-
-      TRY_CATCH (ex, RETURN_MASK_ALL)
-	{
-	  CORE_ADDR lm_addr;
-	  
-	  /* Fetch the load module address for this objfile.  */
-	  lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
-	                                                   objfile);
-	  /* If it's 0, throw the appropriate exception.  */
-	  if (lm_addr == 0)
-	    throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
-			 _("TLS load module not found"));
-
-	  addr = target_get_thread_local_address (ptid, lm_addr, 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
-    error (_("Cannot find thread-local variables on this target"));
-
-  return addr;
+  return target_translate_tls_address (debaton->objfile, offset);
 }
 
 /* Evaluate a location description, starting at DATA and with length
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.63
diff -u -p -r1.63 eval.c
--- eval.c	25 Jul 2006 04:24:50 -0000	1.63
+++ eval.c	9 Oct 2006 22:25:18 -0000
@@ -2019,6 +2019,21 @@ evaluate_subexp_standard (struct type *e
 	return value_at_lazy (exp->elts[pc + 1].type,
 			      value_as_address (arg1));
 
+    case UNOP_MEMVAL_TLS:
+      (*pos) += 3;
+      arg1 = evaluate_subexp (expect_type, exp, pos, noside);
+      if (noside == EVAL_SKIP)
+	goto nosideret;
+      if (noside == EVAL_AVOID_SIDE_EFFECTS)
+	return value_zero (exp->elts[pc + 2].type, lval_memory);
+      else
+	{
+	  CORE_ADDR tls_addr;
+	  tls_addr = target_translate_tls_address (exp->elts[pc + 1].objfile,
+						   value_as_address (arg1));
+	  return value_at_lazy (exp->elts[pc + 2].type, tls_addr);
+	}
+
     case UNOP_PREINCREMENT:
       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
Index: expprint.c
===================================================================
RCS file: /cvs/src/src/gdb/expprint.c,v
retrieving revision 1.24
diff -u -p -r1.24 expprint.c
--- expprint.c	7 Aug 2006 03:30:54 -0000	1.24
+++ expprint.c	9 Oct 2006 22:25:18 -0000
@@ -31,6 +31,7 @@
 #include "target.h"
 #include "gdb_string.h"
 #include "block.h"
+#include "objfiles.h"
 
 #ifdef HAVE_CTYPE_H
 #include <ctype.h>
@@ -414,6 +415,18 @@ print_subexp_standard (struct expression
 	fputs_filtered (")", stream);
       return;
 
+    case UNOP_MEMVAL_TLS:
+      (*pos) += 3;
+      if ((int) prec > (int) PREC_PREFIX)
+	fputs_filtered ("(", stream);
+      fputs_filtered ("{", stream);
+      type_print (exp->elts[pc + 2].type, "", stream, 0);
+      fputs_filtered ("} ", stream);
+      print_subexp (exp, pos, stream, PREC_PREFIX);
+      if ((int) prec > (int) PREC_PREFIX)
+	fputs_filtered (")", stream);
+      return;
+
     case BINOP_ASSIGN_MODIFY:
       opcode = exp->elts[pc + 1].opcode;
       (*pos) += 2;
@@ -694,6 +707,8 @@ op_name_standard (enum exp_opcode opcode
       return "UNOP_CAST";
     case UNOP_MEMVAL:
       return "UNOP_MEMVAL";
+    case UNOP_MEMVAL_TLS:
+      return "UNOP_MEMVAL_TLS";
     case UNOP_NEG:
       return "UNOP_NEG";
     case UNOP_LOGICAL_NOT:
@@ -999,6 +1014,16 @@ dump_subexp_body_standard (struct expres
       fprintf_filtered (stream, ")");
       elt = dump_subexp (exp, stream, elt + 2);
       break;
+    case UNOP_MEMVAL_TLS:
+      fprintf_filtered (stream, "TLS type @");
+      gdb_print_host_address (exp->elts[elt + 1].type, stream);
+      fprintf_filtered (stream, " (__thread /* \"%s\" */ ",
+                        (exp->elts[elt].objfile == NULL ? "(null)"
+			 : exp->elts[elt].objfile->name));
+      type_print (exp->elts[elt + 1].type, NULL, stream, 0);
+      fprintf_filtered (stream, ")");
+      elt = dump_subexp (exp, stream, elt + 3);
+      break;
     case OP_TYPE:
       fprintf_filtered (stream, "Type @");
       gdb_print_host_address (exp->elts[elt].type, stream);
Index: expression.h
===================================================================
RCS file: /cvs/src/src/gdb/expression.h,v
retrieving revision 1.18
diff -u -p -r1.18 expression.h
--- expression.h	17 Dec 2005 22:33:59 -0000	1.18
+++ expression.h	9 Oct 2006 22:25:18 -0000
@@ -234,6 +234,13 @@ enum exp_opcode
        following subexpression.  */
     UNOP_MEMVAL,
 
+    /* UNOP_MEMVAL_TLS is followed by a `struct objfile' pointer in the next
+       exp_element and a type pointer in the following exp_element.
+       With another UNOP_MEMVAL_TLS at the end, this makes four exp_elements.
+       It casts the contents of the word offsetted by the value of the
+       following subexpression from the TLS specified by `struct objfile'.  */
+    UNOP_MEMVAL_TLS,
+
     /* UNOP_... operate on one value from a following subexpression
        and replace it with a result.  They take no immediate arguments.  */
 
@@ -360,6 +367,7 @@ union exp_element
     struct type *type;
     struct internalvar *internalvar;
     struct block *block;
+    struct objfile *objfile;
   };
 
 struct expression
Index: parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.53
diff -u -p -r1.53 parse.c
--- parse.c	6 Jul 2006 14:00:48 -0000	1.53
+++ parse.c	9 Oct 2006 22:25:18 -0000
@@ -53,6 +53,7 @@
 #include "gdb_assert.h"
 #include "block.h"
 #include "source.h"
+#include "objfiles.h"
 
 /* Standard set of definitions for printing, dumping, prefixifying,
  * and evaluating expressions.  */
@@ -219,6 +220,15 @@ write_exp_elt_block (struct block *b)
 }
 
 void
+write_exp_elt_objfile (struct objfile *objfile)
+{
+  union exp_element tmp;
+  memset (&tmp, 0, sizeof (union exp_element));
+  tmp.objfile = objfile;
+  write_exp_elt (tmp);
+}
+
+void
 write_exp_elt_longcst (LONGEST expelt)
 {
   union exp_element tmp;
@@ -378,6 +388,7 @@ write_exp_bitstring (struct stoken str)
 static struct type *msym_text_symbol_type;
 static struct type *msym_data_symbol_type;
 static struct type *msym_unknown_symbol_type;
+static struct type *msym_tls_symbol_type;
 
 void
 write_exp_msymbol (struct minimal_symbol *msymbol, 
@@ -397,6 +408,22 @@ write_exp_msymbol (struct minimal_symbol
 
   write_exp_elt_opcode (OP_LONG);
 
+  if (SYMBOL_BFD_SECTION (msymbol)->flags & SEC_THREAD_LOCAL)
+    {
+      bfd *bfd = SYMBOL_BFD_SECTION (msymbol)->owner;
+      struct objfile *ofp;
+
+      ALL_OBJFILES (ofp)
+	if (ofp->obfd == bfd)
+	  break;
+
+      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
+      write_exp_elt_objfile (ofp);
+      write_exp_elt_type (msym_tls_symbol_type);
+      write_exp_elt_opcode (UNOP_MEMVAL_TLS);
+      return;
+    }
+
   write_exp_elt_opcode (UNOP_MEMVAL);
   switch (msymbol->type)
     {
@@ -904,6 +931,11 @@ operator_length_standard (struct express
       args = 1;
       break;
 
+    case UNOP_MEMVAL_TLS:
+      oplen = 4;
+      args = 1;
+      break;
+
     case UNOP_ABS:
     case UNOP_CAP:
     case UNOP_CHR:
@@ -1341,6 +1373,10 @@ build_parse (void)
     init_type (TYPE_CODE_INT, 1, 0,
 	       "<variable (not text or data), no debug info>",
 	       NULL);
+
+  msym_tls_symbol_type =
+    init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
+	       "<thread local variable, no debug info>", NULL);
 }
 
 /* This function avoids direct calls to fprintf 
Index: parser-defs.h
===================================================================
RCS file: /cvs/src/src/gdb/parser-defs.h,v
retrieving revision 1.20
diff -u -p -r1.20 parser-defs.h
--- parser-defs.h	17 Dec 2005 22:34:01 -0000	1.20
+++ parser-defs.h	9 Oct 2006 22:25:18 -0000
@@ -131,6 +131,8 @@ extern void write_exp_bitstring (struct 
 
 extern void write_exp_elt_block (struct block *);
 
+extern void write_exp_elt_objfile (struct objfile *objfile);
+
 extern void write_exp_msymbol (struct minimal_symbol *,
 			       struct type *, struct type *);
 
Index: target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.126
diff -u -p -r1.126 target.c
--- target.c	21 Sep 2006 14:00:53 -0000	1.126
+++ target.c	9 Oct 2006 22:25:18 -0000
@@ -39,6 +39,7 @@
 #include "regcache.h"
 #include "gdb_assert.h"
 #include "gdbcore.h"
+#include "exceptions.h"
 
 static void target_info (char *, int);
 
@@ -758,6 +759,92 @@ pop_target (void)
   internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
 }
 
+/* Using the objfile specified in BATON, find the address for the
+   current thread's thread-local storage with offset OFFSET.  */
+CORE_ADDR
+target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
+{
+  volatile CORE_ADDR addr = 0;
+
+  if (target_get_thread_local_address_p ()
+      && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
+    {
+      ptid_t ptid = inferior_ptid;
+      volatile struct gdb_exception ex;
+
+      TRY_CATCH (ex, RETURN_MASK_ALL)
+	{
+	  CORE_ADDR lm_addr;
+	  
+	  /* Fetch the load module address for this objfile.  */
+	  lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
+	                                                   objfile);
+	  /* If it's 0, throw the appropriate exception.  */
+	  if (lm_addr == 0)
+	    throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
+			 _("TLS load module not found"));
+
+	  addr = target_get_thread_local_address (ptid, lm_addr, 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
+    error (_("Cannot find thread-local variables on this target"));
+
+  return addr;
+}
+
 #undef	MIN
 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
 
Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.89
diff -u -p -r1.89 target.h
--- target.h	21 Sep 2006 14:00:53 -0000	1.89
+++ target.h	9 Oct 2006 22:25:18 -0000
@@ -1227,6 +1227,9 @@ extern void target_preopen (int);
 
 extern void pop_target (void);
 
+extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
+					       CORE_ADDR offset);
+
 /* Struct section_table maps address ranges to file sections.  It is
    mostly used with BFD files, but can be used without (e.g. for handling
    raw disks, or files not in formats handled by BFD).  */
Index: testsuite/gdb.threads/tls-nodebug.c
===================================================================
RCS file: testsuite/gdb.threads/tls-nodebug.c
diff -N testsuite/gdb.threads/tls-nodebug.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.threads/tls-nodebug.c	9 Oct 2006 22:25:19 -0000
@@ -0,0 +1,10 @@
+/* Test accessing TLS based variable without any debug info compiled.  */
+
+#include <pthread.h>
+
+__thread int thread_local = 42;
+
+int main(void)
+{
+  return 0;
+}
Index: testsuite/gdb.threads/tls-nodebug.exp
===================================================================
RCS file: testsuite/gdb.threads/tls-nodebug.exp
diff -N testsuite/gdb.threads/tls-nodebug.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.threads/tls-nodebug.exp	9 Oct 2006 22:25:19 -0000
@@ -0,0 +1,52 @@
+# tls.exp -- Expect script to test thread-local storage without debuginfo
+# Copyright (C) 2006 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+set testfile tls-nodebug
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if [istarget "*-*-linux"] then {
+    set target_cflags "-D_MIT_POSIX_THREADS"
+} else {
+    set target_cflags ""
+}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+if ![runto_main] then {
+   fail "Can't run to main"
+   return 0
+}
+
+# Formerly: Cannot access memory at address 0x0
+gdb_test "p thread_local" "= 42" "thread local storage"
+
+# Done!
+#
+gdb_exit
+
+return 0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo
  2006-10-10  3:22         ` RFC: Access TLS symbols without DWARF debuginfo Daniel Jacobowitz
@ 2006-10-10  4:25           ` Eli Zaretskii
  2006-10-17 21:03             ` Daniel Jacobowitz
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2006-10-10  4:25 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: jan.kratochvil, gdb-patches

> Date: Mon, 9 Oct 2006 23:22:26 -0400
> From: Daniel Jacobowitz <drow@false.org>
> Cc: Eli Zaretskii <eliz@gnu.org>
> 
> Eli, this patch added support for printing thread local (__thread)
> variables in files without debugging information, on platforms where we
> could already do it with debugging information.  I'm undecided on
> whether that's NEWS-worthy.  What do you think?

I think we should mention it in NEWS.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo
  2006-10-10  4:25           ` Eli Zaretskii
@ 2006-10-17 21:03             ` Daniel Jacobowitz
  2006-10-17 22:03               ` Jan Kratochvil
  2006-10-18  4:27               ` Eli Zaretskii
  0 siblings, 2 replies; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-10-17 21:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: jan.kratochvil, gdb-patches

On Tue, Oct 10, 2006 at 06:25:12AM +0200, Eli Zaretskii wrote:
> > Date: Mon, 9 Oct 2006 23:22:26 -0400
> > From: Daniel Jacobowitz <drow@false.org>
> > Cc: Eli Zaretskii <eliz@gnu.org>
> > 
> > Eli, this patch added support for printing thread local (__thread)
> > variables in files without debugging information, on platforms where we
> > could already do it with debugging information.  I'm undecided on
> > whether that's NEWS-worthy.  What do you think?
> 
> I think we should mention it in NEWS.

Is this OK?

-- 
Daniel Jacobowitz
CodeSourcery

2006-10-17  Daniel Jacobowitz  <dan@codesourcery.com>

	* NEWS: Mention support for TLS without debugging information.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.197
diff -u -p -r1.197 NEWS
--- NEWS	16 Aug 2006 20:33:23 -0000	1.197
+++ NEWS	17 Oct 2006 21:00:23 -0000
@@ -14,6 +14,9 @@ supported.
 * The "set trust-readonly-sections" command works again.  This command was
 broken in GDB 6.3, 6.4, and 6.5.
 
+* Support for GNU/Linux Thread Local Storage (TLS) no longer requires
+symbolic debug information (e.g. DWARF-2).
+
 * New commands
 
 set substitute-path


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo
  2006-10-17 21:03             ` Daniel Jacobowitz
@ 2006-10-17 22:03               ` Jan Kratochvil
  2006-10-18 15:29                 ` Daniel Jacobowitz
  2006-10-18  4:27               ` Eli Zaretskii
  1 sibling, 1 reply; 15+ messages in thread
From: Jan Kratochvil @ 2006-10-17 22:03 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Eli Zaretskii, gdb-patches

On Tue, 17 Oct 2006 23:03:11 +0200, Daniel Jacobowitz wrote:
> On Tue, Oct 10, 2006 at 06:25:12AM +0200, Eli Zaretskii wrote:
...
> > I think we should mention it in NEWS.
> 
> Is this OK?
...
> 2006-10-17  Daniel Jacobowitz  <dan@codesourcery.com>
> 
> 	* NEWS: Mention support for TLS without debugging information.
...
> +* Support for GNU/Linux Thread Local Storage (TLS) no longer requires
> +symbolic debug information (e.g. DWARF-2).
> +

Please note the TLS support is still not complete:

* Support for GNU/Linux Thread Local Storage (TLS) no longer requires
symbolic debug information (e.g. DWARF-2).  It requires the inferior process to
use threads (to be linked -lpthread).



Regards,
Jan


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo
  2006-10-17 21:03             ` Daniel Jacobowitz
  2006-10-17 22:03               ` Jan Kratochvil
@ 2006-10-18  4:27               ` Eli Zaretskii
  1 sibling, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2006-10-18  4:27 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: jan.kratochvil, gdb-patches

> Date: Tue, 17 Oct 2006 17:03:11 -0400
> From: Daniel Jacobowitz <drow@false.org>
> Cc: jan.kratochvil@redhat.com, gdb-patches@sourceware.org
> 
> On Tue, Oct 10, 2006 at 06:25:12AM +0200, Eli Zaretskii wrote:
> > > Date: Mon, 9 Oct 2006 23:22:26 -0400
> > > From: Daniel Jacobowitz <drow@false.org>
> > > Cc: Eli Zaretskii <eliz@gnu.org>
> > > 
> > > Eli, this patch added support for printing thread local (__thread)
> > > variables in files without debugging information, on platforms where we
> > > could already do it with debugging information.  I'm undecided on
> > > whether that's NEWS-worthy.  What do you think?
> > 
> > I think we should mention it in NEWS.
> 
> Is this OK?

Shouldn't we mention thread-local variables explicitly, even if only
as an "e.g."?

Otherwise, fine with me.  Thanks.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: RFC: Access TLS symbols without DWARF debuginfo
  2006-10-17 22:03               ` Jan Kratochvil
@ 2006-10-18 15:29                 ` Daniel Jacobowitz
  0 siblings, 0 replies; 15+ messages in thread
From: Daniel Jacobowitz @ 2006-10-18 15:29 UTC (permalink / raw)
  To: Jan Kratochvil, Eli Zaretskii; +Cc: gdb-patches

On Wed, Oct 18, 2006 at 12:03:13AM +0200, Jan Kratochvil wrote:
> Please note the TLS support is still not complete:
> 
> * Support for GNU/Linux Thread Local Storage (TLS) no longer requires
> symbolic debug information (e.g. DWARF-2).  It requires the inferior process to
> use threads (to be linked -lpthread).

True - but this is NEWS, not a list of limitations, so I'm going to
omit that.

On Wed, Oct 18, 2006 at 06:27:45AM +0200, Eli Zaretskii wrote:
> Shouldn't we mention thread-local variables explicitly, even if only
> as an "e.g."?
> 
> Otherwise, fine with me.  Thanks.

Good point.  I've checked in this version.

-- 
Daniel Jacobowitz
CodeSourcery

2006-10-17  Daniel Jacobowitz  <dan@codesourcery.com>

	* NEWS: Mention support for TLS without debugging information.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.197
diff -u -p -r1.197 NEWS
--- NEWS	16 Aug 2006 20:33:23 -0000	1.197
+++ NEWS	18 Oct 2006 15:28:34 -0000
@@ -14,6 +14,9 @@ supported.
 * The "set trust-readonly-sections" command works again.  This command was
 broken in GDB 6.3, 6.4, and 6.5.
 
+* Support for GNU/Linux Thread Local Storage (TLS, per-thread variables) no
+longer requires symbolic debug information (e.g. DWARF-2).
+
 * New commands
 
 set substitute-path


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-10-18 15:29 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-25 13:43 RFC: Ignore TLS symbols for non-TLS programs Jan Kratochvil
2006-08-25 16:43 ` Daniel Jacobowitz
2006-08-26 11:56   ` Daniel Jacobowitz
2006-08-25 13:48     ` RFC: Access TLS symbols without DWARF debuginfo Jan Kratochvil
2006-08-25 20:02       ` Daniel Jacobowitz
2006-08-28 18:27         ` RFC: Access TLS symbols without DWARF debuginfo v2 Jan Kratochvil
2006-08-28 21:02           ` Jim Blandy
2006-08-29 11:41             ` Daniel Jacobowitz
2006-10-09 20:20               ` Daniel Jacobowitz
2006-10-10  3:22         ` RFC: Access TLS symbols without DWARF debuginfo Daniel Jacobowitz
2006-10-10  4:25           ` Eli Zaretskii
2006-10-17 21:03             ` Daniel Jacobowitz
2006-10-17 22:03               ` Jan Kratochvil
2006-10-18 15:29                 ` Daniel Jacobowitz
2006-10-18  4:27               ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox