Blame SOURCES/gdb-rhbz1225569-oom-killer-aarch64-frame-same-id-7of8.patch

2c2fa1
commit 1b5d0ab34c53d6e896d2c0958b1176e324bb7878
2c2fa1
Author: Pedro Alves <palves@redhat.com>
2c2fa1
Date:   Wed Jul 16 19:25:41 2014 +0100
2c2fa1
2c2fa1
    gdb.trace/tfile.c: Remove Thumb bit in one more more, general cleanup
2c2fa1
    
2c2fa1
    I noticed that the existing code casts a function's address to 'long',
2c2fa1
    but that doesn't work correctly on some ABIs, like Win64, where long
2c2fa1
    is 32-bit and while pointers are 64-bit:
2c2fa1
    
2c2fa1
      func_addr = (long) &write_basic_trace_file;
2c2fa1
    
2c2fa1
    Fixing that showed there's actually another place in the file that
2c2fa1
    writes a function address to file, and therefore should clear the
2c2fa1
    Thumb bit.  This commit adds a macro+function pair to centralize the
2c2fa1
    Thumb bit handling, and uses it in both places.
2c2fa1
    
2c2fa1
    The rest is just enough changes to make the file build without
2c2fa1
    warnings with "-Wall -Wextra" with x86_64-w64-mingw32-gcc and
2c2fa1
    i686-w64-mingw32-gcc cross compilers, and with -m32/-m64 on x86_64
2c2fa1
    GNU/Linux.  Currently with x86_64-w64-mingw32-gcc we get:
2c2fa1
    
2c2fa1
      $ x86_64-w64-mingw32-gcc tfile.c  -Wall -DTFILE_DIR=\"\"
2c2fa1
      tfile.c: In function 'start_trace_file':
2c2fa1
      tfile.c:51:23: error: 'S_IRGRP' undeclared (first use in this function)
2c2fa1
    	 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
2c2fa1
    			 ^
2c2fa1
      tfile.c:51:23: note: each undeclared identifier is reported only once for each function it appears in
2c2fa1
      tfile.c:51:31: error: 'S_IROTH' undeclared (first use in this function)
2c2fa1
    	 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
2c2fa1
    				 ^
2c2fa1
      tfile.c: In function 'add_memory_block':
2c2fa1
      tfile.c:79:10: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
2c2fa1
         ll_x = (unsigned long) addr;
2c2fa1
    	    ^
2c2fa1
      tfile.c: In function 'write_basic_trace_file':
2c2fa1
      tfile.c:113:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
2c2fa1
         func_addr = (long) &write_basic_trace_file;
2c2fa1
    		 ^
2c2fa1
      tfile.c:137:3: warning: passing argument 1 of 'add_memory_block' from incompatible pointer type [enabled by default]
2c2fa1
         add_memory_block (&testglob, sizeof (testglob));
2c2fa1
         ^
2c2fa1
      tfile.c:72:1: note: expected 'char *' but argument is of type 'int *'
2c2fa1
       add_memory_block (char *addr, int size)
2c2fa1
       ^
2c2fa1
      tfile.c:139:3: warning: passing argument 1 of 'add_memory_block' from incompatible pointer type [enabled by default]
2c2fa1
         add_memory_block (&testglob2, 1);
2c2fa1
         ^
2c2fa1
      tfile.c:72:1: note: expected 'char *' but argument is of type 'int *'
2c2fa1
       add_memory_block (char *addr, int size)
2c2fa1
       ^
2c2fa1
      tfile.c: In function 'write_error_trace_file':
2c2fa1
      tfile.c:185:3: warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
2c2fa1
         char *hex = alloca (len * 2 + 1);
2c2fa1
         ^
2c2fa1
      tfile.c:185:15: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by default]
2c2fa1
         char *hex = alloca (len * 2 + 1);
2c2fa1
    		 ^
2c2fa1
      tfile.c:211:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
