~ubuntu-branches/debian/jessie/gdb/jessie

« back to all changes in this revision

Viewing changes to gdb/ax-gdb.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2010-03-20 01:21:29 UTC
  • mfrom: (1.3.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320012129-t7h25y8zgr8c2369
Tags: 7.1-1
* New upstream release, including:
  - PIE support (Closes: #346409).
  - C++ improvements, including static_cast<> et al, namespace imports,
    and bug fixes in printing virtual base classes.
  - Multi-program debugging.  One GDB can now debug multiple programs
    at the same time.
  - Python scripting improvements, including gdb.parse_and_eval.
  - Updated MIPS Linux signal frame layout (Closes: #570875).
  - No internal error stepping over _dl_debug_state (Closes: #569551).
* Update to Standards-Version: 3.8.4 (no changes required).
* Include more relevant (and smaller) docs in the gdbserver package
  (Closes: #571132).
* Do not duplicate documentation in gdb64, gdb-source, and libgdb-dev.
* Fix crash when switching into TUI mode (Closes: #568489).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GDB-specific functions for operating on agent expressions.
2
2
 
3
 
   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2007, 2008, 2009
 
3
   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2007, 2008, 2009, 2010
4
4
   Free Software Foundation, Inc.
5
5
 
6
6
   This file is part of GDB.
22
22
#include "symtab.h"
23
23
#include "symfile.h"
24
24
#include "gdbtypes.h"
 
25
#include "language.h"
25
26
#include "value.h"
26
27
#include "expression.h"
27
28
#include "command.h"
35
36
#include "regcache.h"
36
37
#include "user-regs.h"
37
38
#include "language.h"
 
39
#include "dictionary.h"
 
40
#include "breakpoint.h"
 
41
#include "tracepoint.h"
38
42
 
39
43
/* To make sense of this file, you should read doc/agentexpr.texi.
40
44
   Then look at the types and enums in ax-gdb.h.  For the code itself,
138
142
                        struct type *size_type);
139
143
static void gen_expr (struct expression *exp, union exp_element **pc,
140
144
                      struct agent_expr *ax, struct axs_value *value);
 
145
static void gen_expr_binop_rest (struct expression *exp,
 
146
                                 enum exp_opcode op, union exp_element **pc,
 
147
                                 struct agent_expr *ax,
 
148
                                 struct axs_value *value,
 
149
                                 struct axs_value *value1,
 
150
                                 struct axs_value *value2);
141
151
 
142
152
static void agent_command (char *exp, int from_tty);
143
153
 
393
403
  switch (TYPE_CODE (type))
394
404
    {
395
405
    case TYPE_CODE_PTR:
 
406
    case TYPE_CODE_REF:
396
407
    case TYPE_CODE_ENUM:
397
408
    case TYPE_CODE_INT:
398
409
    case TYPE_CODE_CHAR:
893
904
  switch (TYPE_CODE (type))
894
905
    {
895
906
    case TYPE_CODE_PTR:
 
907
    case TYPE_CODE_REF:
896
908
      /* It's implementation-defined, and I'll bet this is what GCC
897
909
         does.  */
898
910
      break;
953
965
gen_ptradd (struct agent_expr *ax, struct axs_value *value,
954
966
            struct axs_value *value1, struct axs_value *value2)
955
967
{
956
 
  gdb_assert (TYPE_CODE (value1->type) == TYPE_CODE_PTR);
 
968
  gdb_assert (pointer_type (value1->type));
957
969
  gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
958
970
 
959
971
  gen_scale (ax, aop_mul, value1->type);
969
981
gen_ptrsub (struct agent_expr *ax, struct axs_value *value,
970
982
            struct axs_value *value1, struct axs_value *value2)
971
983
{
972
 
  gdb_assert (TYPE_CODE (value1->type) == TYPE_CODE_PTR);
 
984
  gdb_assert (pointer_type (value1->type));
973
985
  gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
974
986
 
975
987
  gen_scale (ax, aop_mul, value1->type);
986
998
             struct axs_value *value1, struct axs_value *value2,
987
999
             struct type *result_type)
988
1000
{
989
 
  gdb_assert (TYPE_CODE (value1->type) == TYPE_CODE_PTR);
990
 
  gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_PTR);
 
1001
  gdb_assert (pointer_type (value1->type));
 
1002
  gdb_assert (pointer_type (value2->type));
991
1003
 
992
1004
  if (TYPE_LENGTH (TYPE_TARGET_TYPE (value1->type))
993
1005
      != TYPE_LENGTH (TYPE_TARGET_TYPE (value2->type)))
1060
1072
{
1061
1073
  /* The caller should check the type, because several operators use
1062
1074
     this, and we don't know what error message to generate.  */
1063
 
  if (TYPE_CODE (value->type) != TYPE_CODE_PTR)
 
1075
  if (!pointer_type (value->type))
1064
1076
    internal_error (__FILE__, __LINE__,
1065
1077
                    _("gen_deref: expected a pointer"));
1066
1078
 
1070
1082
     T" to "T", and mark the value as an lvalue in memory.  Leave it
1071
1083
     to the consumer to actually dereference it.  */
1072
1084
  value->type = check_typedef (TYPE_TARGET_TYPE (value->type));
 
1085
  if (TYPE_CODE (value->type) == TYPE_CODE_VOID)
 
1086
    error (_("Attempt to dereference a generic pointer."));
1073
1087
  value->kind = ((TYPE_CODE (value->type) == TYPE_CODE_FUNC)
1074
1088
                 ? axs_rvalue : axs_lvalue_memory);
1075
1089
}
1319
1333
  /* Follow pointers until we reach a non-pointer.  These aren't the C
1320
1334
     semantics, but they're what the normal GDB evaluator does, so we
1321
1335
     should at least be consistent.  */
1322
 
  while (TYPE_CODE (value->type) == TYPE_CODE_PTR)
 
1336
  while (pointer_type (value->type))
1323
1337
    {
1324
1338
      require_rvalue (ax, value);
1325
1339
      gen_deref (ax, value);
1439
1453
          struct agent_expr *ax, struct axs_value *value)
1440
1454
{
1441
1455
  /* Used to hold the descriptions of operand expressions.  */
1442
 
  struct axs_value value1, value2;
1443
 
  enum exp_opcode op = (*pc)[0].opcode;
 
1456
  struct axs_value value1, value2, value3;
 
1457
  enum exp_opcode op = (*pc)[0].opcode, op2;
 
1458
  int if1, go1, if2, go2, end;
1444
1459
 
1445
1460
  /* If we're looking at a constant expression, just push its value.  */
1446
1461
  {
1477
1492
      (*pc)++;
1478
1493
      gen_expr (exp, pc, ax, &value1);
1479
1494
      gen_usual_unary (exp, ax, &value1);
1480
 
      gen_expr (exp, pc, ax, &value2);
1481
 
      gen_usual_unary (exp, ax, &value2);
1482
 
      gen_usual_arithmetic (exp, ax, &value1, &value2);
1483
 
      switch (op)
1484
 
        {
1485
 
        case BINOP_ADD:
1486
 
          if (TYPE_CODE (value1.type) == TYPE_CODE_INT
1487
 
              && TYPE_CODE (value2.type) == TYPE_CODE_PTR)
1488
 
            {
1489
 
              /* Swap the values and proceed normally.  */
1490
 
              ax_simple (ax, aop_swap);
1491
 
              gen_ptradd (ax, value, &value2, &value1);
1492
 
            }
1493
 
          else if (TYPE_CODE (value1.type) == TYPE_CODE_PTR
1494
 
                   && TYPE_CODE (value2.type) == TYPE_CODE_INT)
1495
 
            gen_ptradd (ax, value, &value1, &value2);
1496
 
          else
1497
 
            gen_binop (ax, value, &value1, &value2,
1498
 
                       aop_add, aop_add, 1, "addition");
1499
 
          break;
1500
 
        case BINOP_SUB:
1501
 
          if (TYPE_CODE (value1.type) == TYPE_CODE_PTR
1502
 
              && TYPE_CODE (value2.type) == TYPE_CODE_INT)
1503
 
            gen_ptrsub (ax,value, &value1, &value2);
1504
 
          else if (TYPE_CODE (value1.type) == TYPE_CODE_PTR
1505
 
                   && TYPE_CODE (value2.type) == TYPE_CODE_PTR)
1506
 
            /* FIXME --- result type should be ptrdiff_t */
1507
 
            gen_ptrdiff (ax, value, &value1, &value2,
1508
 
                         builtin_type (exp->gdbarch)->builtin_long);
1509
 
          else
1510
 
            gen_binop (ax, value, &value1, &value2,
1511
 
                       aop_sub, aop_sub, 1, "subtraction");
1512
 
          break;
1513
 
        case BINOP_MUL:
1514
 
          gen_binop (ax, value, &value1, &value2,
1515
 
                     aop_mul, aop_mul, 1, "multiplication");
1516
 
          break;
1517
 
        case BINOP_DIV:
1518
 
          gen_binop (ax, value, &value1, &value2,
1519
 
                     aop_div_signed, aop_div_unsigned, 1, "division");
1520
 
          break;
1521
 
        case BINOP_REM:
1522
 
          gen_binop (ax, value, &value1, &value2,
1523
 
                     aop_rem_signed, aop_rem_unsigned, 1, "remainder");
1524
 
          break;
1525
 
        case BINOP_SUBSCRIPT:
1526
 
          gen_ptradd (ax, value, &value1, &value2);
1527
 
          if (TYPE_CODE (value->type) != TYPE_CODE_PTR)
1528
 
            error (_("Invalid combination of types in array subscripting."));
1529
 
          gen_deref (ax, value);
1530
 
          break;
1531
 
        case BINOP_BITWISE_AND:
1532
 
          gen_binop (ax, value, &value1, &value2,
1533
 
                     aop_bit_and, aop_bit_and, 0, "bitwise and");
1534
 
          break;
1535
 
 
1536
 
        case BINOP_BITWISE_IOR:
1537
 
          gen_binop (ax, value, &value1, &value2,
1538
 
                     aop_bit_or, aop_bit_or, 0, "bitwise or");
1539
 
          break;
1540
 
 
1541
 
        case BINOP_BITWISE_XOR:
1542
 
          gen_binop (ax, value, &value1, &value2,
1543
 
                     aop_bit_xor, aop_bit_xor, 0, "bitwise exclusive-or");
1544
 
          break;
1545
 
 
1546
 
        case BINOP_EQUAL:
1547
 
          gen_binop (ax, value, &value1, &value2,
1548
 
                     aop_equal, aop_equal, 0, "equal");
1549
 
          break;
1550
 
 
1551
 
        case BINOP_NOTEQUAL:
1552
 
          gen_binop (ax, value, &value1, &value2,
1553
 
                     aop_equal, aop_equal, 0, "equal");
1554
 
          gen_logical_not (ax, value,
1555
 
                           language_bool_type (exp->language_defn,
1556
 
                                               exp->gdbarch));
1557
 
          break;
1558
 
 
1559
 
        case BINOP_LESS:
1560
 
          gen_binop (ax, value, &value1, &value2,
1561
 
                     aop_less_signed, aop_less_unsigned, 0, "less than");
1562
 
          break;
1563
 
 
1564
 
        case BINOP_GTR:
1565
 
          ax_simple (ax, aop_swap);
1566
 
          gen_binop (ax, value, &value1, &value2,
1567
 
                     aop_less_signed, aop_less_unsigned, 0, "less than");
1568
 
          break;
1569
 
 
1570
 
        case BINOP_LEQ:
1571
 
          ax_simple (ax, aop_swap);
1572
 
          gen_binop (ax, value, &value1, &value2,
1573
 
                     aop_less_signed, aop_less_unsigned, 0, "less than");
1574
 
          gen_logical_not (ax, value,
1575
 
                           language_bool_type (exp->language_defn,
1576
 
                                               exp->gdbarch));
1577
 
          break;
1578
 
 
1579
 
        case BINOP_GEQ:
1580
 
          gen_binop (ax, value, &value1, &value2,
1581
 
                     aop_less_signed, aop_less_unsigned, 0, "less than");
1582
 
          gen_logical_not (ax, value,
1583
 
                           language_bool_type (exp->language_defn,
1584
 
                                               exp->gdbarch));
1585
 
          break;
1586
 
 
1587
 
        default:
1588
 
          /* We should only list operators in the outer case statement
1589
 
             that we actually handle in the inner case statement.  */
1590
 
          internal_error (__FILE__, __LINE__,
1591
 
                          _("gen_expr: op case sets don't match"));
1592
 
        }
 
1495
      gen_expr_binop_rest (exp, op, pc, ax, value, &value1, &value2);
 
1496
      break;
 
1497
 
 
1498
    case BINOP_LOGICAL_AND:
 
1499
      (*pc)++;
 
1500
      /* Generate the obvious sequence of tests and jumps.  */
 
1501
      gen_expr (exp, pc, ax, &value1);
 
1502
      gen_usual_unary (exp, ax, &value1);
 
1503
      if1 = ax_goto (ax, aop_if_goto);
 
1504
      go1 = ax_goto (ax, aop_goto);
 
1505
      ax_label (ax, if1, ax->len);
 
1506
      gen_expr (exp, pc, ax, &value2);
 
1507
      gen_usual_unary (exp, ax, &value2);
 
1508
      if2 = ax_goto (ax, aop_if_goto);
 
1509
      go2 = ax_goto (ax, aop_goto);
 
1510
      ax_label (ax, if2, ax->len);
 
1511
      ax_const_l (ax, 1);
 
1512
      end = ax_goto (ax, aop_goto);
 
1513
      ax_label (ax, go1, ax->len);
 
1514
      ax_label (ax, go2, ax->len);
 
1515
      ax_const_l (ax, 0);
 
1516
      ax_label (ax, end, ax->len);
 
1517
      value->kind = axs_rvalue;
 
1518
      value->type = language_bool_type (exp->language_defn, exp->gdbarch);
 
1519
      break;
 
1520
 
 
1521
    case BINOP_LOGICAL_OR:
 
1522
      (*pc)++;
 
1523
      /* Generate the obvious sequence of tests and jumps.  */
 
1524
      gen_expr (exp, pc, ax, &value1);
 
1525
      gen_usual_unary (exp, ax, &value1);
 
1526
      if1 = ax_goto (ax, aop_if_goto);
 
1527
      gen_expr (exp, pc, ax, &value2);
 
1528
      gen_usual_unary (exp, ax, &value2);
 
1529
      if2 = ax_goto (ax, aop_if_goto);
 
1530
      ax_const_l (ax, 0);
 
1531
      end = ax_goto (ax, aop_goto);
 
1532
      ax_label (ax, if1, ax->len);
 
1533
      ax_label (ax, if2, ax->len);
 
1534
      ax_const_l (ax, 1);
 
1535
      ax_label (ax, end, ax->len);
 
1536
      value->kind = axs_rvalue;
 
1537
      value->type = language_bool_type (exp->language_defn, exp->gdbarch);
 
1538
      break;
 
1539
 
 
1540
    case TERNOP_COND:
 
1541
      (*pc)++;
 
1542
      gen_expr (exp, pc, ax, &value1);
 
1543
      gen_usual_unary (exp, ax, &value1);
 
1544
      /* For (A ? B : C), it's easiest to generate subexpression
 
1545
         bytecodes in order, but if_goto jumps on true, so we invert
 
1546
         the sense of A.  Then we can do B by dropping through, and
 
1547
         jump to do C.  */
 
1548
      gen_logical_not (ax, &value1,
 
1549
                       language_bool_type (exp->language_defn, exp->gdbarch));
 
1550
      if1 = ax_goto (ax, aop_if_goto);
 
1551
      gen_expr (exp, pc, ax, &value2);
 
1552
      gen_usual_unary (exp, ax, &value2);
 
1553
      end = ax_goto (ax, aop_goto);
 
1554
      ax_label (ax, if1, ax->len);
 
1555
      gen_expr (exp, pc, ax, &value3);
 
1556
      gen_usual_unary (exp, ax, &value3);
 
1557
      ax_label (ax, end, ax->len);
 
1558
      /* This is arbitary - what if B and C are incompatible types? */
 
1559
      value->type = value2.type;
 
1560
      value->kind = value2.kind;
 
1561
      break;
 
1562
 
 
1563
    case BINOP_ASSIGN:
 
1564
      (*pc)++;
 
1565
      if ((*pc)[0].opcode == OP_INTERNALVAR)
 
1566
        {
 
1567
          char *name = internalvar_name ((*pc)[1].internalvar);
 
1568
          struct trace_state_variable *tsv;
 
1569
          (*pc) += 3;
 
1570
          gen_expr (exp, pc, ax, value);
 
1571
          tsv = find_trace_state_variable (name);
 
1572
          if (tsv)
 
1573
            {
 
1574
              ax_tsv (ax, aop_setv, tsv->number);
 
1575
              if (trace_kludge)
 
1576
                ax_tsv (ax, aop_tracev, tsv->number);
 
1577
            }
 
1578
          else
 
1579
            error (_("$%s is not a trace state variable, may not assign to it"), name);
 
1580
        }
 
1581
      else
 
1582
        error (_("May only assign to trace state variables"));
 
1583
      break;
 
1584
 
 
1585
    case BINOP_ASSIGN_MODIFY:
 
1586
      (*pc)++;
 
1587
      op2 = (*pc)[0].opcode;
 
1588
      (*pc)++;
 
1589
      (*pc)++;
 
1590
      if ((*pc)[0].opcode == OP_INTERNALVAR)
 
1591
        {
 
1592
          char *name = internalvar_name ((*pc)[1].internalvar);
 
1593
          struct trace_state_variable *tsv;
 
1594
          (*pc) += 3;
 
1595
          tsv = find_trace_state_variable (name);
 
1596
          if (tsv)
 
1597
            {
 
1598
              /* The tsv will be the left half of the binary operation.  */
 
1599
              ax_tsv (ax, aop_getv, tsv->number);
 
1600
              if (trace_kludge)
 
1601
                ax_tsv (ax, aop_tracev, tsv->number);
 
1602
              /* Trace state variables are always 64-bit integers.  */
 
1603
              value1.kind = axs_rvalue;
 
1604
              value1.type = builtin_type (exp->gdbarch)->builtin_long_long;
 
1605
              /* Now do right half of expression.  */
 
1606
              gen_expr_binop_rest (exp, op2, pc, ax, value, &value1, &value2);
 
1607
              /* We have a result of the binary op, set the tsv.  */
 
1608
              ax_tsv (ax, aop_setv, tsv->number);
 
1609
              if (trace_kludge)
 
1610
                ax_tsv (ax, aop_tracev, tsv->number);
 
1611
            }
 
1612
          else
 
1613
            error (_("$%s is not a trace state variable, may not assign to it"), name);
 
1614
        }
 
1615
      else
 
1616
        error (_("May only assign to trace state variables"));
1593
1617
      break;
1594
1618
 
1595
1619
      /* Note that we need to be a little subtle about generating code
1643
1667
      break;
1644
1668
 
1645
1669
    case OP_INTERNALVAR:
1646
 
      error (_("GDB agent expressions cannot use convenience variables."));
 
1670
      {
 
1671
        const char *name = internalvar_name ((*pc)[1].internalvar);
 
1672
        struct trace_state_variable *tsv;
 
1673
        (*pc) += 3;
 
1674
        tsv = find_trace_state_variable (name);
 
1675
        if (tsv)
 
1676
          {
 
1677
            ax_tsv (ax, aop_getv, tsv->number);
 
1678
            if (trace_kludge)
 
1679
              ax_tsv (ax, aop_tracev, tsv->number);
 
1680
            /* Trace state variables are always 64-bit integers.  */
 
1681
            value->kind = axs_rvalue;
 
1682
            value->type = builtin_type (exp->gdbarch)->builtin_long_long;
 
1683
          }
 
1684
        else
 
1685
          error (_("$%s is not a trace state variable; GDB agent expressions cannot use convenience variables."), name);
 
1686
      }
 
1687
      break;
1647
1688
 
1648
1689
      /* Weirdo operator: see comments for gen_repeat for details.  */
1649
1690
    case BINOP_REPEAT:
1718
1759
      (*pc)++;
1719
1760
      gen_expr (exp, pc, ax, value);
1720
1761
      gen_usual_unary (exp, ax, value);
1721
 
      if (TYPE_CODE (value->type) != TYPE_CODE_PTR)
 
1762
      if (!pointer_type (value->type))
1722
1763
        error (_("Argument of unary `*' is not a pointer."));
1723
1764
      gen_deref (ax, value);
1724
1765
      break;
1759
1800
      }
1760
1801
      break;
1761
1802
 
 
1803
    case OP_THIS:
 
1804
      {
 
1805
        char *this_name;
 
1806
        struct symbol *func, *sym;
 
1807
        struct block *b;
 
1808
 
 
1809
        func = block_linkage_function (block_for_pc (ax->scope));
 
1810
        this_name = language_def (SYMBOL_LANGUAGE (func))->la_name_of_this;
 
1811
        b = SYMBOL_BLOCK_VALUE (func);
 
1812
 
 
1813
        /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
 
1814
           symbol instead of the LOC_ARG one (if both exist).  */
 
1815
        sym = lookup_block_symbol (b, this_name, NULL, VAR_DOMAIN);
 
1816
        if (!sym)
 
1817
          error (_("no `%s' found"), this_name);
 
1818
 
 
1819
        gen_var_ref (exp->gdbarch, ax, value, sym);
 
1820
        (*pc) += 2;
 
1821
      }
 
1822
      break;
 
1823
 
1762
1824
    case OP_TYPE:
1763
1825
      error (_("Attempt to use a type name as an expression."));
1764
1826
 
1766
1828
      error (_("Unsupported operator in expression."));
1767
1829
    }
1768
1830
}
 
1831
 
 
1832
/* This handles the middle-to-right-side of code generation for binary
 
1833
   expressions, which is shared between regular binary operations and
 
1834
   assign-modify (+= and friends) expressions.  */
 
1835
 
 
1836
static void
 
1837
gen_expr_binop_rest (struct expression *exp,
 
1838
                     enum exp_opcode op, union exp_element **pc,
 
1839
                     struct agent_expr *ax, struct axs_value *value,
 
1840
                     struct axs_value *value1, struct axs_value *value2)
 
1841
{
 
1842
  gen_expr (exp, pc, ax, value2);
 
1843
  gen_usual_unary (exp, ax, value2);
 
1844
  gen_usual_arithmetic (exp, ax, value1, value2);
 
1845
  switch (op)
 
1846
    {
 
1847
    case BINOP_ADD:
 
1848
      if (TYPE_CODE (value1->type) == TYPE_CODE_INT
 
1849
          && pointer_type (value2->type))
 
1850
        {
 
1851
          /* Swap the values and proceed normally.  */
 
1852
          ax_simple (ax, aop_swap);
 
1853
          gen_ptradd (ax, value, value2, value1);
 
1854
        }
 
1855
      else if (pointer_type (value1->type)
 
1856
               && TYPE_CODE (value2->type) == TYPE_CODE_INT)
 
1857
        gen_ptradd (ax, value, value1, value2);
 
1858
      else
 
1859
        gen_binop (ax, value, value1, value2,
 
1860
                   aop_add, aop_add, 1, "addition");
 
1861
      break;
 
1862
    case BINOP_SUB:
 
1863
      if (pointer_type (value1->type)
 
1864
          && TYPE_CODE (value2->type) == TYPE_CODE_INT)
 
1865
        gen_ptrsub (ax,value, value1, value2);
 
1866
      else if (pointer_type (value1->type)
 
1867
               && pointer_type (value2->type))
 
1868
        /* FIXME --- result type should be ptrdiff_t */
 
1869
        gen_ptrdiff (ax, value, value1, value2,
 
1870
                     builtin_type (exp->gdbarch)->builtin_long);
 
1871
      else
 
1872
        gen_binop (ax, value, value1, value2,
 
1873
                   aop_sub, aop_sub, 1, "subtraction");
 
1874
      break;
 
1875
    case BINOP_MUL:
 
1876
      gen_binop (ax, value, value1, value2,
 
1877
                 aop_mul, aop_mul, 1, "multiplication");
 
1878
      break;
 
1879
    case BINOP_DIV:
 
1880
      gen_binop (ax, value, value1, value2,
 
1881
                 aop_div_signed, aop_div_unsigned, 1, "division");
 
1882
      break;
 
1883
    case BINOP_REM:
 
1884
      gen_binop (ax, value, value1, value2,
 
1885
                 aop_rem_signed, aop_rem_unsigned, 1, "remainder");
 
1886
      break;
 
1887
    case BINOP_SUBSCRIPT:
 
1888
      {
 
1889
        struct type *type;
 
1890
 
 
1891
        if (binop_types_user_defined_p (op, value1->type, value2->type))
 
1892
          {
 
1893
            error (_("\
 
1894
cannot subscript requested type: cannot call user defined functions"));
 
1895
          }
 
1896
        else
 
1897
          {
 
1898
            /* If the user attempts to subscript something that is not
 
1899
               an array or pointer type (like a plain int variable for
 
1900
               example), then report this as an error.  */
 
1901
            type = check_typedef (value1->type);
 
1902
            if (TYPE_CODE (type) != TYPE_CODE_ARRAY
 
1903
                && TYPE_CODE (type) != TYPE_CODE_PTR)
 
1904
              {
 
1905
                if (TYPE_NAME (type))
 
1906
                  error (_("cannot subscript something of type `%s'"),
 
1907
                         TYPE_NAME (type));
 
1908
                else
 
1909
                  error (_("cannot subscript requested type"));
 
1910
              }
 
1911
          }
 
1912
 
 
1913
        if (!is_integral_type (value2->type))
 
1914
          error (_("Argument to arithmetic operation not a number or boolean."));
 
1915
 
 
1916
        gen_ptradd (ax, value, value1, value2);
 
1917
        gen_deref (ax, value);
 
1918
        break;
 
1919
      }
 
1920
    case BINOP_BITWISE_AND:
 
1921
      gen_binop (ax, value, value1, value2,
 
1922
                 aop_bit_and, aop_bit_and, 0, "bitwise and");
 
1923
      break;
 
1924
 
 
1925
    case BINOP_BITWISE_IOR:
 
1926
      gen_binop (ax, value, value1, value2,
 
1927
                 aop_bit_or, aop_bit_or, 0, "bitwise or");
 
1928
      break;
 
1929
      
 
1930
    case BINOP_BITWISE_XOR:
 
1931
      gen_binop (ax, value, value1, value2,
 
1932
                 aop_bit_xor, aop_bit_xor, 0, "bitwise exclusive-or");
 
1933
      break;
 
1934
 
 
1935
    case BINOP_EQUAL:
 
1936
      gen_binop (ax, value, value1, value2,
 
1937
                 aop_equal, aop_equal, 0, "equal");
 
1938
      break;
 
1939
 
 
1940
    case BINOP_NOTEQUAL:
 
1941
      gen_binop (ax, value, value1, value2,
 
1942
                 aop_equal, aop_equal, 0, "equal");
 
1943
      gen_logical_not (ax, value,
 
1944
                       language_bool_type (exp->language_defn,
 
1945
                                           exp->gdbarch));
 
1946
      break;
 
1947
 
 
1948
    case BINOP_LESS:
 
1949
      gen_binop (ax, value, value1, value2,
 
1950
                 aop_less_signed, aop_less_unsigned, 0, "less than");
 
1951
      break;
 
1952
 
 
1953
    case BINOP_GTR:
 
1954
      ax_simple (ax, aop_swap);
 
1955
      gen_binop (ax, value, value1, value2,
 
1956
                 aop_less_signed, aop_less_unsigned, 0, "less than");
 
1957
      break;
 
1958
 
 
1959
    case BINOP_LEQ:
 
1960
      ax_simple (ax, aop_swap);
 
1961
      gen_binop (ax, value, value1, value2,
 
1962
                 aop_less_signed, aop_less_unsigned, 0, "less than");
 
1963
      gen_logical_not (ax, value,
 
1964
                       language_bool_type (exp->language_defn,
 
1965
                                           exp->gdbarch));
 
1966
      break;
 
1967
 
 
1968
    case BINOP_GEQ:
 
1969
      gen_binop (ax, value, value1, value2,
 
1970
                 aop_less_signed, aop_less_unsigned, 0, "less than");
 
1971
      gen_logical_not (ax, value,
 
1972
                       language_bool_type (exp->language_defn,
 
1973
                                           exp->gdbarch));
 
1974
      break;
 
1975
 
 
1976
    default:
 
1977
      /* We should only list operators in the outer case statement
 
1978
         that we actually handle in the inner case statement.  */
 
1979
      internal_error (__FILE__, __LINE__,
 
1980
                      _("gen_expr: op case sets don't match"));
 
1981
    }
 
1982
}
1769
1983
 
1770
1984
 
 
1985
/* Given a single variable and a scope, generate bytecodes to trace
 
1986
   its value.  This is for use in situations where we have only a
 
1987
   variable's name, and no parsed expression; for instance, when the
 
1988
   name comes from a list of local variables of a function.  */
 
1989
 
 
1990
struct agent_expr *
 
1991
gen_trace_for_var (CORE_ADDR scope, struct symbol *var)
 
1992
{
 
1993
  struct cleanup *old_chain = 0;
 
1994
  struct agent_expr *ax = new_agent_expr (scope);
 
1995
  struct axs_value value;
 
1996
 
 
1997
  old_chain = make_cleanup_free_agent_expr (ax);
 
1998
 
 
1999
  trace_kludge = 1;
 
2000
  gen_var_ref (NULL, ax, &value, var);
 
2001
 
 
2002
  /* Make sure we record the final object, and get rid of it.  */
 
2003
  gen_traced_pop (ax, &value);
 
2004
 
 
2005
  /* Oh, and terminate.  */
 
2006
  ax_simple (ax, aop_end);
 
2007
 
 
2008
  /* We have successfully built the agent expr, so cancel the cleanup
 
2009
     request.  If we add more cleanups that we always want done, this
 
2010
     will have to get more complicated.  */
 
2011
  discard_cleanups (old_chain);
 
2012
  return ax;
 
2013
}
1771
2014
 
1772
2015
/* Generating bytecode from GDB expressions: driver */
1773
2016