This is the mail archive of the gdb-patches@sourceware.org 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]

Re: RFC: fix stack height checks for agent expressions


On 11/18/05, Jim Blandy <jimb@red-bean.com> wrote:
> I'll commit in a bit if nobody has further thoughts.
>
> gdb/ChangeLog:
> 2005-11-18  Jim Blandy  <jimb@redhat.com>
>
>         * ax-general.c (ax_reqs): If the jump target is marked as an
>         instruction boundary, we have a stack height we can check there,
>         too.

I've committed the attached, which is slightly different:

gdb/ChangeLog:
2005-12-07  Jim Blandy  <jimb@redhat.com>

	* ax-general.c (ax_reqs): Check stack heights for backward jumps,
	too.  Correctly check height at target.  Doc fixes.
gdb/ChangeLog:
2005-12-07  Jim Blandy  <jimb@redhat.com>

	* ax-general.c (ax_reqs): Check stack heights for backward jumps,
	too.  Correctly check height at target.  Doc fixes.

Index: gdb/ax-general.c
===================================================================
RCS file: /cvs/src/src/gdb/ax-general.c,v
retrieving revision 1.8
diff -c -p -r1.8 ax-general.c
*** gdb/ax-general.c	29 Jan 2005 17:53:25 -0000	1.8
--- gdb/ax-general.c	7 Dec 2005 19:28:51 -0000
*************** ax_reqs (struct agent_expr *ax, struct a
*** 388,402 ****
    int reg_mask_len = 1;
    unsigned char *reg_mask = xmalloc (reg_mask_len * sizeof (reg_mask[0]));
  
!   /* Jump target table.  targets[i] is non-zero iff there is a jump to
!      offset i.  */
    char *targets = (char *) alloca (ax->len * sizeof (targets[0]));
  
!   /* Instruction boundary table.  boundary[i] is non-zero iff an
!      instruction starts at offset i.  */
    char *boundary = (char *) alloca (ax->len * sizeof (boundary[0]));
  
!   /* Stack height record.  iff either targets[i] or boundary[i] is
       non-zero, heights[i] is the height the stack should have before
       executing the bytecode at that point.  */
    int *heights = (int *) alloca (ax->len * sizeof (heights[0]));
--- 388,402 ----
    int reg_mask_len = 1;
    unsigned char *reg_mask = xmalloc (reg_mask_len * sizeof (reg_mask[0]));
  
!   /* Jump target table.  targets[i] is non-zero iff we have found a
!      jump to offset i.  */
    char *targets = (char *) alloca (ax->len * sizeof (targets[0]));
  
!   /* Instruction boundary table.  boundary[i] is non-zero iff our scan
!      has reached an instruction starting at offset i.  */
    char *boundary = (char *) alloca (ax->len * sizeof (boundary[0]));
  
!   /* Stack height record.  If either targets[i] or boundary[i] is
       non-zero, heights[i] is the height the stack should have before
       executing the bytecode at that point.  */
    int *heights = (int *) alloca (ax->len * sizeof (heights[0]));
*************** ax_reqs (struct agent_expr *ax, struct a
*** 437,444 ****
  	  return;
  	}
  
!       /* If this instruction is a jump target, does the current stack
!          height match the stack height at the jump source?  */
        if (targets[i] && (heights[i] != height))
  	{
  	  reqs->flaw = agent_flaw_height_mismatch;
--- 437,445 ----
  	  return;
  	}
  
!       /* If this instruction is a forward jump target, does the
!          current stack height match the stack height at the jump
!          source?  */
        if (targets[i] && (heights[i] != height))
  	{
  	  reqs->flaw = agent_flaw_height_mismatch;
*************** ax_reqs (struct agent_expr *ax, struct a
*** 472,492 ****
  	      xfree (reg_mask);
  	      return;
  	    }
! 	  /* Have we already found other jumps to the same location?  */
! 	  else if (targets[target])
  	    {
! 	      if (heights[i] != height)
  		{
  		  reqs->flaw = agent_flaw_height_mismatch;
  		  xfree (reg_mask);
  		  return;
  		}
  	    }
! 	  else
! 	    {
! 	      targets[target] = 1;
! 	      heights[target] = height;
! 	    }
  	}
  
        /* For unconditional jumps with a successor, check that the
--- 473,494 ----
  	      xfree (reg_mask);
  	      return;
  	    }
! 
! 	  /* Do we have any information about what the stack height
!              should be at the target?  */
! 	  if (targets[target] || boundary[target])
  	    {
! 	      if (heights[target] != height)
  		{
  		  reqs->flaw = agent_flaw_height_mismatch;
  		  xfree (reg_mask);
  		  return;
  		}
  	    }
! 
!           /* Record the target, along with the stack height we expect.  */
!           targets[target] = 1;
!           heights[target] = height;
  	}
  
        /* For unconditional jumps with a successor, check that the

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