This is the mail archive of the gdb-patches@sources.redhat.com 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]

Re: [RFA] Fix compilation failure in hpux-thread.c under HPUX 11.00


> Thanks for looking into this.  Looking at your patch, my first
> impulse was to declare your changes as obvious and tell you to
> commit it.
> 
> But now that I've taken a closer look at find_active_thread(), I
> see the following:
> 
> static int
> find_active_thread (void)
> {
>   ...
> 
>   return (cma_thread_get_unique (&tcb.prolog.client_thread) << 16) 
>          | PIDGET (main_ptid);
> }
> 
> It appears to me that this code is still utilizing the old technique
> of overloading a thread and a pid into the same 32-bit identifier.
> 
> So, find_active_thread() should probably be rewritten as follows:
> 
> static ptid_t
> find_active_thread (void)
> {
>   ...
> 
>   return (ptid_build (PIDGET (main_ptid), 0, 
>                       cma_thread_get_unique (&tcb.prolog.client_thread)));
> }
> 
> My guess is that making the above change will allow hpux-thread.c to
> compile, but that it won't really work right (or even at all) until
> find_tcb() is rewritten.  I think that find_tcb should take a ptid_t
> instead of an int as its thread argument.  It needs to fetch the thread
> by invoking ptid_get_tid() instead of right shifting by 16.
> 
> Once this is done, hpux_pid_to_str() also needs to be revised to
> call ptid_get_tid() instead of shifting the pid result right by 16.

Kevin,

  thanks for your feedback. I have tried to implement your suggestions,
but it is a bit hard for me, because I don't have the knowledge on how
the data structures are organised. I tried to guess as best as I could
and came up with the following patch. I made the changes in emergency
mode because I'm off on a trip the entire next week. You'll have to
excuse me if I don't respond to your comments.

  As a side note, I tried to run the GDB I obtained and did not have
much luck. Setting breakpoints seems ok, although I haven't double
checked the pc addresses. However, when I try to run, GDB prints
"Starting program ..." and then just sits there. The inferior is never
spawned but I get 2 gdb processes for the price of one. I haven't had
time to investigate more, and I'm not sure if this is because of my
changes or not.

Anyway, I'm attaching the patch, awaiting your comments. There is one
static variable that was probably intended to be used as a cache. It was
never assigned a value, so I deleted it for now. I could submit this
obvious change as a separate patch if necessary.

2001-09-28  J. Brobecker <brobecker@gnat.com>

	* hpux-thread.c: rewrite find_active_thread() and find_tcb()
	to use ptid_t, instead of overloading the thread and the pid
        into the same 32-bit value. Make associated necessary adaptations.
        Also remove unused variable cached_active_thread.

Thanks,
-- 
Joel
Index: hpux-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/hpux-thread.c,v
retrieving revision 1.10
diff -c -3 -p -r1.10 hpux-thread.c
*** hpux-thread.c	2001/05/06 22:22:02	1.10
--- hpux-thread.c	2001/09/28 21:09:31
*************** static void init_hpux_thread_ops (void);
*** 69,106 ****
  
  static struct target_ops hpux_thread_ops;
  
! static int find_active_thread (void);
  
  static int cached_thread;
- static int cached_active_thread;
  static cma__t_int_tcb cached_tcb;
  
! static int
  find_active_thread (void)
  {
    static cma__t_int_tcb tcb;
    CORE_ADDR tcb_ptr;
  
-   if (cached_active_thread != 0)
-     return cached_active_thread;
- 
    read_memory ((CORE_ADDR) P_cma__g_current_thread,
  	       (char *) &tcb_ptr,
  	       sizeof tcb_ptr);
  
    read_memory (tcb_ptr, (char *) &tcb, sizeof tcb);
  
!   return (cma_thread_get_unique (&tcb.prolog.client_thread) << 16) 
!          | PIDGET (main_ptid);
  }
  
! static cma__t_int_tcb *find_tcb (int thread);
  
  static cma__t_int_tcb *
