ba67a79
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
ba67a79
ba67a79
ba67a79
currently for trivia nonthreaded helloworld with no debug info up to -ggdb2 you
ba67a79
will get:
ba67a79
        (gdb) p errno
aefb0e1
        [some error]
ba67a79
ba67a79
* with -ggdb2 and less "errno" in fact does not exist anywhere as it was
ba67a79
  compiled to "(*__errno_location ())" and the macro definition is not present.
ba67a79
  Unfortunately gdb will find the TLS symbol and it will try to access it but
ba67a79
  as the program has been compiled without -lpthread the TLS base register
ba67a79
  (%gs on i386) is not setup and it will result in:
ba67a79
        Cannot access memory at address 0x8
ba67a79
aefb0e1
Attached suggestion patch how to deal with the most common "errno" symbol
ba67a79
for the most common under-ggdb3 compiled programs.
ba67a79
ba67a79
ba67a79
2006-08-25  Jan Kratochvil  <jan.kratochvil@redhat.com>
ba67a79
aefb0e1
	* target.c (target_translate_tls_address): Provided warnings for TLS
aefb0e1
	`errno' on non-TLS targets.
ba67a79
ba67a79
aefb0e1
Index: gdb-6.6/gdb/target.c
ba67a79
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/target.c	2007-01-17 01:25:31.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/target.c	2007-01-20 06:31:36.000000000 +0100
aefb0e1
@@ -898,7 +898,18 @@
aefb0e1
   /* It wouldn't be wrong here to try a gdbarch method, too; finding
aefb0e1
      TLS is an ABI-specific thing.  But we don't do that yet.  */
aefb0e1
   else
ba67a79
-    error (_("Cannot find thread-local variables on this target"));
ba67a79
+    {
ba67a79
+      struct minimal_symbol *msymbol;
ba67a79
+
ba67a79
+      msymbol = lookup_minimal_symbol ("errno", NULL, NULL);
ba67a79
+      if (msymbol != NULL
ba67a79
+	  && SYMBOL_VALUE_ADDRESS (msymbol) == offset
ba67a79
+	  && SYMBOL_BFD_SECTION (msymbol)->owner == objfile->obfd)
ba67a79
+	error (_("TLS symbol `errno' not resolved for non-TLS program."
ba67a79
+		 " You should use symbol \"(*__errno_location ())\" or"
ba67a79
+		 " compile the program with `gcc -ggdb3' or `gcc -pthread'."));
ba67a79
+      error (_("Cannot find thread-local variables on this target"));
ba67a79
+    }
ba67a79
 
aefb0e1
   return addr;
ba67a79
 }