public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug threads/13448] New: char[] thread local variables displayed incorrectly
@ 2011-11-29 12:29 ben.cohen at kognitio dot com
  2011-11-29 14:50 ` [Bug threads/13448] " ben.cohen at kognitio dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ben.cohen at kognitio dot com @ 2011-11-29 12:29 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=13448

             Bug #: 13448
           Summary: char[] thread local variables displayed incorrectly
           Product: gdb
           Version: 7.3
            Status: NEW
          Severity: normal
          Priority: P2
         Component: threads
        AssignedTo: unassigned@sourceware.org
        ReportedBy: ben.cohen@kognitio.com
    Classification: Unclassified


Created attachment 6079
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6079
Example of incorrect "print myname" and then correct after bt

Thread-local variables that are of type char[] aren't printed correctly for
some threads.

Compile and run the following file and use gdb to attach or debug a core dump. 
Then "print myname" or "thread apply all print myname" prints some unknown
number rather than that variable.  See the attached file for an example of the
output.

If you subsequently do for example a backtrace then the same print command will
work after that.

If you change the program so that either of the threads does "while (1) {}"
rather than sleeping then "t a a p myname" works correctly from the start. 
Perhaps it is something to do with the threads being in a system call?

If you use for example a char, int or int[] thread local variable this bug
doesn't happen.

This is a bug in 7.3.1 but not in 7.1 or 7.2 (I haven't tried 7.3).


/* thread_local_var.c: Compile with:
 *     gcc -o thread_local_var thread_local_var.c -pthread -ggdb
 */
#include <string.h>
#include <pthread.h>

__thread char myname[128] = "(unnamed thread)";

void *th(void* x)
{
  strcpy(myname, "a new thread");
  while(1) sleep(1);
}

main()
{
  pthread_t t;

  strcpy(myname, "this is the main thread");
  pthread_create(&t, NULL, th, NULL);
  while(1) sleep(1);
}

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

end of thread, other threads:[~2011-12-02 17:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-29 12:29 [Bug threads/13448] New: char[] thread local variables displayed incorrectly ben.cohen at kognitio dot com
2011-11-29 14:50 ` [Bug threads/13448] " ben.cohen at kognitio dot com
2011-11-29 14:51 ` ben.cohen at kognitio dot com
2011-11-29 18:14 ` tromey at redhat dot com
2011-11-29 23:15 ` jan.kratochvil at redhat dot com
2011-12-01  2:34 ` jan.kratochvil at redhat dot com
2011-12-02  1:09 ` jan.kratochvil at redhat dot com
2011-12-02 17:02 ` cvs-commit at gcc dot gnu.org
2011-12-02 17:03 ` jan.kratochvil at redhat dot com

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).