! find_tcb (int thread)
  {
    cma__t_known_object queue_header;
    cma__t_queue *queue_ptr;
  
    if (thread == cached_thread)
      return &cached_tcb;
--- 69,103 ----
  
  static struct target_ops hpux_thread_ops;
  
! static ptid_t find_active_thread (void);
  
  static int cached_thread;
  static cma__t_int_tcb cached_tcb;
  
! static ptid_t
  find_active_thread (void)
  {
    static cma__t_int_tcb tcb;
    CORE_ADDR tcb_ptr;
  
    read_memory ((CORE_ADDR) P_cma__g_current_thread,
  	       (char *) &tcb_ptr,
  	       sizeof tcb_ptr);
  
    read_memory (tcb_ptr, (char *) &tcb, sizeof tcb);
  
!   return (ptid_build (PIDGET (main_ptid), 0,
!                       cma_thread_get_unique (&tcb.prolog.client_thread)));
  }
  
! static cma__t_int_tcb *find_tcb (ptid_t ptid);
  
  static cma__t_int_tcb *
! find_tcb (ptid_t ptid)
  {
    cma__t_known_object queue_header;
    cma__t_queue *queue_ptr;
+   int thread = ptid_get_tid (ptid);
  
    if (thread == cached_thread)
      return &cached_tcb;
*************** find_tcb (int thread)
*** 120,133 ****
        read_memory ((CORE_ADDR) tcb_ptr, (char *) &cached_tcb, sizeof cached_tcb);
  
        if (cached_tcb.header.type == cma__c_obj_tcb)
! 	if (cma_thread_get_unique (&cached_tcb.prolog.client_thread) == thread >> 16)
  	  {
  	    cached_thread = thread;
  	    return &cached_tcb;
  	  }
      }
  
!   error ("Can't find TCB %d,%d", thread >> 16, thread & 0xffff);
    return NULL;
  }
  
--- 117,130 ----
        read_memory ((CORE_ADDR) tcb_ptr, (char *) &cached_tcb, sizeof cached_tcb);
  
        if (cached_tcb.header.type == cma__c_obj_tcb)
! 	if (cma_thread_get_unique (&cached_tcb.prolog.client_thread) == thread)
  	  {
  	    cached_thread = thread;
  	    return &cached_tcb;
  	  }
      }
  
!   error ("Can't find TCB %d", thread);
    return NULL;
  }
  
*************** hpux_thread_resume (ptid_t ptid, int ste
*** 193,199 ****
    child_ops.to_resume (ptid, step, signo);
  
    cached_thread = 0;
-   cached_active_thread = 0;
  
    do_cleanups (old_chain);
  }
--- 190,195 ----
*************** hpux_thread_fetch_registers (int regno)
*** 257,263 ****
    int i;
    int first_regno, last_regno;
  
!   tcb_ptr = find_tcb (PIDGET (inferior_ptid));
  
    old_chain = save_inferior_ptid ();
  
--- 253,259 ----
    int i;
    int first_regno, last_regno;
  
!   tcb_ptr = find_tcb (inferior_ptid);
  
    old_chain = save_inferior_ptid ();
  
*************** hpux_thread_store_registers (int regno)
*** 319,325 ****
    int i;
    int first_regno, last_regno;
  
!   tcb_ptr = find_tcb (PIDGET (inferior_ptid));
  
    old_chain = save_inferior_ptid ();
  
--- 315,321 ----
    int i;
    int first_regno, last_regno;
  
!   tcb_ptr = find_tcb (inferior_ptid);
  
    old_chain = save_inferior_ptid ();
  
*************** hpux_pid_to_str (ptid_t ptid)
*** 532,538 ****
    static char buf[100];
    int pid = PIDGET (ptid);
  
!   sprintf (buf, "Thread %d", pid >> 16);
  
    return buf;
  }
--- 528,534 ----
    static char buf[100];
    int pid = PIDGET (ptid);
  
!   sprintf (buf, "Thread %ld", ptid_get_tid (ptid));
  
    return buf;
  }

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