This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix a crash on NULL event_thread


On Sat, 13 Sep 2008 00:44:55 +0200, Pedro Alves wrote:
> On Friday 12 September 2008 23:12:27, Jan Kratochvil wrote:
> > various testcases - such as gdb.threads/bp_in_thread.exp - crash HEAD. 
> > Tested only on Fedora kernel-2.6.27-0.317.rc5.git10.fc10.x86_64 but I
> > expect it can happen anywhere.
> >
> > LINUX_HANDLE_EXTENDED_WAIT calls ADD_LWP but not ADD_THREAD.
> 
> Hmm, it may be due to something having changed in the scheduling, as I'm
> on ubuntu's 2.6.24-19-generic x86_64 SMP (dual core), and I never saw
> that happen.

Yes, the Fedora kernels have a different ptrace implementation (based on
utrace by Roland McGrath) which has more free but still permitted timing.


> Would it be possible to add the thread to the thread list, in
> addition to the lwp?

IMO the reason for two lists is that really these two resources are different.
You can perfectly have tracked LWPs with no corresponding thread structures.
Attached a testcase using clone(2) which if you CTRL-C it has a state:
(gdb) plist thread_list ptid
$1 = {pid = 25112, lwp = 25112, tid = 0}
(gdb) plist lwp_list ptid
$2 = {pid = 25112, lwp = 25115, tid = 0}
$3 = {pid = 25112, lwp = 25112, tid = 0}

New thread notification will come from libthread_db but some time in between
we have no corresponding thread structures such as they will never exist for
standalone LWPs.


Regards,
Jan
#include <unistd.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <sched.h>
#include <sys/mman.h>

#define FLAGS (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND \
	       | CLONE_THREAD | CLONE_SYSVSEM)

static int
child_func (void *arg)
{
  sleep (60);
  _exit (EXIT_SUCCESS);
  abort ();
}

int
main (void)
{
#ifndef PAGE_SIZE
#define PAGE_SIZE 0x1000
#endif
  const size_t stack_size = PAGE_SIZE;
  unsigned char *stack = mmap (NULL, stack_size, PROT_READ | PROT_WRITE,
			       MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  int child_tid;

  assert (stack != NULL);
  assert (stack != MAP_FAILED);
  stack[0] = 0;
  stack[stack_size - 1] = 0;

#ifdef __ia64__
  extern int __clone2 (int (*fn) (void *arg), void *child_stack,
		       size_t stack_size, int flags, void *arg);
  child_tid = __clone2 (child_func, stack + stack_size, stack_size,
			FLAGS, NULL);
#else	/* !__ia64__ */
  child_tid = clone (child_func, stack + stack_size, FLAGS, NULL);
#endif	/* !__ia64__ */

  sleep (60);

  return EXIT_SUCCESS;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]