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]

[RFA Rodney Brown] gcore for UnixWare



Hello Rodney, 

Sorry for the delay.  These changes make 'gcore' work for Unixware.
I've included the changes for bfd because you'll need them for 
verification (I've submitted them separately to the binutils list
for approval).



2002-02-11  Michael Snyder  <msnyder@redhat.com>

	* procfs.c: Include elf-bfd.h (for elfcore_write functions).
	(gcore section): Ifdef for Solaris and Unixware only.
	(procfs_do_thread_registers): Unixware needs one lwpstatus
	per thread (not one prstatus or pstatus).
	(procfs_make_note_section): Iterate only over kernel threads (lwps),
	not over all gdb threads.  For unixware, call elfcore_write_pstatus
	once before iterating over threads.

Index: procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.35
diff -c -3 -p -r1.35 procfs.c
*** procfs.c	2002/01/09 00:36:58	1.35
--- procfs.c	2002/02/12 00:55:38
*************** Inc., 59 Temple Place - Suite 330, Bosto
*** 23,28 ****
--- 23,29 ----
  #include "inferior.h"
  #include "target.h"
  #include "gdbcore.h"
+ #include "elf-bfd.h"		/* for elfcore_write_* */
  #include "gdbcmd.h"
  #include "gdbthread.h"
  
*************** procfs_first_available (void)
*** 5721,5726 ****
--- 5722,5729 ----
  }
  
  /* ===================  GCORE .NOTE "MODULE" =================== */
