[PATCH] Make gcore work for sparc64 solaris

Michael Snyder msnyder@cygnus.com
Wed Feb 13 17:58:00 GMT 2002


These changes make the generate-core-file command work for
64 bit sparc solaris.

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

	* gcore.c (gcore_command): Use gcore_default_target instead of NULL.
	(default_gcore_mach): Just return 0, work around a problem in bfd.
	(default_gcore_target): OK to return NULL if exec_bfd is null.
	(make_mem_sec): Use a cast, avoid a warning.

	* procfs.c (find_memory_regions_callback): Use a cast instead of
	calling host_pointer_to_address (which complains if 
	sizeof (host pointer) != sizeof (target pointer)).
	(procfs_make_note_section): Avoid overflow in psargs string.

Index: gcore.c
===================================================================
RCS file: /cvs/src/src/gdb/gcore.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 gcore.c
*** gcore.c	2002/01/14 20:00:48	1.3
--- gcore.c	2002/02/14 01:52:01
*************** gcore_command (char *args, int from_tty)
*** 63,69 ****
  		      "Opening corefile '%s' for output.\n", corefilename);
  
    /* Open the output file. */
!   if (!(obfd = bfd_openw (corefilename, NULL /*default_gcore_target ()*/)))
      {
        error ("Failed to open '%s' for output.", corefilename);
      }
--- 63,69 ----
  		      "Opening corefile '%s' for output.\n", corefilename);
  
    /* Open the output file. */
!   if (!(obfd = bfd_openw (corefilename, default_gcore_target ())))
      {
        error ("Failed to open '%s' for output.", corefilename);
      }
*************** gcore_command (char *args, int from_tty)
*** 117,132 ****
  static unsigned long
  default_gcore_mach (void)
  {
  #ifdef TARGET_ARCHITECTURE
    const struct bfd_arch_info * bfdarch = TARGET_ARCHITECTURE;
  
    if (bfdarch != NULL)
      return bfdarch->mach;
! #endif
    if (exec_bfd == NULL)
      error ("Can't find default bfd machine type (need execfile).");
  
    return bfd_get_mach (exec_bfd);
  }
  
  static enum bfd_architecture
--- 117,136 ----
  static unsigned long
  default_gcore_mach (void)
  {
+ #if 1	/* See if this even matters... */
+   return 0;
+ #else
  #ifdef TARGET_ARCHITECTURE
    const struct bfd_arch_info * bfdarch = TARGET_ARCHITECTURE;
  
    if (bfdarch != NULL)
      return bfdarch->mach;
! #endif /* TARGET_ARCHITECTURE */
    if (exec_bfd == NULL)
      error ("Can't find default bfd machine type (need execfile).");
  
    return bfd_get_mach (exec_bfd);
+ #endif /* 1 */
  }
  
  static enum bfd_architecture
*************** default_gcore_target (void)
*** 149,157 ****
  {
    /* FIXME -- this may only work for ELF targets.  */
    if (exec_bfd == NULL)
!     error ("Can't find default bfd target for corefile (need execfile).");
! 
!   return bfd_get_target (exec_bfd);
  }
  
  /*
--- 153,161 ----
  {
    /* FIXME -- this may only work for ELF targets.  */
    if (exec_bfd == NULL)
!     return NULL;
!   else
!     return bfd_get_target (exec_bfd);
  }
  
  /*
*************** make_mem_sec (bfd *obfd, 
*** 344,351 ****
    if (info_verbose)
      {
        fprintf_filtered (gdb_stdout, 
! 			"Save segment, %ld bytes at 0x%s\n",
! 			size, paddr_nz (addr));
      }
  
    bfd_set_section_size (obfd, osec, size);
--- 348,355 ----
    if (info_verbose)
      {
        fprintf_filtered (gdb_stdout, 
! 			"Save segment, %lld bytes at 0x%s\n",
! 			(long long) size, paddr_nz (addr));
      }
  
    bfd_set_section_size (obfd, osec, size);
Index: procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.36
diff -c -3 -p -r1.36 procfs.c
*** procfs.c	2002/02/13 22:03:46	1.36
--- procfs.c	2002/02/14 01:52:02
*************** find_memory_regions_callback (struct prm
*** 5388,5394 ****
  					   void *),
  			      void *data)
  {
!   return (*func) (host_pointer_to_address ((void *) map->pr_vaddr),
  		  map->pr_size, 
  		  (map->pr_mflags & MA_READ) != 0,
  		  (map->pr_mflags & MA_WRITE) != 0,
--- 5388,5394 ----
  					   void *),
  			      void *data)
  {
!   return (*func) ((CORE_ADDR) map->pr_vaddr,
  		  map->pr_size, 
  		  (map->pr_mflags & MA_READ) != 0,
  		  (map->pr_mflags & MA_WRITE) != 0,
*************** procfs_make_note_section (bfd *obfd, int
*** 5793,5798 ****
--- 5793,5799 ----
    char psargs[80] = {'\0'};
    procinfo *pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
    char *note_data = NULL;
+   char *inf_args;
    struct procfs_corefile_thread_data thread_args;
  
    if (get_exec_file (0))
*************** procfs_make_note_section (bfd *obfd, int
*** 5800,5810 ****
        strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
        strncpy (psargs, get_exec_file (0), 
  	       sizeof (psargs));
!       if (get_inferior_args ())
  	{
  	  strncat (psargs, " ", 
  		   sizeof (psargs) - strlen (psargs));
! 	  strncat (psargs, get_inferior_args (), 
  		   sizeof (psargs) - strlen (psargs));
  	}
      }
--- 5801,5814 ----
        strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
        strncpy (psargs, get_exec_file (0), 
  	       sizeof (psargs));
! 
!       inf_args = get_inferior_args ();
!       if (inf_args && *inf_args &&
! 	  strlen (inf_args) < ((int) sizeof (psargs) - (int) strlen (psargs)))
  	{
  	  strncat (psargs, " ", 
  		   sizeof (psargs) - strlen (psargs));
! 	  strncat (psargs, inf_args, 
  		   sizeof (psargs) - strlen (psargs));
  	}
      }



More information about the Gdb-patches mailing list