Resume threads

Brethour, Tanya (tonic) tonic@sequent.com
Mon Jul 24 13:56:00 GMT 2000


Hello!

I have a quick question regarding resuming threads. I am currently porting
gdb 5.0 to ptx 4.5+ and I am having some trouble getting the threads to
resume properly.

My question is not a ptx specific question.. but more a GDB question (how is
it supposed to work).

Currently.. I am using a test program that creates 10 threads and they each
call this "Stress" function that does some memory allocation and
dealllocation stress test. I set a breakpoint at stress.. and let gdb fly.
The problem is.. that after it creates the last thread.. it tries to write to
memory (I am assuming this is the breakpoint stuff because they should all be
stopped in Stress at this point) and the thread (inferior_pid) is NOT
stopped. So I get errors when writing to memory and the thread is not
stopped.

Now.. my ptx_thread_resume function.. resumes either the inferior_pid or ALL
the threads.. depending on the pid it is passed. -1 means to resume all
threads (or so I think...). So when its -1 I call iterate_over_threads and
either resume them all.. or step the inferior pid thread (and resume the
rest).

Now being new to GDB.. I might have the different cases messed up. What I
mean.. is that -1 might not mean to resume all threads.. etc. So I am hoping
someone can help.

In addition.. I have played around with my create_inferior function.. and
placed the add_thread(inferior_pid) either before or after the proceed call.
When it is placed after the proceed call.. gdb hangs because my resume
function.. never resumes the inferior_pid because pid=-1 and it is not in the
thread list. However.. if I placed it before.. I get the issue I talked about
above.. where I can not write memory because my thread is not stopped!

The bottom line is: Does anyone have an idea how resume is supposed to work
with threads? Do I have the right idea? And if so.. why would I get errors?
If I do not have the concept correct.. please let me know! In addition..
should the inferior_pid be added before or after the proceed call in the
create_inferior function. See below ..I have pasted my code:


Thanks,
Tanya

struct resumeHLPR
{
  int step;
  int signo;
};

static int ptx_thread_resumeHLPR (struct thread_info *tp, struct resumeHLPR
*resumeinfo)
{
  int Error =0 ;
  int pid = 0;
  int lwpid = 0;

  /*Lets get pid, lwpid from tp->pid*/
  pid = PIDGET(tp->pid);
  lwpid = TIDGET(tp->pid);

  
  if (resumeinfo->step && tp->pid == inferior_pid)
    {
      Error= lwp_trace(TRC_STEP_LWP,pid,lwpid,0,0,0,0);
      /*printf("Step - PID:%X  LWPID:%X\n",pid,lwpid);*/
    }
  else
    {
      Error= lwp_trace(TRC_RESUME_LWP,pid,lwpid,0,0,
		     tp->pid == inferior_pid ? resumeinfo->signo : 0, 0); 
      /*printf("Resume - PID:%X  LWPID:%X\n",pid,lwpid);*/
    }


 return 0;
}



static void ptx_thread_resume (pid, step, signo)
     int pid;
     int step;
     enum target_signal signo;
{

  int Error=0;
  int lwpid=0;
  int savepid = 0;
  
  struct resumeHLPR rinfo;
  rinfo.step = step;
  rinfo.signo = signo;

  if(pid == -1)
    {
      iterate_over_threads(ptx_thread_resumeHLPR,&rinfo);
    }
  
  else
    {
      pid = PIDGET(inferior_pid);
  
      lwpid = TIDGET(inferior_pid);
  
  
      if(step)
      {
	Error= lwp_trace(TRC_STEP_LWP,pid,lwpid,0,0,0,0); 
	printf("Step - PID:%X  LWPID:%X\n",pid,lwpid);
      }
      else
      {
	Error= lwp_trace(TRC_RESUME_LWP,pid,lwpid,0,0,signo,0); 
	printf("Resume - PID:%X  LWPID:%X\n",pid,lwpid);
      }
      
      if(Error)
      printf("Resume_thread %s\n",strerror(Error));
      
      }
 
}

static void
ptx_thread_create_inferior (exec_file, allargs, env)
     char *exec_file;
     char *allargs;
     char **env;
{

 
  fork_inferior (exec_file, allargs, env, lwptrace_me,
		 lwptrace_him, NULL,  NULL);
  
   
  
  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
  push_target (&ptx_thread_ops);

  add_thread (inferior_pid);

}




More information about the Gdb mailing list