2c2fa1
    	(long) &write_basic_trace_file);
2c2fa1
          ^
2c2fa1
    
2c2fa1
    Tested on x86_64 Fedora 20, -m64 and -m32.
2c2fa1
    Tested by Yao on arm targets.
2c2fa1
    
2c2fa1
    gdb/testsuite/
2c2fa1
    2014-07-16  Pedro Alves  <palves@redhat.com>
2c2fa1
    
2c2fa1
    	* gdb.trace/tfile.c: Include unistd.h and stdint.h.
2c2fa1
    	(start_trace_file): Guard S_IRGRP and S_IROTH uses behind #ifdef.
2c2fa1
    	(tfile_write_64, tfile_write_16, tfile_write_8, tfile_write_addr)
2c2fa1
    	(tfile_write_buf): New functions.
2c2fa1
    	(add_memory_block): Rewrite using the above.
2c2fa1
    	(adjust_function_address): New function.
2c2fa1
    	(FUNCTION_ADDRESS): New macro.
2c2fa1
    	(write_basic_trace_file): Remove short_x local, and use
2c2fa1
    	tfile_write_16. Change type of func_addr local to unsigned long
2c2fa1
    	long.  Use FUNCTION_ADDRESS instead of handling the Thumb bit
2c2fa1
    	here.  Cast argument of add_memory_block to char pointer.
2c2fa1
    	(write_error_trace_file): Avoid alloca.  Use FUNCTION_ADDRESS.
2c2fa1
    	(main): Remove parameters.
2c2fa1
    	* gdb.trace/tfile.exp: Remove nowarnings.
2c2fa1
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/testsuite/gdb.trace/tfile.c
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.c
2c2fa1
@@ -3,9 +3,11 @@
2c2fa1
    GDB.  */
2c2fa1
 
2c2fa1
 #include <stdio.h>
2c2fa1
+#include <unistd.h>
2c2fa1
 #include <string.h>
2c2fa1
 #include <fcntl.h>
2c2fa1
 #include <sys/stat.h>
2c2fa1
+#include <stdint.h>
2c2fa1
 
2c2fa1
 char spbuf[200];
2c2fa1
 
2c2fa1
@@ -23,9 +25,17 @@ int
2c2fa1
 start_trace_file (char *filename)
