public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* RFC: change needs_frame_tls_address
@ 2010-07-23 22:33 Tom Tromey
  2010-07-24  1:04 ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2010-07-23 22:33 UTC (permalink / raw)
  To: gdb-patches

I am curious to get reactions on this patch.

This fixes PR 11803, a gdb assertion resulting from trying to print the
TLS variable in this program:

    class A { public: static __thread int num; };
    __thread int A::num = 1;
    int main() { return 0; }

For this we get a warning from value_static_field, then things go
downhill and we hit an internal_error.  From the PR:

(gdb) print A::num
warning: static field's value depends on the current frame - bad debug info?
findvar.c:427: internal-error: read_var_value: Assertion `frame' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) 


After tracing through the TLS code for a bit, I have concluded that TLS
does not really need a frame, at least not in the gdb sense.  Instead, I
think it only needs registers -- a funny sort of distinction to make,
but nevertheless...

With this patch the behavior seems ok:

    (gdb) p A::num
    $1 = 1
    (gdb) kill
    Kill the program being debugged? (y or n) y
    (gdb) p A::num
    Cannot access memory at address 0xb7fdb6d8

If this seems acceptable I will write up a real test case.
If it is not acceptable, I would appreciate some enlightenment as to
what other approach I should take.

This built & regtested ok on x86-64 (compile farm).

Tom

2010-07-23  Tom Tromey  <tromey@redhat.com>

	PR exp/11803:
	* dwarf2loc.c (needs_frame_tls_address): Don't require a frame.

Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.95
diff -u -r1.95 dwarf2loc.c
--- dwarf2loc.c	13 Jul 2010 15:09:03 -0000	1.95
+++ dwarf2loc.c	23 Jul 2010 22:25:56 -0000
@@ -1053,13 +1053,15 @@
   return 1;
 }
 
-/* Thread-local accesses do require a frame.  */
 static CORE_ADDR
 needs_frame_tls_address (void *baton, CORE_ADDR offset)
 {
   struct needs_frame_baton *nf_baton = baton;
 
-  nf_baton->needs_frame = 1;
+  /* Thread-local accesses require registers, but not an actual
+     frame.  This is a funny sort of distinction to make, but it lets
+     us avoid assertions elsewhere in gdb.  */
+  nf_baton->needs_frame = 0;
   return 1;
 }
 

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

* Re: RFC: change needs_frame_tls_address
  2010-07-23 22:33 RFC: change needs_frame_tls_address Tom Tromey
@ 2010-07-24  1:04 ` Pedro Alves
  2010-07-26 13:36   ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2010-07-24  1:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

> For this we get a warning from value_static_field, then things go
> downhill and we hit an internal_error.  From the PR:

(...)

> After tracing through the TLS code for a bit, I have concluded that TLS
> does not really need a frame, at least not in the gdb sense.  Instead, I
> think it only needs registers -- a funny sort of distinction to make,
> but nevertheless...

Given that if you have registers, you always have a frame, I don't
think that's a good check.

>     (gdb) p A::num
>     $1 = 1
>     (gdb) kill
>     Kill the program being debugged? (y or n) y
>     (gdb) p A::num
>     Cannot access memory at address 0xb7fdb6d8

Is that useful?  It seems to be trying to print a bogus
address.  Actually, I'm surprised you even got that memory error
instead of "Cannot find thread-local variables on this target", which
is what I get on x86-64 (both -m64/-m32) with your change applied.
Clearly gdb didn't try reading any register, otherwise, you would see
some other error.  Do you have other changes in your tree perhaps?

> If it is not acceptable, I would appreciate some enlightenment as to
> what other approach I should take.

The warning seems bogus to me:

> (gdb) print A::num
> warning: static field's value depends on the current frame - bad debug info?
> findvar.c:427: internal-error: read_var_value: Assertion `frame' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> Quit this debugging session? (y or n) 

I think we should throw an error instead, just like what you get when
you try to print a non class static global TLS variable:

 __thread int global_num = 1;

Both cases are the same in the user's perpective, so should behave
equal.  Trying to print `global_num' with no process/core throws an
error in value_of_variable.  I guess we should make value_static_field
use value_of_variable instead of read_var_value directly too (or a factored
out variant that doesn't throw if read_var_value returns NULL).

-- 
Pedro Alves

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

* Re: RFC: change needs_frame_tls_address
  2010-07-24  1:04 ` Pedro Alves
@ 2010-07-26 13:36   ` Daniel Jacobowitz
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Jacobowitz @ 2010-07-26 13:36 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Tom Tromey

On Sat, Jul 24, 2010 at 02:04:20AM +0100, Pedro Alves wrote:
> Given that if you have registers, you always have a frame, I don't
> think that's a good check.

Agreed.  Do we need to separate "needs any frame" vs "specific to one
frame" if parts of GDB ask both questions?  This is the same as a
global register variable - which I'm sure GDB messes up too :-)

-- 
Daniel Jacobowitz
CodeSourcery

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

end of thread, other threads:[~2010-07-26 13:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-23 22:33 RFC: change needs_frame_tls_address Tom Tromey
2010-07-24  1:04 ` Pedro Alves
2010-07-26 13:36   ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).