+ #if defined (UNIXWARE) || defined (PIOCOPENLWP) || defined (PCAGENT)
+ /* gcore only implemented on solaris and unixware (so far) */
  
  static char *
  procfs_do_thread_registers (bfd *obfd, ptid_t ptid, 
*************** procfs_do_thread_registers (bfd *obfd, p
*** 5733,5744 ****
    merged_pid = TIDGET (ptid) << 16 | PIDGET (ptid);
  
    fill_gregset (&gregs, -1);
    note_data = (char *) elfcore_write_prstatus (obfd,
!                                                note_data,
!                                                note_size,
  					       merged_pid, 
  					       stop_signal,
!                                                &gregs);
    fill_fpregset (&fpregs, -1);
    note_data = (char *) elfcore_write_prfpreg (obfd,
  					      note_data,
--- 5736,5756 ----
    merged_pid = TIDGET (ptid) << 16 | PIDGET (ptid);
  
    fill_gregset (&gregs, -1);
+ #if defined (UNIXWARE)
+   note_data = (char *) elfcore_write_lwpstatus (obfd,
+ 						note_data,
+ 						note_size,
+ 						merged_pid, 
+ 						stop_signal,
+ 						&gregs);
+ #else
    note_data = (char *) elfcore_write_prstatus (obfd,
! 					       note_data,
! 					       note_size,
  					       merged_pid, 
  					       stop_signal,
! 					       &gregs);
! #endif
    fill_fpregset (&fpregs, -1);
    note_data = (char *) elfcore_write_prfpreg (obfd,
  					      note_data,
*************** struct procfs_corefile_thread_data {
*** 5755,5770 ****
  };
  
  static int
! procfs_corefile_thread_callback (struct thread_info *ti, void *data)
  {
    struct procfs_corefile_thread_data *args = data;
-   procinfo *pi = find_procinfo (PIDGET (ti->ptid), TIDGET (ti->ptid));
  
!   if (pi != NULL && TIDGET (ti->ptid) != 0)
      {
        ptid_t saved_ptid = inferior_ptid;
!       inferior_ptid = ti->ptid;
!       args->note_data = procfs_do_thread_registers (args->obfd, ti->ptid, 
  						    args->note_data, 
  						    args->note_size);
        inferior_ptid = saved_ptid;
--- 5767,5781 ----
  };
  
  static int
! procfs_corefile_thread_callback (procinfo *pi, procinfo *thread, void *data)
  {
    struct procfs_corefile_thread_data *args = data;
  
!   if (pi != NULL && thread->tid != 0)
      {
        ptid_t saved_ptid = inferior_ptid;
!       inferior_ptid = MERGEPID (pi->pid, thread->tid);
!       args->note_data = procfs_do_thread_registers (args->obfd, inferior_ptid, 
  						    args->note_data, 
  						    args->note_size);
        inferior_ptid = saved_ptid;
*************** procfs_make_note_section (bfd *obfd, int
*** 5804,5813 ****
  					       fname, 
  					       psargs);
  
    thread_args.obfd = obfd;
    thread_args.note_data = note_data;
    thread_args.note_size = note_size;
!   iterate_over_threads (procfs_corefile_thread_callback, &thread_args);
    if (thread_args.note_data == note_data)
      {
        /* iterate_over_threads didn't come up with any threads;
--- 5815,5832 ----
  					       fname, 
  					       psargs);
  
+ #ifdef UNIXWARE
+   fill_gregset (&gregs, -1);
+   note_data = elfcore_write_pstatus (obfd, note_data, note_size, 
+ 				     PIDGET (inferior_ptid), 
+ 				     stop_signal, &gregs);
+ #endif
+ 
    thread_args.obfd = obfd;
    thread_args.note_data = note_data;
    thread_args.note_size = note_size;
!   proc_iterate_over_threads (pi, procfs_corefile_thread_callback, &thread_args);
! 
    if (thread_args.note_data == note_data)
      {
        /* iterate_over_threads didn't come up with any threads;
*************** procfs_make_note_section (bfd *obfd, int
*** 5824,5827 ****
--- 5843,5847 ----
    return note_data;
  }
  
+ #endif /* Solaris or Unixware */
  /* ===================  END GCORE .NOTE "MODULE" =================== */



2002-02-11  Michael Snyder  <msnyder@redhat.com>

	* elf-bfd.h (elfcore_write_lwpstatus): Add prototype.
	* elf.c (elfcore_grok_pstatus): Add prototype.
	(elfcore_grok_lwpstatus): Add prototype.
	(elfcore_write_lwpstatus): New function.
	(elfcore_write_pstatus): Fix typo, eliminate unnecessary memcpy.

Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.66
diff -c -3 -p -r1.66 elf-bfd.h
*** elf-bfd.h	2002/01/21 10:29:07	1.66
--- elf-bfd.h	2002/02/12 00:50:10
*************** extern char *elfcore_write_prfpreg 
*** 1531,1536 ****
--- 1531,1538 ----
    PARAMS ((bfd *, char *, int *, void *, int));
  extern char *elfcore_write_prxfpreg 
    PARAMS ((bfd *, char *, int *, void *, int));
+ extern char *elfcore_write_lwpstatus 
+   PARAMS ((bfd*, char*, int*, long, int, void*));
  
  /* MIPS ELF specific routines.  */
  
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.127
diff -c -3 -p -r1.127 elf.c
*** elf.c	2002/01/30 10:31:28	1.127
--- elf.c	2002/02/12 00:50:10
*************** elfcore_grok_psinfo (abfd, note)
*** 6148,6153 ****
--- 6148,6155 ----
  #endif /* defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) */
  
  #if defined (HAVE_PSTATUS_T)
+ static boolean elfcore_grok_pstatus PARAMS ((bfd *, Elf_Internal_Note *));
+ 
  static boolean
  elfcore_grok_pstatus (abfd, note)
       bfd *abfd;
*************** elfcore_grok_pstatus (abfd, note)
*** 6185,6190 ****
--- 6187,6194 ----
  #endif /* defined (HAVE_PSTATUS_T) */
  
 #if defined (HAVE_LWPSTATUS_T)
+ static boolean elfcore_grok_lwpstatus PARAMS ((bfd *, Elf_Internal_Note *));
+ 
  static boolean
  elfcore_grok_lwpstatus (abfd, note)
       bfd *abfd;
*************** elfcore_write_prstatus (abfd, buf, bufsi
*** 6598,6603 ****
--- 6602,6639 ----
  }
  #endif /* HAVE_PRSTATUS_T */
  
+ #if defined (HAVE_LWPSTATUS_T)
+ char *
+ elfcore_write_lwpstatus (abfd, buf, bufsiz, pid, cursig, gregs)
+      bfd *abfd;
+      char *buf;
+      int *bufsiz;
+      long pid;
+      int cursig;
+      void *gregs;
+ {
+   lwpstatus_t lwpstat;
+   char *note_name = "CORE";
+ 
+   memset (&lwpstat, 0, sizeof (lwpstat));
+   lwpstat.pr_lwpid  = pid >> 16;
+   lwpstat.pr_cursig = cursig;
+ #if defined (HAVE_LWPSTATUS_T_PR_REG)
+   memcpy (lwpstat.pr_reg, gregs, sizeof (lwpstat.pr_reg));
+ #elif defined (HAVE_LWPSTATUS_T_PR_CONTEXT)
+ #if !defined(gregs)
+   memcpy (lwpstat.pr_context.uc_mcontext.gregs,
+ 	  gregs, sizeof (lwpstat.pr_context.uc_mcontext.gregs));
+ #else
+   memcpy (lwpstat.pr_context.uc_mcontext.__gregs,
+ 	  gregs, sizeof (lwpstat.pr_context.uc_mcontext.__gregs));
+ #endif
+ #endif
+   return elfcore_write_note (abfd, buf, bufsiz, note_name, 
+ 			     NT_LWPSTATUS, &lwpstat, sizeof (lwpstat));
+ }
+ #endif /* HAVE_LWPSTATUS_T */
+ 
  #if defined (HAVE_PSTATUS_T)
  char *
  elfcore_write_pstatus (abfd, buf, bufsiz, pid, cursig, gregs)
*************** elfcore_write_pstatus (abfd, buf, bufsiz
*** 6611,6621 ****
    pstatus_t pstat;
    char *note_name = "CORE";
  
!   memset (&pstat, 0, sizeof (prstat));
!   pstat.pr_pid = pid;
!   memcpy (pstat.pr_reg, gregs, sizeof (pstat.pr_reg));
!   return elfcore_write_note (abfd, buf, bufsiz, 
! 			     note_name, NT_PSTATUS, &pstat, sizeof (pstat));
  }
  #endif /* HAVE_PSTATUS_T */
  
--- 6647,6657 ----
    pstatus_t pstat;
    char *note_name = "CORE";
  
!   memset (&pstat, 0, sizeof (pstat));
!   pstat.pr_pid = pid & 0xffff;
!   buf = elfcore_write_note (abfd, buf, bufsiz, note_name, 
! 			    NT_PSTATUS, &pstat, sizeof (pstat));
!   return buf;
  }
  #endif /* HAVE_PSTATUS_T */
  


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