2c2fa1
 {
2c2fa1
   int fd;
2c2fa1
+  mode_t mode = S_IRUSR | S_IWUSR;
2c2fa1
 
2c2fa1
-  fd = open (filename, O_WRONLY|O_CREAT|O_APPEND,
2c2fa1
-	     S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
2c2fa1
+#ifdef S_IRGRP
2c2fa1
+  mode |= S_IRGRP;
2c2fa1
+#endif
2c2fa1
+
2c2fa1
+#ifdef S_IROTH
2c2fa1
+  mode |= S_IROTH;
2c2fa1
+#endif
2c2fa1
+
2c2fa1
+  fd = open (filename, O_WRONLY|O_CREAT|O_APPEND, mode);
2c2fa1
 
2c2fa1
   if (fd < 0)
2c2fa1
     return fd;
2c2fa1
@@ -44,31 +54,73 @@ finish_trace_file (int fd)
2c2fa1
   close (fd);
2c2fa1
 }
2c2fa1
 
2c2fa1
+static void
2c2fa1
+tfile_write_64 (uint64_t value)
2c2fa1
+{
2c2fa1
+  memcpy (trptr, &value, sizeof (uint64_t));
2c2fa1
+  trptr += sizeof (uint64_t);
2c2fa1
+}
2c2fa1
 
2c2fa1
-void
2c2fa1
-add_memory_block (char *addr, int size)
2c2fa1
+static void
2c2fa1
+tfile_write_16 (uint16_t value)
2c2fa1
+{
2c2fa1
+  memcpy (trptr, &value, sizeof (uint16_t));
2c2fa1
+  trptr += sizeof (uint16_t);
2c2fa1
+}
2c2fa1
+
2c2fa1
+static void
2c2fa1
+tfile_write_8 (uint8_t value)
2c2fa1
 {
2c2fa1
-  short short_x;
2c2fa1
-  unsigned long long ll_x;
2c2fa1
+  memcpy (trptr, &value, sizeof (uint8_t));
2c2fa1
+  trptr += sizeof (uint8_t);
2c2fa1
+}
2c2fa1
 
2c2fa1
-  *((char *) trptr) = 'M';
2c2fa1
-  trptr += 1;
2c2fa1
-  ll_x = (unsigned long) addr;
2c2fa1
-  memcpy (trptr, &ll_x, sizeof (unsigned long long));
2c2fa1
-  trptr += sizeof (unsigned long long);
2c2fa1
-  short_x = size;
2c2fa1
-  memcpy (trptr, &short_x, 2);
2c2fa1
-  trptr += 2;
2c2fa1
+static void
2c2fa1
+tfile_write_addr (char *addr)
2c2fa1
+{
2c2fa1
+  tfile_write_64 ((uint64_t) (uintptr_t) addr);
2c2fa1
+}
2c2fa1
+
2c2fa1
+static void
2c2fa1
+tfile_write_buf (const void *addr, size_t size)
2c2fa1
+{
2c2fa1
   memcpy (trptr, addr, size);
2c2fa1
   trptr += size;
2c2fa1
 }
2c2fa1
 
2c2fa1
 void
2c2fa1
+add_memory_block (char *addr, int size)
2c2fa1
+{
2c2fa1
+  tfile_write_8 ('M');
2c2fa1
+  tfile_write_addr (addr);
2c2fa1
+  tfile_write_16 (size);
2c2fa1
+  tfile_write_buf (addr, size);
2c2fa1
+}
2c2fa1
+
2c2fa1
+/* Adjust a function's address to account for architectural
2c2fa1
+   particularities.  */
2c2fa1
+
2c2fa1
+static uintptr_t
2c2fa1
+adjust_function_address (uintptr_t func_addr)
2c2fa1
+{
2c2fa1
+#if defined(__thumb__) || defined(__thumb2__)
2c2fa1
+  /* Although Thumb functions are two-byte aligned, function
2c2fa1
+     pointers have the Thumb bit set.  Clear it.  */
2c2fa1
+  return func_addr & ~1;
2c2fa1
+#else
2c2fa1
+  return func_addr;
2c2fa1
+#endif
2c2fa1
+}
2c2fa1
+
2c2fa1
+/* Get a function's address as an integer.  */
2c2fa1
+
2c2fa1
+#define FUNCTION_ADDRESS(FUN) adjust_function_address ((uintptr_t) &FUN)
2c2fa1
+
2c2fa1
+void
2c2fa1
 write_basic_trace_file (void)
2c2fa1
 {
2c2fa1
   int fd, int_x;
2c2fa1
-  short short_x;
2c2fa1
-  long func_addr;
2c2fa1
+  unsigned long long func_addr;
2c2fa1
 
2c2fa1
   fd = start_trace_file ("basic.tf");
2c2fa1
 
2c2fa1
@@ -86,15 +138,9 @@ write_basic_trace_file (void)
2c2fa1
 
2c2fa1
   /* Dump tracepoint definitions, in syntax similar to that used
2c2fa1
      for reconnection uploads.  */
2c2fa1
-  /* FIXME need a portable way to print function address in hex */
2c2fa1
-  func_addr = (long) &write_basic_trace_file;
2c2fa1
-#if defined(__thumb__) || defined(__thumb2__)
2c2fa1
-  /* Although Thumb functions are two-byte aligned, function
2c2fa1
-     pointers have the Thumb bit set.  Clear it.  */
2c2fa1
-  func_addr &= ~1;
2c2fa1
-#endif
2c2fa1
+  func_addr = FUNCTION_ADDRESS (write_basic_trace_file);
2c2fa1
 
2c2fa1
-  snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n", func_addr);
2c2fa1
+  snprintf (spbuf, sizeof spbuf, "tp T1:%llx:E:0:0\n", func_addr);
2c2fa1
   write (fd, spbuf, strlen (spbuf));
2c2fa1
   /* (Note that we would only need actions defined if we wanted to
2c2fa1
      test tdump.) */
2c2fa1
@@ -106,14 +152,13 @@ write_basic_trace_file (void)
2c2fa1
   /* (Encapsulate better if we're going to do lots of this; note that
2c2fa1
      buffer endianness is the target program's enddianness.) */
2c2fa1
   trptr = trbuf;
2c2fa1
-  short_x = 1;
2c2fa1
-  memcpy (trptr, &short_x, 2);
2c2fa1
-  trptr += 2;
2c2fa1
+  tfile_write_16 (1);
2c2fa1
+
2c2fa1
   tfsizeptr = trptr;
2c2fa1
   trptr += 4;
2c2fa1
-  add_memory_block (&testglob, sizeof (testglob));
2c2fa1
+  add_memory_block ((char *) &testglob, sizeof (testglob));
2c2fa1
   /* Divide a variable between two separate memory blocks.  */
2c2fa1
-  add_memory_block (&testglob2, 1);
2c2fa1
+  add_memory_block ((char *) &testglob2, 1);
2c2fa1
   add_memory_block (((char*) &testglob2) + 1, sizeof (testglob2) - 1);
2c2fa1
   /* Go back and patch in the frame size.  */
2c2fa1
   int_x = trptr - tfsizeptr - sizeof (int);
2c2fa1
@@ -158,8 +203,8 @@ write_error_trace_file (void)
2c2fa1
 {
2c2fa1
   int fd;
2c2fa1
   const char made_up[] = "made-up error";
2c2fa1
+  char hex[(sizeof (made_up) - 1) * 2 + 1];
2c2fa1
   int len = sizeof (made_up) - 1;
2c2fa1
-  char *hex = alloca (len * 2 + 1);
2c2fa1
 
2c2fa1
   fd = start_trace_file ("error.tf");
2c2fa1
 
2c2fa1
@@ -183,9 +228,8 @@ write_error_trace_file (void)
2c2fa1
 
2c2fa1
   /* Dump tracepoint definitions, in syntax similar to that used
2c2fa1
      for reconnection uploads.  */
2c2fa1
-  /* FIXME need a portable way to print function address in hex */
2c2fa1
-  snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n",
2c2fa1
-	    (long) &write_basic_trace_file);
2c2fa1
+  snprintf (spbuf, sizeof spbuf, "tp T1:%llx:E:0:0\n",
2c2fa1
+	    (unsigned long long) FUNCTION_ADDRESS (write_basic_trace_file));
2c2fa1
   write (fd, spbuf, strlen (spbuf));
2c2fa1
   /* (Note that we would only need actions defined if we wanted to
2c2fa1
      test tdump.) */
2c2fa1
@@ -210,7 +254,7 @@ done_making_trace_files (void)
2c2fa1
 }
2c2fa1
 
2c2fa1
 int
2c2fa1
-main (int argc, char **argv, char **envp)
2c2fa1
+main (void)
2c2fa1
 {
2c2fa1
   write_basic_trace_file ();
2c2fa1
 
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.exp
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/testsuite/gdb.trace/tfile.exp
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.trace/tfile.exp
2c2fa1
@@ -26,7 +26,7 @@ gdb_exit
2c2fa1
 gdb_start
2c2fa1
 standard_testfile
2c2fa1
 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
2c2fa1
-	  executable {debug nowarnings}] != "" } {
2c2fa1
+	  executable {debug}] != "" } {
2c2fa1
     untested ${testfile}.exp
2c2fa1
     return -1
2c2fa1
 }