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]

[RFA] rs6000-tdep.c: Improve prologue handling with code motion.


Under AIX, shared system libraries are compiled with a high optimization
level, causing code motion of non-prologue instructions into the prologue.

As we have no source level debug information for shared system libraries,
backtraces through shared system library functions do not work.

Here is an example from the testsuite:

pes@limo_2003$ gdbnd interrupt
GNU gdb 20001025
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-ibm-aix4.3.3.0"...
(gdb) r
Starting program: interrupt
talk to me baby
^C
Program received signal SIGINT, Interrupt.
0xd016fdf0 in read ()
(gdb) bt
#0  0xd016fdf0 in read ()
#1  0xffffffff in ?? () from (unknown load module)


With the patch below I get the following result:

Program received signal SIGINT, Interrupt.
0xd016fdf0 in read ()
(gdb) bt
#0  0xd016fdf0 in read ()
#1  0x10000380 in main ()
    at /users/pes/gdbnd/devo/gdb/testsuite/gdb.base/interrupt.c:17
#2  0x100001dc in __start ()


There are no testsuite regressions with the patch.

	* rs6000-tdep.c (skip_prologue):  Handle optimizer code motions into
	the prologue by continuing the prologue search, if we have no valid
	frame yet or if the return address is not yet saved in the frame.

*** ./rs6000-tdep.c.orig	Wed Oct 25 21:25:44 2000
--- ./rs6000-tdep.c	Sun Nov  5 14:00:44 2000
***************
*** 381,391 ****
  
  #define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
  
  static CORE_ADDR
  skip_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, struct rs6000_framedata *fdata)
  {
    CORE_ADDR orig_pc = pc;
!   CORE_ADDR last_prologue_pc;
    char buf[4];
    unsigned long op;
    long offset = 0;
--- 380,394 ----
  
  #define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
  
+ /* Limit the number of skipped non-prologue instructions, as the examining
+    of the prologue is expensive.  */
+ static int max_skip_non_prologue_insns = 10;
+ 
  static CORE_ADDR
  skip_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, struct rs6000_framedata *fdata)
  {
    CORE_ADDR orig_pc = pc;
!   CORE_ADDR last_prologue_pc = pc;
    char buf[4];
    unsigned long op;
    long offset = 0;
***************
*** 395,400 ****
--- 398,404 ----
    int framep = 0;
    int minimal_toc_loaded = 0;
    int prev_insn_was_prologue_insn = 1;
+   int num_skip_non_prologue_insns = 0;
  
    memset (fdata, 0, sizeof (struct rs6000_framedata));
    fdata->saved_gpr = -1;
***************
*** 629,635 ****
  	}
        else
  	{
! 	  break;
  	}
      }
  
--- 633,675 ----
  	}
        else
  	{
! 	  /* Not a recognized prologue instruction.
! 	     Handle optimizer code motions into the prologue by continuing
! 	     the search if we have no valid frame yet or if the return
! 	     address is not yet saved in the frame.  */
! 	  if (fdata->frameless == 0
! 	      && (lr_reg == -1 || fdata->nosavedpc == 0))
! 	    break;
! 
! 	  if (op == 0x4e800020		/* blr */
! 	      || op == 0x4e800420)	/* bctr */
! 	    /* Do not scan past epilogue in frameless functions or
! 	       trampolines.  */
! 	    break;
! 	  if ((op & 0xf4000000) == 0x40000000) /* bxx */
! 	    /* Never skip branches. */
! 	    break;
! 
! 	  if (num_skip_non_prologue_insns == 0 && lim_pc == 0)
! 	    {
! 	      /* Stop scan if we are looking for the end of the prologue
! 		 and we have line numbers for the function
! 		 The current result is good enough, and the compiler will
! 		 hopefully help us to get better results via the line number
! 		 info.  */
! 	      struct symtab_and_line sal;
! 	      sal = find_pc_line (pc, 0);
! 	      if (sal.line != 0)
! 		break;
! 	    }
! 	  if (num_skip_non_prologue_insns++ > max_skip_non_prologue_insns)
! 	    /* Do not scan too many insns, scanning insns is expensive with
! 	       remote targets.  */
! 	    break;
! 
! 	  /* Continue scanning.  */
! 	  prev_insn_was_prologue_insn = 0;
! 	  continue;
  	}
      }
  

-- 
Peter Schauer			pes@regent.e-technik.tu-muenchen.de

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