Package: gdb
Version: 7.2-1
Severity: normal
Tags: patch
User: [email protected]
Usertags: origin-ubuntu natty ubuntu-patch

In Ubuntu, the attached patch was applied to gain the ability to use
the "gcore" command on binaries with GNU_RELRO sections (like those produced
when using hardening-includes or hardening-wrapper).

For further details, see
https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/680588

Thanks,

-Kees

-- System Information:
Debian Release: squeeze/sid
  APT prefers natty
  APT policy: (500, 'natty')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.37-8-generic (SMP w/4 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -Nru gdb-7.2/debian/changelog gdb-7.2/debian/changelog
diff -Nru gdb-7.2/debian/patches/gdb-7.2-gcore-relro-cleanup.patch gdb-7.2/debian/patches/gdb-7.2-gcore-relro-cleanup.patch
--- gdb-7.2/debian/patches/gdb-7.2-gcore-relro-cleanup.patch	1969-12-31 16:00:00.000000000 -0800
+++ gdb-7.2/debian/patches/gdb-7.2-gcore-relro-cleanup.patch	2010-12-09 19:54:32.000000000 -0800
@@ -0,0 +1,259 @@
+Description: cleanups needed to support "gcore" command when target has
+ GNU_RELRO sections.
+Bug: http://sourceware.org/bugzilla/show_bug.cgi?id=11804
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/680588
+Origin: http://www.cygwin.com/ml/gdb-patches/2010-09/msg00395.html
+Author: Jan Kratochvil <[email protected]>
+
+gdb/
+2010-08-31  Jan Kratochvil  <[email protected]>
+
+	Code cleanup.
+	* defs.h (find_memory_region_ftype): New typedef.
+	(exec_set_find_memory_regions): Use it.
+	* exec.c (exec_set_find_memory_regions): Use find_memory_region_ftype.
+	* fbsd-nat.c (fbsd_find_memory_regions): Likewise.
+	* gcore.c (objfile_find_memory_regions): Likewise.
+	* gnu-nat.c (gnu_find_memory_regions): Likewise.
+	* linux-nat.c (linux_nat_find_memory_regions): Likewise.
+	* procfs.c (iterate_over_mappings_cb_ftype): Remove.
+	(iterate_over_mappings): Rename iterate_over_mappings_cb_ftype to
+	find_memory_region_ftype.
+	(insert_dbx_link_bpt_in_region): Likewise.
+	(iterate_over_mappings): Likewise.  Drop the comment part about the
+	function prototype.
+	(find_memory_regions_callback): Use find_memory_region_ftype.
+	(proc_find_memory_regions): Likewise.
+	(info_mappings_callback): Rename iterate_over_mappings_cb_ftype to
+	find_memory_region_ftype.
+	* target.c (dummy_find_memory_regions): Use find_memory_region_ftype.
+	* target.h (struct target_ops) <to_find_memory_regions>: Likewise.
+
+Index: gdb-7.2/gdb/defs.h
+===================================================================
+--- gdb-7.2.orig/gdb/defs.h	2010-12-09 19:51:45.146834477 -0800
++++ gdb-7.2/gdb/defs.h	2010-12-09 19:53:37.281926514 -0800
+@@ -631,12 +631,13 @@
+ 
+ /* From exec.c */
+ 
++typedef int (*find_memory_region_ftype) (CORE_ADDR addr, unsigned long size,
++					 int read, int write, int exec,
++					 void *data);
++
+ /* Take over the 'find_mapped_memory' vector from exec.c. */
+-extern void exec_set_find_memory_regions (int (*) (int (*) (CORE_ADDR, 
+-							    unsigned long, 
+-							    int, int, int, 
+-							    void *),
+-						   void *));
++extern void exec_set_find_memory_regions
++  (int (*func) (find_memory_region_ftype func, void *data));
+ 
+ /* Possible lvalue types.  Like enum language, this should be in
+    value.h, but needs to be here for the same reason. */
+Index: gdb-7.2/gdb/exec.c
+===================================================================
+--- gdb-7.2.orig/gdb/exec.c	2010-12-09 19:51:45.166838954 -0800
++++ gdb-7.2/gdb/exec.c	2010-12-09 19:53:37.311933228 -0800
+@@ -835,11 +835,7 @@
+ /* Find mapped memory. */
+ 
+ extern void
+-exec_set_find_memory_regions (int (*func) (int (*) (CORE_ADDR, 
+-						    unsigned long, 
+-						    int, int, int, 
+-						    void *),
+-					   void *))
++exec_set_find_memory_regions (int (*func) (find_memory_region_ftype, void *))
+ {
+   exec_ops.to_find_memory_regions = func;
+ }
+Index: gdb-7.2/gdb/fbsd-nat.c
+===================================================================
+--- gdb-7.2.orig/gdb/fbsd-nat.c	2010-12-09 19:51:45.126830000 -0800
++++ gdb-7.2/gdb/fbsd-nat.c	2010-12-09 19:53:37.311933228 -0800
+@@ -92,9 +92,7 @@
+    argument to FUNC.  */
+ 
+ int
+-fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
+-				       int, int, int, void *),
+-			  void *obfd)
++fbsd_find_memory_regions (find_memory_region_ftype func, void *obfd)
+ {
+   pid_t pid = ptid_get_pid (inferior_ptid);
+   char *mapfilename;
+Index: gdb-7.2/gdb/gcore.c
+===================================================================
+--- gdb-7.2.orig/gdb/gcore.c	2010-12-09 19:51:45.196845668 -0800
++++ gdb-7.2/gdb/gcore.c	2010-12-09 19:53:37.311933228 -0800
+@@ -462,9 +462,7 @@
+ }
+ 
+ static int
+-objfile_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
+-					  int, int, int, void *),
+-			     void *obfd)
++objfile_find_memory_regions (find_memory_region_ftype func, void *obfd)
+ {
+   /* Use objfile data to create memory sections.  */
+   struct objfile *objfile;
+Index: gdb-7.2/gdb/gnu-nat.c
+===================================================================
+--- gdb-7.2.orig/gdb/gnu-nat.c	2010-12-09 19:51:45.216850144 -0800
++++ gdb-7.2/gdb/gnu-nat.c	2010-12-09 19:53:37.311933228 -0800
+@@ -2487,11 +2487,7 @@
+ 
+ /* Call FUNC on each memory region in the task.  */
+ static int
+-gnu_find_memory_regions (int (*func) (CORE_ADDR,
+-				      unsigned long,
+-				      int, int, int,
+-				      void *),
+-			 void *data)
++gnu_find_memory_regions (find_memory_region_ftype func, void *data)
+ {
+   error_t err;
+   task_t task;
+Index: gdb-7.2/gdb/linux-nat.c
+===================================================================
+--- gdb-7.2.orig/gdb/linux-nat.c	2010-12-09 19:51:45.206847906 -0800
++++ gdb-7.2/gdb/linux-nat.c	2010-12-09 19:53:37.321935466 -0800
+@@ -4051,9 +4051,7 @@
+    regions in the inferior for a corefile.  */
+ 
+ static int
+-linux_nat_find_memory_regions (int (*func) (CORE_ADDR,
+-					    unsigned long,
+-					    int, int, int, void *), void *obfd)
++linux_nat_find_memory_regions (find_memory_region_ftype func, void *obfd)
+ {
+   int pid = PIDGET (inferior_ptid);
+   char mapsfilename[MAXPATHLEN];
+Index: gdb-7.2/gdb/procfs.c
+===================================================================
+--- gdb-7.2.orig/gdb/procfs.c	2010-12-09 19:51:45.156836716 -0800
++++ gdb-7.2/gdb/procfs.c	2010-12-09 19:53:37.351942180 -0800
+@@ -438,17 +438,9 @@
+ static int find_syscall (procinfo *pi, char *name);
+ #endif /* DYNAMIC_SYSCALLS */
+ 
+-/* A function type used as a callback back iterate_over_mappings.  */
+-typedef int (iterate_over_mappings_cb_ftype)
+-  (CORE_ADDR vaddr, unsigned long size, int read, int write, int execute,
+-   void *data);
+-
+ static int iterate_over_mappings
+-  (procinfo *pi,
+-   iterate_over_mappings_cb_ftype *child_func,
+-   void *data,
+-   int (*func) (struct prmap *map,
+-		iterate_over_mappings_cb_ftype *child_func,
++  (procinfo *pi, find_memory_region_ftype child_func, void *data,
++   int (*func) (struct prmap *map, find_memory_region_ftype child_func,
+ 		void *data));
+ 
+ /* The head of the procinfo list: */
+@@ -3784,7 +3776,7 @@
+ 
+ static int
+ insert_dbx_link_bpt_in_region (struct prmap *map,
+-			       iterate_over_mappings_cb_ftype *child_func,
++			       find_memory_region_ftype child_func,
+ 			       void *data)
+ {
+   procinfo *pi = (procinfo *) data;
+@@ -5226,11 +5218,10 @@
+    from the callback function, or zero.  */
+ 
+ static int
+-iterate_over_mappings (procinfo *pi,
+-		       iterate_over_mappings_cb_ftype *child_func,
++iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func,
+ 		       void *data,
+ 		       int (*func) (struct prmap *map,
+-				    iterate_over_mappings_cb_ftype *child_func,
++				    find_memory_region_ftype child_func,
+ 				    void *data))
+ {
+   char pathname[MAX_PROC_NAME_SIZE];
+@@ -5282,23 +5273,12 @@
+ }
+ 
+ /* Implements the to_find_memory_regions method.  Calls an external
+-   function for each memory region.  The external function will have
+-   the signature:
+-
+-     int callback (CORE_ADDR vaddr,
+-		   unsigned long size,
+-		   int read, int write, int execute,
+-		   void *data);
+-
++   function for each memory region.
+    Returns the integer value returned by the callback.  */
+ 
+ static int
+ find_memory_regions_callback (struct prmap *map,
+-			      int (*func) (CORE_ADDR,
+-					   unsigned long,
+-					   int, int, int,
+-					   void *),
+-			      void *data)
++			      find_memory_region_ftype func, void *data)
+ {
+   return (*func) ((CORE_ADDR) map->pr_vaddr,
+ 		  map->pr_size,
+@@ -5321,11 +5301,7 @@
+    the callback.  */
+ 
+ static int
+-proc_find_memory_regions (int (*func) (CORE_ADDR,
+-				       unsigned long,
+-				       int, int, int,
+-				       void *),
+-			  void *data)
++proc_find_memory_regions (find_memory_region_ftype func, void *data)
+ {
+   procinfo *pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
+ 
+@@ -5364,8 +5340,7 @@
+    mappings'.  */
+ 
+ static int
+-info_mappings_callback (struct prmap *map,
+-			iterate_over_mappings_cb_ftype *ignore,
++info_mappings_callback (struct prmap *map, find_memory_region_ftype ignore,
+ 			void *unused)
+ {
+   unsigned int pr_off;
+Index: gdb-7.2/gdb/target.c
+===================================================================
+--- gdb-7.2.orig/gdb/target.c	2010-12-09 19:51:45.136832238 -0800
++++ gdb-7.2/gdb/target.c	2010-12-09 19:53:37.351942180 -0800
+@@ -2875,7 +2875,7 @@
+ 
+ /* Error-catcher for target_find_memory_regions.  */
+ static int
+-dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
++dummy_find_memory_regions (find_memory_region_ftype ignore1, void *ignore2)
+ {
+   error (_("Command not implemented for this target."));
+   return 0;
+Index: gdb-7.2/gdb/target.h
+===================================================================
+--- gdb-7.2.orig/gdb/target.h	2010-12-09 19:51:45.186843430 -0800
++++ gdb-7.2/gdb/target.h	2010-12-09 19:53:37.361944418 -0800
+@@ -492,11 +492,7 @@
+     int (*to_async_mask) (int);
+     int (*to_supports_non_stop) (void);
+     /* find_memory_regions support method for gcore */
+-    int (*to_find_memory_regions) (int (*) (CORE_ADDR,
+-					    unsigned long,
+-					    int, int, int,
+-					    void *),
+-				   void *);
++    int (*to_find_memory_regions) (find_memory_region_ftype func, void *data);
+     /* make_corefile_notes support method for gcore */
+     char * (*to_make_corefile_notes) (bfd *, int *);
+     /* get_bookmark support method for bookmarks */
diff -Nru gdb-7.2/debian/patches/gdb-7.2-gcore-relro-writer.patch gdb-7.2/debian/patches/gdb-7.2-gcore-relro-writer.patch
--- gdb-7.2/debian/patches/gdb-7.2-gcore-relro-writer.patch	1969-12-31 16:00:00.000000000 -0800
+++ gdb-7.2/debian/patches/gdb-7.2-gcore-relro-writer.patch	2010-12-09 19:54:41.000000000 -0800
@@ -0,0 +1,430 @@
+Description: cleanups needed to support "gcore" command when target has
+ GNU_RELRO sections.
+Bug: http://sourceware.org/bugzilla/show_bug.cgi?id=11804
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/680588
+Origin: http://sourceware.org/ml/gdb-patches/2010-08/msg00554.html
+Author: Jan Kratochvil <[email protected]>
+
+gdb/
+2010-09-22  Jan Kratochvil  <[email protected]>
+
+	Fix gcore writer for -Wl,-z,relro.
+	* defs.h (find_memory_region_ftype): New parameter `modified'.  New
+	comment.
+	* fbsd-nat.c (fbsd_find_memory_regions): Pass -1 to func.
+	* gcore.c (gcore_create_callback): New parameter `modified'.
+	Consider segment as unmodified only if also MODIFIED is 0.  Set
+	SEC_READONLY just according to WRITE.
+	(objfile_find_memory_regions): Pass new values for the `modified'
+	parameter.
+	* gnu-nat.c (gnu_find_memory_regions): Pass -1 for the
+	`modified' parameter.
+	* linux-nat.c (read_mapping): New parameters mapfilename and modified.
+	(linux_nat_find_memory_regions): New variable `modified'.  Try
+	"/proc/%d/smaps" first.  Pass `&modified' and `mapsfilename' to
+	read_mapping.  Call func with MODIFIED.
+	(linux_nat_info_proc_cmd): Pass `fname1' and NULL to read_mapping.
+	* procfs.c (find_memory_regions_callback): Pass -1 for the `modified'
+	parameter.
+
+gdb/testsuite/
+2010-09-22  Jan Kratochvil  <[email protected]>
+
+	Fix gcore writer for -Wl,-z,relro.
+	* gdb.base/gcore-relro.exp: New file.
+	* gdb.base/gcore-relro-main.c: New file.
+	* gdb.base/gcore-relro-lib.c: New file.
+
+Index: gdb-7.2/gdb/defs.h
+===================================================================
+--- gdb-7.2.orig/gdb/defs.h	2010-12-09 19:53:37.281926514 -0800
++++ gdb-7.2/gdb/defs.h	2010-12-09 19:53:51.065010647 -0800
+@@ -631,9 +631,10 @@
+ 
+ /* From exec.c */
+ 
++/* MODIFIED has value -1 for unknown, 0 for not modified, 1 for modified.  */
+ typedef int (*find_memory_region_ftype) (CORE_ADDR addr, unsigned long size,
+ 					 int read, int write, int exec,
+-					 void *data);
++					 int modified, void *data);
+ 
+ /* Take over the 'find_mapped_memory' vector from exec.c. */
+ extern void exec_set_find_memory_regions
+Index: gdb-7.2/gdb/fbsd-nat.c
+===================================================================
+--- gdb-7.2.orig/gdb/fbsd-nat.c	2010-12-09 19:53:37.311933228 -0800
++++ gdb-7.2/gdb/fbsd-nat.c	2010-12-09 19:53:51.075012885 -0800
+@@ -133,7 +133,7 @@
+ 	}
+ 
+       /* Invoke the callback function to create the corefile segment. */
+-      func (start, size, read, write, exec, obfd);
++      func (start, size, read, write, exec, -1, obfd);
+     }
+ 
+   do_cleanups (cleanup);
+Index: gdb-7.2/gdb/gcore.c
+===================================================================
+--- gdb-7.2.orig/gdb/gcore.c	2010-12-09 19:53:37.311933228 -0800
++++ gdb-7.2/gdb/gcore.c	2010-12-09 19:53:51.075012885 -0800
+@@ -378,8 +378,8 @@
+ }
+ 
+ static int
+-gcore_create_callback (CORE_ADDR vaddr, unsigned long size,
+-		       int read, int write, int exec, void *data)
++gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read,
++		       int write, int exec, int modified, void *data)
+ {
+   bfd *obfd = data;
+   asection *osec;
+@@ -388,7 +388,7 @@
+   /* If the memory segment has no permissions set, ignore it, otherwise
+      when we later try to access it for read/write, we'll get an error
+      or jam the kernel.  */
+-  if (read == 0 && write == 0 && exec == 0)
++  if (read == 0 && write == 0 && exec == 0 && modified == 0)
+     {
+       if (info_verbose)
+         {
+@@ -399,7 +399,7 @@
+       return 0;
+     }
+ 
+-  if (write == 0 && !solib_keep_data_in_core (vaddr, size))
++  if (write == 0 && modified == 0 && !solib_keep_data_in_core (vaddr, size))
+     {
+       /* See if this region of memory lies inside a known file on disk.
+ 	 If so, we can avoid copying its contents by clearing SEC_LOAD.  */
+@@ -432,10 +432,12 @@
+ 	    }
+ 	}
+ 
+-    keep:
+-      flags |= SEC_READONLY;
++    keep:;
+     }
+ 
++  if (write == 0)
++    flags |= SEC_READONLY;
++
+   if (exec)
+     flags |= SEC_CODE;
+   else
+@@ -485,6 +487,7 @@
+ 			 1, /* All sections will be readable.  */
+ 			 (flags & SEC_READONLY) == 0, /* Writable.  */
+ 			 (flags & SEC_CODE) != 0, /* Executable.  */
++			 -1, /* Modified is unknown.  */
+ 			 obfd);
+ 	  if (ret != 0)
+ 	    return ret;
+@@ -497,6 +500,7 @@
+ 	     1, /* Stack section will be readable.  */
+ 	     1, /* Stack section will be writable.  */
+ 	     0, /* Stack section will not be executable.  */
++	     1, /* Stack section will be modified.  */
+ 	     obfd);
+ 
+   /* Make a heap segment. */
+@@ -505,6 +509,7 @@
+ 	     1, /* Heap section will be readable.  */
+ 	     1, /* Heap section will be writable.  */
+ 	     0, /* Heap section will not be executable.  */
++	     1, /* Heap section will be modified.  */
+ 	     obfd);
+ 
+   return 0;
+Index: gdb-7.2/gdb/gnu-nat.c
+===================================================================
+--- gdb-7.2.orig/gdb/gnu-nat.c	2010-12-09 19:53:37.311933228 -0800
++++ gdb-7.2/gdb/gnu-nat.c	2010-12-09 19:53:51.075012885 -0800
+@@ -2544,7 +2544,7 @@
+ 		     last_protection & VM_PROT_READ,
+ 		     last_protection & VM_PROT_WRITE,
+ 		     last_protection & VM_PROT_EXECUTE,
+-		     data);
++		     -1, data);
+ 	  last_region_address = region_address;
+ 	  last_region_end = region_address += region_length;
+ 	  last_protection = protection;
+@@ -2557,7 +2557,7 @@
+ 	     last_protection & VM_PROT_READ,
+ 	     last_protection & VM_PROT_WRITE,
+ 	     last_protection & VM_PROT_EXECUTE,
+-	     data);
++	     -1, data);
+ 
+   return 0;
+ }
+Index: gdb-7.2/gdb/linux-nat.c
+===================================================================
+--- gdb-7.2.orig/gdb/linux-nat.c	2010-12-09 19:53:37.321935466 -0800
++++ gdb-7.2/gdb/linux-nat.c	2010-12-09 19:53:51.085015123 -0800
+@@ -4021,12 +4021,9 @@
+ /* Service function for corefiles and info proc.  */
+ 
+ static int
+-read_mapping (FILE *mapfile,
+-	      long long *addr,
+-	      long long *endaddr,
+-	      char *permissions,
+-	      long long *offset,
+-	      char *device, long long *inode, char *filename)
++read_mapping (FILE *mapfile, const char *mapfilename, long long *addr,
++	      long long *endaddr, char *permissions, long long *offset,
++	      char *device, long long *inode, char *filename, int *modified)
+ {
+   int ret = fscanf (mapfile, "%llx-%llx %s %llx %s %llx",
+ 		    addr, endaddr, permissions, offset, device, inode);
+@@ -4044,6 +4041,41 @@
+       ret += fscanf (mapfile, "%[^\n]\n", filename);
+     }
+ 
++  if (modified != NULL)
++    {
++      *modified = -1;
++      for (;;)
++	{
++	  int ch, got;
++	  char keyword[64 + 1];
++	  unsigned long number;
++
++	  ch = fgetc (mapfile);
++	  if (ch != EOF)
++	    ungetc (ch, mapfile);
++	  if (ch < 'A' || ch > 'Z')
++	    break;
++	  got = fscanf (mapfile, "%64s%lu", keyword, &number);
++	  do
++	    ch = fgetc (mapfile);
++	  while (ch != EOF && ch != '\n');
++	  if (got != 2)
++	    {
++	      warning (_("Error parsing file %s"), mapfilename);
++	      break;
++	    }
++	  if (number != 0 && (strcmp (keyword, "Shared_Dirty:") == 0
++			      || strcmp (keyword, "Private_Dirty:") == 0
++			      || strcmp (keyword, "Swap:") == 0))
++	    *modified = 1;
++	  else if (*modified == -1)
++	    {
++	      /* A valid line proves an smaps file is being read in.  */
++	      *modified = 0;
++	    }
++	}
++    }
++
+   return (ret != 0 && ret != EOF);
+ }
+ 
+@@ -4058,13 +4090,17 @@
+   FILE *mapsfile;
+   long long addr, endaddr, size, offset, inode;
+   char permissions[8], device[8], filename[MAXPATHLEN];
+-  int read, write, exec;
++  int read, write, exec, modified;
+   struct cleanup *cleanup;
+ 
+   /* Compose the filename for the /proc memory map, and open it.  */
+-  sprintf (mapsfilename, "/proc/%d/maps", pid);
++  sprintf (mapsfilename, "/proc/%d/smaps", pid);
+   if ((mapsfile = fopen (mapsfilename, "r")) == NULL)
+-    error (_("Could not open %s."), mapsfilename);
++    {
++      sprintf (mapsfilename, "/proc/%d/maps", pid);
++      if ((mapsfile = fopen (mapsfilename, "r")) == NULL)
++	error (_("Could not open %s."), mapsfilename);
++    }
+   cleanup = make_cleanup_fclose (mapsfile);
+ 
+   if (info_verbose)
+@@ -4072,8 +4108,9 @@
+ 		      "Reading memory regions from %s\n", mapsfilename);
+ 
+   /* Now iterate until end-of-file.  */
+-  while (read_mapping (mapsfile, &addr, &endaddr, &permissions[0],
+-		       &offset, &device[0], &inode, &filename[0]))
++  while (read_mapping (mapsfile, mapsfilename, &addr, &endaddr,
++		       &permissions[0], &offset, &device[0], &inode,
++		       &filename[0], &modified))
+     {
+       size = endaddr - addr;
+ 
+@@ -4096,7 +4133,7 @@
+ 
+       /* Invoke the callback function to create the corefile
+ 	 segment.  */
+-      func (addr, size, read, write, exec, obfd);
++      func (addr, size, read, write, exec, modified, obfd);
+     }
+   do_cleanups (cleanup);
+   return 0;
+@@ -4559,8 +4596,9 @@
+ 			   "      Size", "    Offset", "objfile");
+ 	    }
+ 
+-	  while (read_mapping (procfile, &addr, &endaddr, &permissions[0],
+-			       &offset, &device[0], &inode, &filename[0]))
++	  while (read_mapping (procfile, fname1, &addr, &endaddr,
++			       &permissions[0], &offset, &device[0], &inode,
++			       &filename[0], NULL))
+ 	    {
+ 	      size = endaddr - addr;
+ 
+Index: gdb-7.2/gdb/procfs.c
+===================================================================
+--- gdb-7.2.orig/gdb/procfs.c	2010-12-09 19:53:37.351942180 -0800
++++ gdb-7.2/gdb/procfs.c	2010-12-09 19:53:51.115021838 -0800
+@@ -5285,7 +5285,7 @@
+ 		  (map->pr_mflags & MA_READ) != 0,
+ 		  (map->pr_mflags & MA_WRITE) != 0,
+ 		  (map->pr_mflags & MA_EXEC) != 0,
+-		  data);
++		  -1, data);
+ }
+ 
+ /* External interface.  Calls a callback function once for each
+Index: gdb-7.2/gdb/testsuite/gdb.base/gcore-relro-lib.c
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ gdb-7.2/gdb/testsuite/gdb.base/gcore-relro-lib.c	2010-12-09 19:53:51.125024077 -0800
+@@ -0,0 +1,21 @@
++/* Copyright 2010 Free Software Foundation, Inc.
++
++   This file is part of GDB.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
++
++void
++lib (void)
++{
++}
+Index: gdb-7.2/gdb/testsuite/gdb.base/gcore-relro-main.c
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ gdb-7.2/gdb/testsuite/gdb.base/gcore-relro-main.c	2010-12-09 19:53:51.125024077 -0800
+@@ -0,0 +1,25 @@
++/* Copyright 2010 Free Software Foundation, Inc.
++
++   This file is part of GDB.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
++
++extern void lib (void);
++
++int
++main (void)
++{
++  lib ();
++  return 0;
++}
+Index: gdb-7.2/gdb/testsuite/gdb.base/gcore-relro.exp
+===================================================================
+--- /dev/null	1970-01-01 00:00:00.000000000 +0000
++++ gdb-7.2/gdb/testsuite/gdb.base/gcore-relro.exp	2010-12-09 19:53:51.125024077 -0800
+@@ -0,0 +1,80 @@
++# Copyright 2010 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++if {[skip_shlib_tests]} {
++    return 0
++}
++
++set testfile "gcore-relro"
++set srcmainfile ${testfile}-main.c
++set srclibfile ${testfile}-lib.c
++set libfile ${objdir}/${subdir}/${testfile}-lib.so
++set objfile ${objdir}/${subdir}/${testfile}-main.o
++set executable ${testfile}-main
++set binfile ${objdir}/${subdir}/${executable}
++set gcorefile ${objdir}/${subdir}/${executable}.gcore
++
++if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} {debug}] != ""
++     || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
++     untested ${testfile}.exp
++     return -1
++}
++set opts [list debug shlib=${libfile} additional_flags=-Wl,-z,relro]
++if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
++     unsupported "-Wl,-z,relro compilation failed"
++     return -1
++}
++
++clean_restart $executable
++gdb_load_shlibs $libfile
++
++# Does this gdb support gcore?
++set test "help gcore"
++gdb_test_multiple $test $test {
++    -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
++	# gcore command not supported -- nothing to test here.
++	unsupported "gdb does not support gcore on this target"
++	return -1;
++    }
++    -re "Save a core file .*\r\n$gdb_prompt $" {
++	pass $test
++    }
++}
++
++if { ![runto lib] } then {
++    return -1
++}
++
++set escapedfilename [string_to_regexp ${gcorefile}]
++
++set test "save a corefile"
++gdb_test_multiple "gcore ${gcorefile}" $test {
++    -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
++	pass $test
++    }
++    -re "Can't create a corefile\r\n$gdb_prompt $" {
++	unsupported $test
++	return -1
++    }
++}
++
++# Now restart gdb and load the corefile.
++
++clean_restart $executable
++gdb_load_shlibs $libfile
++
++gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
++
++gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
diff -Nru gdb-7.2/debian/patches/series gdb-7.2/debian/patches/series
--- gdb-7.2/debian/patches/series	2010-10-28 06:23:47.000000000 -0700
+++ gdb-7.2/debian/patches/series	2010-12-09 19:55:16.000000000 -0800
@@ -5,0 +5,3 @@
+gdb-7.2-gcore-relro-cleanup.patch
+gdb-7.2-gcore-relro-writer.patch

Reply via email to