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]
Other format: [Raw text]

infttrace vs attach.exp



attach.exp was failing a number of tests because we were unable to
derive the exec file when attaching to a process.

According to HP, there's a bug in the kernel which affects the ttrace
call to get the exec file in certain circumstances.  Luckily, if the 
ttrace call fails, we can fall back to pstat to get the information we
need.  

This patch implements the pstat fall-back and removes the old code which
tried to guess the base of the processes stack and use that to try
and find an exec name in the stack (ick).

With this patch attach.exp runs on hpux11 without any unexpected failures.

	* infttrace.c: Include <sys/pstat.h>.
	(child_pid_to_exec_file): Revamp.  Use pstat call to get the
	exec file if the ttrace equivalent fails.

Index: infttrace.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/infttrace.c,v
retrieving revision 2.22.14.1
diff -c -3 -p -r2.22.14.1 infttrace.c
*** infttrace.c	2001/12/18 17:51:05	2.22.14.1
--- infttrace.c	2001/12/20 04:56:19
***************
*** 28,33 ****
--- 28,41 ----
  #include "gdb_wait.h"
  #include "command.h"
  
+ /* We need pstat functionality so that we can get the exec file
+    for a process we attach to.
+ 
+    According to HP, we should use the 64bit interfaces, so we
+    define _PSTAT64 to achieve this.  */
+ #define _PSTAT64
+ #include <sys/pstat.h>
+ 
  /* Some hackery to work around a use of the #define name NO_FLAGS
   * in both gdb and HPUX (bfd.h and /usr/include/machine/vmparam.h).
   */
*************** udot_info (void)
*** 5056,5134 ****
  }
  #endif /* !defined (CHILD_XFER_MEMORY).  */
  
  /* TTrace version of "target_pid_to_exec_file"
   */
  char *
  child_pid_to_exec_file (int tid)
  {
-   static char exec_file_buffer[1024];
    int tt_status;
!   CORE_ADDR top_of_stack;
!   char four_chars[4];
!   int name_index;
!   int i;
!   int done;
!   ptid_t saved_inferior_ptid;
  
!   /* As of 10.x HP-UX, there's an explicit request to get the
!    *pathname.
!    */
    tt_status = call_ttrace (TT_PROC_GET_PATHNAME,
  			   tid,
! 			   (TTRACE_ARG_TYPE) exec_file_buffer,
! 			   (TTRACE_ARG_TYPE) sizeof (exec_file_buffer) - 1,
! 			   TT_NIL);
    if (tt_status >= 0)
      return exec_file_buffer;
- 
-   /* ??rehrauer: The above request may or may not be broken.  It
-      doesn't seem to work when I use it.  But, it may be designed
-      to only work immediately after an exec event occurs.  (I'm
-      waiting for COSL to explain.)
- 
-      In any case, if it fails, try a really, truly amazingly gross
-      hack that DDE uses, of pawing through the process' data
-      segment to find the pathname.
-    */
-   top_of_stack = (TARGET_PTR_BIT == 64 ? 0x800003ffff7f0000 : 0x7b03a000);
-   name_index = 0;
-   done = 0;
  
!   /* On the chance that pid != inferior_ptid, set inferior_ptid
!      to pid, so that (grrrr!) implicit uses of inferior_ptid get
!      the right id.
!    */
!   saved_inferior_ptid = inferior_ptid;
!   inferior_ptid = pid_to_ptid (tid);
! 
!   /* Try to grab a null-terminated string. */
!   while (!done)
      {
!       if (target_read_memory (top_of_stack, four_chars, 4) != 0)
! 	{
! 	  inferior_ptid = saved_inferior_ptid;
! 	  return NULL;
! 	}
!       for (i = 0; i < 4; i++)
! 	{
! 	  exec_file_buffer[name_index++] = four_chars[i];
! 	  done = (four_chars[i] == '\0');
! 	  if (done)
! 	    break;
! 	}
!       top_of_stack += 4;
!     }
  
!   if (exec_file_buffer[0] == '\0')
!     {
!       inferior_ptid = saved_inferior_ptid;
!       return NULL;
      }
  
!   inferior_ptid = saved_inferior_ptid;
!   return exec_file_buffer;
  }
- 
  
  void
  pre_fork_inferior (void)
--- 5064,5106 ----
  }
  #endif /* !defined (CHILD_XFER_MEMORY).  */
  
+ 
  /* TTrace version of "target_pid_to_exec_file"
   */
  char *
  child_pid_to_exec_file (int tid)
  {
    int tt_status;
!   static char exec_file_buffer[1024];
!   pid_t pid;
!   static struct pst_status buf;
  
!   /* On various versions of hpux11, this may fail due to a supposed
!      kernel bug.  We have alternate methods to get this information
!      (ie pstat).  */
    tt_status = call_ttrace (TT_PROC_GET_PATHNAME,
  			   tid,
! 			   (uint64_t) exec_file_buffer,
! 			   sizeof (exec_file_buffer) - 1,
! 			   0);
    if (tt_status >= 0)
      return exec_file_buffer;
  
!   /* Try to get process information via pstat and extract the filename
!      from the pst_cmd field within the pst_status structure.  */
!   if (pstat_getproc (&buf, sizeof (struct pst_status), 0, tid) != -1)
      {
!       char *p = buf.pst_cmd;
  
!       while (*p && *p != ' ')
! 	p++;
!       *p = 0;
! 
!       return (buf.pst_cmd);
      }
  
!   return (NULL);
  }
  
  void
  pre_fork_inferior (void)





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