2010-02-16 Sami Wagiaalla <swagiaal@redhat.com>
[deliverable/binutils-gdb.git] / gdb / ax-general.c
index eb7a7caa11ebc02a6d19f645682c6fc0e42a4d11..e2ceb3de7061c84749faa5dc2164ccef13b437d5 100644 (file)
@@ -1,11 +1,12 @@
 /* Functions for manipulating expressions designed to be executed on the agent
-   Copyright 1998, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2007, 2008, 2009, 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 2 of the License, or
+   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,
@@ -14,9 +15,7 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Despite what the above comment says about this file being part of
    GDB, we would like to keep these functions free of GDB
@@ -231,8 +230,12 @@ ax_const_l (struct agent_expr *x, LONGEST l)
      signed or unsigned; we always reproduce the value exactly, and
      use the shortest representation.  */
   for (op = 0, size = 8; size < 64; size *= 2, op++)
-    if (-((LONGEST) 1 << size) <= l && l < ((LONGEST) 1 << size))
-      break;
+    {
+      LONGEST lim = 1 << (size - 1);
+
+      if (-lim <= l && l <= lim - 1)
+        break;
+    }
 
   /* Emit the right opcode... */
   ax_simple (x, ops[op]);
@@ -269,6 +272,22 @@ ax_reg (struct agent_expr *x, int reg)
   x->buf[x->len + 2] = (reg) & 0xff;
   x->len += 3;
 }
+
+/* Assemble code to operate on a trace state variable.  */
+
+void
+ax_tsv (struct agent_expr *x, enum agent_op op, int num)
+{
+  /* Make sure the tsv number is in range.  */
+  if (num < 0 || num > 0xffff)
+    internal_error (__FILE__, __LINE__, _("ax-general.c (ax_tsv): variable number is %d, out of range"), num);
+
+  grow_expr (x, 3);
+  x->buf[x->len] = op;
+  x->buf[x->len + 1] = (num >> 8) & 0xff;
+  x->buf[x->len + 2] = (num) & 0xff;
+  x->len += 3;
+}
 \f
 
 
@@ -321,9 +340,9 @@ struct aop_map aop_map[] =
   {"pop", 0, 0, 1, 0},         /* 0x29 */
   {"zero_ext", 1, 0, 1, 1},    /* 0x2a */
   {"swap", 0, 0, 2, 2},                /* 0x2b */
-  {0, 0, 0, 0, 0},             /* 0x2c */
-  {0, 0, 0, 0, 0},             /* 0x2d */
-  {0, 0, 0, 0, 0},             /* 0x2e */
+  {"getv", 2, 0, 0, 1},                /* 0x2c */
+  {"setv", 2, 0, 0, 1},                /* 0x2d */
+  {"tracev", 2, 0, 0, 1},      /* 0x2e */
   {0, 0, 0, 0, 0},             /* 0x2f */
   {"trace16", 2, 0, 1, 1},     /* 0x30 */
 };
@@ -388,15 +407,15 @@ ax_reqs (struct agent_expr *ax, struct agent_reqs *reqs)
   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.  */
+  /* 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 an
-     instruction starts at offset i.  */
+  /* 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.  iff either targets[i] or boundary[i] is
+  /* 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]));
@@ -437,8 +456,9 @@ ax_reqs (struct agent_expr *ax, struct agent_reqs *reqs)
          return;
        }
 
-      /* If this instruction is a jump target, does the current stack
-         height match the stack height at the jump source?  */
+      /* 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;
@@ -472,21 +492,22 @@ ax_reqs (struct agent_expr *ax, struct agent_reqs *reqs)
              xfree (reg_mask);
              return;
            }
-         /* Have we already found other jumps to the same location?  */
-         else if (targets[target])
+
+         /* Do we have any information about what the stack height
+             should be at the target?  */
+         if (targets[target] || boundary[target])
            {
-             if (heights[i] != height)
+             if (heights[target] != height)
                {
                  reqs->flaw = agent_flaw_height_mismatch;
                  xfree (reg_mask);
                  return;
                }
            }
-         else
-           {
-             targets[target] = 1;
-             heights[target] = height;
-           }
+
+          /* 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
This page took 0.037435 seconds and 4 git commands to generate.