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]

Fix passing of arguments on x86-64


call-ar-st was failing to "print print_small_structs" since the stack
was not properly aligned and therefore the called function died in
glibc with a segv.  The problem is that entries have to be aligned by
8 byte but the bottom of the stack by 16 byte.  I fixed also another
failure where my last patch set %rax to all floating points args where
it should have been only the floating points args passed in SSE
registers.

The appended patch fixes all failures in call-ar-st and brings down
the testsuite failures:

                === gdb Summary ===

# of expected passes            8984
# of unexpected failures        72
# of unexpected successes       4
# of expected failures          46
# of known failures             23
# of unresolved testcases       3
# of untested testcases         6
# of unsupported tests          1

The remaining failures are:
FAIL: gdb.base/callfuncs.exp: backtrace at nested call level 2
FAIL: gdb.base/callfuncs.exp: backtrace at nested call level 3
FAIL: gdb.base/callfuncs.exp: backtrace at nested call level 4
FAIL: gdb.base/callfuncs.exp: backtrace after finish from nested call level 4
FAIL: gdb.base/callfuncs.exp: Finish from nested call level 3
FAIL: gdb.base/callfuncs.exp: backtrace after finish from nested call level 3
FAIL: gdb.base/callfuncs.exp: Finish from nested call level 2
FAIL: gdb.base/callfuncs.exp: backtrace after finish from nested call level 2
FAIL: gdb.base/callfuncs.exp: Finish from nested call level 1
FAIL: gdb.base/restore.exp: caller1 called callee1; variable l1 restored to 32492
FAIL: gdb.base/restore.exp: caller2 called callee1; variable l2 restored to 32493
FAIL: gdb.base/restore.exp: caller3 called callee1; variable l3 restored to 32494
FAIL: gdb.base/restore.exp: caller4 called callee1; variable l4 restored to 32495
FAIL: gdb.base/restore.exp: caller5 called callee1; variable l5 restored to 32496
FAIL: gdb.base/selftest.exp: step into xmalloc call
FAIL: gdb.base/shlib-call.exp: step into mainshr1
FAIL: gdb.base/signals.exp: continue to func1 (probably kernel bug)
FAIL: gdb.base/signals.exp: continue to handler (the program exited)
FAIL: gdb.base/store.exp: up print old r - char
FAIL: gdb.base/store.exp: up print old r - short
FAIL: gdb.base/store.exp: up print old r - int
FAIL: gdb.base/store.exp: up print old r - long
FAIL: gdb.base/store.exp: up print old r - longest
FAIL: gdb.base/store.exp: up print old r - float
FAIL: gdb.base/store.exp: up print old r - double
FAIL: gdb.base/store.exp: up print old r - doublest
FAIL: gdb.base/structs2.exp: structs2 continue1 (PRMS 13536)
FAIL: gdb.base/structs2.exp: structs2 continue2 (PRMS 13536)
FAIL: gdb.c++/templates.exp: ptype T5<int>
FAIL: gdb.c++/templates.exp: ptype t5i
FAIL: gdb.c++/templates.exp: constructor breakpoint (timeout)
FAIL: gdb.c++/templates.exp: (timeout) print fint
FAIL: gdb.c++/templates.exp: (timeout) print fvpchar
FAIL: gdb.c++/templates.exp: (timeout) ptype Foo
FAIL: gdb.c++/templates.exp: (timeout) ptype fint
FAIL: gdb.c++/templates.exp: (timeout) ptype fchar
FAIL: gdb.c++/templates.exp: (timeout) ptype fvpchar
FAIL: gdb.c++/templates.exp: (timeout) print Foo<volatile char *>::foo
FAIL: gdb.c++/templates.exp: (timeout) print Foo<volatile char*>::foo
FAIL: gdb.c++/templates.exp: (timeout) ptype Bar
FAIL: gdb.c++/templates.exp: (timeout) ptype bint
FAIL: gdb.c++/templates.exp: (timeout) ptype bint2
FAIL: gdb.c++/templates.exp: (timeout) ptype Baz
FAIL: gdb.c++/templates.exp: (timeout) ptype bazint
FAIL: gdb.c++/templates.exp: (timeout) ptype bazint2
FAIL: gdb.c++/templates.exp: (timeout) ptype Qux
FAIL: gdb.c++/templates.exp: (timeout) ptype quxint
FAIL: gdb.c++/templates.exp: (timeout) ptype Spec
FAIL: gdb.c++/templates.exp: (timeout) ptype siip
FAIL: gdb.c++/templates.exp: (timeout) ptype Garply<int>
FAIL: gdb.c++/templates.exp: (timeout) ptype Garply<Garply<char> >
FAIL: gdb.c++/templates.exp: print Garply<Garply<char> >::garply (timeout)
FAIL: gdb.c++/templates.exp: break Garply<Garply<char> >::garply (timeout)
FAIL: gdb.java/jmisc.exp: setting breakpoint at jmisc.main
FAIL: gdb.java/jmisc.exp: ptype jmisc
FAIL: gdb.java/jmisc.exp: p args
FAIL: gdb.java/jmisc.exp: p *args
FAIL: gdb.java/jmisc1.exp: ptype jmisc
FAIL: gdb.java/jmisc2.exp: ptype jmisc
FAIL: gdb.mi/mi-var-display.exp: get children local variable weird
FAIL: gdb.mi/mi1-var-display.exp: get children local variable weird
FAIL: gdb.objc/basicclass.exp: Call an Objective-C method with no arguments
FAIL: gdb.objc/basicclass.exp: Call an Objective-C method with one argument
FAIL: gdb.objc/basicclass.exp: Use of the print-object command
FAIL: gdb.objc/basicclass.exp: Use of the po (print-object) command
FAIL: gdb.threads/linux-dp.exp: philosopher is distinct: 1
FAIL: gdb.threads/linux-dp.exp: philosopher is distinct: 3
FAIL: gdb.threads/linux-dp.exp: philosopher is distinct: 4
FAIL: gdb.threads/linux-dp.exp: philosopher is distinct: 7
FAIL: gdb.threads/print-threads.exp: Running threads (slow with kill breakpoint) (unknown output)
FAIL: gdb.threads/pthreads.exp: check backtrace from main thread
FAIL: gdb.threads/pthreads.exp: apply backtrace command to all three threads

