gdb/gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
Jan Kratochvil aefb0e1e23 - Upgrade to GDB 6.6. Drop redundant patches, forward-port remaining ones.
- Backported post gdb-6.6 release ia64 unwinding fixups.
- Testcase for exec() from threaded program (BZ 202689).
- Resolves: rhbz#221125
- Related: rhbz#202689
2007-01-21 01:53:01 +00:00

50 lines
1.8 KiB
Diff

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
[some error]
* 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
Attached suggestion patch how to deal with the most common "errno" symbol
for the most common under-ggdb3 compiled programs.
2006-08-25 Jan Kratochvil <jan.kratochvil@redhat.com>
* target.c (target_translate_tls_address): Provided warnings for TLS
`errno' on non-TLS targets.
Index: gdb-6.6/gdb/target.c
===================================================================
--- gdb-6.6.orig/gdb/target.c 2007-01-17 01:25:31.000000000 +0100
+++ gdb-6.6/gdb/target.c 2007-01-20 06:31:36.000000000 +0100
@@ -898,7 +898,18 @@
/* 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"));
+ {
+ 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;
}