So, this looks like push_arguments is working now correctly.  Thanks
Elena et. al for writing such good testcases!

Ok to commit for 6.0 and mainline?

Andreas

2003-06-27  Andreas Jaeger  <aj@suse.de>

	* x86-64-tdep.c (x86_64_push_arguments): Align stack to 16-byte
	before the call.
	Set %rax only to number of SSE registers used.

============================================================
Index: gdb/x86-64-tdep.c
--- gdb/x86-64-tdep.c	26 Jun 2003 17:08:10 -0000	1.80
+++ gdb/x86-64-tdep.c	27 Jun 2003 05:34:12 -0000
@@ -597,13 +597,14 @@ x86_64_push_arguments (struct regcache *
 {
   int intreg = 0;
   int ssereg = 0;
-  /* For varargs functions we have to pass the total number of SSE arguments
-     in %rax.  So, let's count this number.  */
+  /* For varargs functions we have to pass the total number of SSE
+     registers used in %rax.  So, let's count this number.  */
   int total_sse_args = 0;
   /* Once an SSE/int argument is passed on the stack, all subsequent
      arguments are passed there.  */
   int sse_stack = 0;
   int int_stack = 0;
+  unsigned total_sp;
   int i;
   char buf[8];
   static int int_parameter_registers[INT_REGS] =
@@ -644,7 +645,8 @@ x86_64_push_arguments (struct regcache *
 	    int_stack = 1;
 	  if (ssereg / 2 + needed_sseregs > SSE_REGS)
 	    sse_stack = 1;
-	  total_sse_args += needed_sseregs;
+	  if (!sse_stack)
+	    total_sse_args += needed_sseregs;
 
 	  for (j = 0; j < n; j++)
 	    {
@@ -720,13 +722,29 @@ x86_64_push_arguments (struct regcache *
 	}
     }
 
+  /* We have to make sure that the stack is 16-byte aligned after the
+     setup.  Let's calculate size of arguments first, align stack and
+     then fill in the arguments.  */
+  total_sp = 0;
+  for (i = 0; i < stack_values_count; i++)
+    {
+      struct value *arg = args[stack_values[i]];
+      int len = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg));
+      total_sp += (len + 7) & ~7;
+    }
+  /* total_sp is now a multiple of 8, if it is not a multiple of 16,
+     change the stack pointer so that it will be afterwards correctly
+     aligned.  */
+  if (total_sp & 15)
+    sp -= 8;
+    
   /* Push any remaining arguments onto the stack.  */
   while (--stack_values_count >= 0)
     {
       struct value *arg = args[stack_values[stack_values_count]];
       int len = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg));
 
-      /* Make sure the stack stays eightbyte-aligned.  */
+      /* Make sure the stack is 8-byte-aligned.  */
       sp -= (len + 7) & ~7;
       write_memory (sp, VALUE_CONTENTS_ALL (arg), len);
     }

-- 
 Andreas Jaeger, SuSE Linux AG, aj@suse.de, http://www.suse.de/~aj
  GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

Attachment: pgp00000.pgp
Description: PGP signature


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