/* GDB-specific functions for operating on agent expressions
- Copyright 1998 Free Software Foundation, Inc.
+ Copyright 1998, 2000 Free Software Foundation, Inc.
-This file is part of GDB.
+ 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
-(at your option) any later version.
+ 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
+ (at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ 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. */
-
-/* $Id$ */
+ 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. */
#include "defs.h"
#include "symtab.h"
#include "expression.h"
#include "command.h"
#include "gdbcmd.h"
+#include "frame.h"
+#include "target.h"
#include "ax.h"
#include "ax-gdb.h"
-/* Probably the best way to read this file is to start with the types
- and enums in ax-gdb.h, and then look at gen_expr, towards the
- bottom; that's the main function that looks at the GDB expressions
- and calls everything else to generate code.
+/* To make sense of this file, you should read doc/agentexpr.texi.
+ Then look at the types and enums in ax-gdb.h. For the code itself,
+ look at gen_expr, towards the bottom; that's the main function that
+ looks at the GDB expressions and calls everything else to generate
+ code.
I'm beginning to wonder whether it wouldn't be nicer to internally
generate trees, with types, and then spit out the bytecode in
pay for the simplicity of this code with less-than-optimal bytecode
strings.
- Remember, "GBD" stands for "Great Britain, Dammit!" So be careful. */
+ Remember, "GBD" stands for "Great Britain, Dammit!" So be careful. */
+\f
-\f
-/* Static forward declarations */
+/* Prototypes for local functions. */
/* There's a standard order to the arguments of these functions:
union exp_element ** --- pointer into expression
struct agent_expr * --- agent expression buffer to generate code into
struct axs_value * --- describes value left on top of stack */
-
-static struct value *const_var_ref PARAMS ((struct symbol *var));
-static struct value *const_expr PARAMS ((union exp_element **pc));
-static struct value *maybe_const_expr PARAMS ((union exp_element **pc));
+
+static struct value *const_var_ref PARAMS ((struct symbol * var));
+static struct value *const_expr PARAMS ((union exp_element ** pc));
+static struct value *maybe_const_expr PARAMS ((union exp_element ** pc));
static void gen_traced_pop PARAMS ((struct agent_expr *, struct axs_value *));
static void gen_frame_args_address PARAMS ((struct agent_expr *));
static void gen_frame_locals_address PARAMS ((struct agent_expr *));
-static void gen_offset PARAMS ((struct agent_expr *ax, int offset));
+static void gen_offset PARAMS ((struct agent_expr * ax, int offset));
static void gen_sym_offset PARAMS ((struct agent_expr *, struct symbol *));
-static void gen_var_ref PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
- struct symbol *var));
-
-
-static void gen_int_literal PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
- LONGEST k, struct type *type));
-
-
-static void require_rvalue PARAMS ((struct agent_expr *ax,
- struct axs_value *value));
-static void gen_usual_unary PARAMS ((struct agent_expr *ax,
- struct axs_value *value));
-static int type_wider_than PARAMS ((struct type *type1,
- struct type *type2));
-static struct type *max_type PARAMS ((struct type *type1,
- struct type *type2));
-static void gen_conversion PARAMS ((struct agent_expr *ax,
- struct type *from,
- struct type *to));
-static int is_nontrivial_conversion PARAMS ((struct type *from,
- struct type *to));
-static void gen_usual_arithmetic PARAMS ((struct agent_expr *ax,
- struct axs_value *value1,
- struct axs_value *value2));
-static void gen_integral_promotions PARAMS ((struct agent_expr *ax,
- struct axs_value *value));
-static void gen_cast PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
- struct type *type));
-static void gen_scale PARAMS ((struct agent_expr *ax,
+static void gen_var_ref PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
+ struct symbol * var));
+
+
+static void gen_int_literal PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
+ LONGEST k, struct type * type));
+
+
+static void require_rvalue PARAMS ((struct agent_expr * ax,
+ struct axs_value * value));
+static void gen_usual_unary PARAMS ((struct agent_expr * ax,
+ struct axs_value * value));
+static int type_wider_than PARAMS ((struct type * type1,
+ struct type * type2));
+static struct type *max_type PARAMS ((struct type * type1,
+ struct type * type2));
+static void gen_conversion PARAMS ((struct agent_expr * ax,
+ struct type * from,
+ struct type * to));
+static int is_nontrivial_conversion PARAMS ((struct type * from,
+ struct type * to));
+static void gen_usual_arithmetic PARAMS ((struct agent_expr * ax,
+ struct axs_value * value1,
+ struct axs_value * value2));
+static void gen_integral_promotions PARAMS ((struct agent_expr * ax,
+ struct axs_value * value));
+static void gen_cast PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
+ struct type * type));
+static void gen_scale PARAMS ((struct agent_expr * ax,
enum agent_op op,
- struct type *type));
-static void gen_add PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
- struct axs_value *value1,
- struct axs_value *value2,
+ struct type * type));
+static void gen_add PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
+ struct axs_value * value1,
+ struct axs_value * value2,
char *name));
-static void gen_sub PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
- struct axs_value *value1,
- struct axs_value *value2));
-static void gen_binop PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
- struct axs_value *value1,
- struct axs_value *value2,
+static void gen_sub PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
+ struct axs_value * value1,
+ struct axs_value * value2));
+static void gen_binop PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
+ struct axs_value * value1,
+ struct axs_value * value2,
enum agent_op op,
enum agent_op op_unsigned,
int may_carry,
char *name));
-static void gen_logical_not PARAMS ((struct agent_expr *ax,
- struct axs_value *value));
-static void gen_complement PARAMS ((struct agent_expr *ax,
- struct axs_value *value));
+static void gen_logical_not PARAMS ((struct agent_expr * ax,
+ struct axs_value * value));
+static void gen_complement PARAMS ((struct agent_expr * ax,
+ struct axs_value * value));
static void gen_deref PARAMS ((struct agent_expr *, struct axs_value *));
static void gen_address_of PARAMS ((struct agent_expr *, struct axs_value *));
-static int find_field PARAMS ((struct type *type, char *name));
-static void gen_bitfield_ref PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
- struct type *type,
+static int find_field PARAMS ((struct type * type, char *name));
+static void gen_bitfield_ref PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
+ struct type * type,
int start, int end));
-static void gen_struct_ref PARAMS ((struct agent_expr *ax,
- struct axs_value *value,
+static void gen_struct_ref PARAMS ((struct agent_expr * ax,
+ struct axs_value * value,
char *field,
char *operator_name,
char *operand_name));
-static void gen_repeat PARAMS ((union exp_element **pc,
- struct agent_expr *ax,
- struct axs_value *value));
-static void gen_sizeof PARAMS ((union exp_element **pc,
- struct agent_expr *ax,
- struct axs_value *value));
-static void gen_expr PARAMS ((union exp_element **pc,
- struct agent_expr *ax,
- struct axs_value *value));
-static void print_axs_value PARAMS ((GDB_FILE *f, struct axs_value *value));
+static void gen_repeat PARAMS ((union exp_element ** pc,
+ struct agent_expr * ax,
+ struct axs_value * value));
+static void gen_sizeof PARAMS ((union exp_element ** pc,
+ struct agent_expr * ax,
+ struct axs_value * value));
+static void gen_expr PARAMS ((union exp_element ** pc,
+ struct agent_expr * ax,
+ struct axs_value * value));
+
+static void print_axs_value (struct ui_file *f, struct axs_value * value);
static void agent_command PARAMS ((char *exp, int from_tty));
-
\f
+
/* Detecting constant expressions. */
/* If the variable reference at *PC is a constant, return its value.
return v;
}
- /* We could add more operators in here. */
+ /* We could add more operators in here. */
case UNOP_NEG:
(*pc)++;
/* If we got a value, then update the real PC. */
if (v)
*pc = tentative_pc;
-
+
return v;
}
-
\f
+
/* Generating bytecode from GDB expressions: general assumptions */
/* Here are a few general assumptions made throughout the code; if you
better scan things pretty thoroughly.
- We assume that all values occupy one stack element. For example,
- sometimes we'll swap to get at the left argument to a binary
- operator. If we decide that void values should occupy no stack
- elements, or that synthetic arrays (whose size is determined at
- run time, created by the `@' operator) should occupy two stack
- elements (address and length), then this will cause trouble.
+ sometimes we'll swap to get at the left argument to a binary
+ operator. If we decide that void values should occupy no stack
+ elements, or that synthetic arrays (whose size is determined at
+ run time, created by the `@' operator) should occupy two stack
+ elements (address and length), then this will cause trouble.
- We assume the stack elements are infinitely wide, and that we
- don't have to worry what happens if the user requests an
- operation that is wider than the actual interpreter's stack.
- That is, it's up to the interpreter to handle directly all the
- integer widths the user has access to. (Woe betide the language
- with bignums!)
+ don't have to worry what happens if the user requests an
+ operation that is wider than the actual interpreter's stack.
+ That is, it's up to the interpreter to handle directly all the
+ integer widths the user has access to. (Woe betide the language
+ with bignums!)
- We don't support side effects. Thus, we don't have to worry about
- GCC's generalized lvalues, function calls, etc.
+ GCC's generalized lvalues, function calls, etc.
- We don't support floating point. Many places where we switch on
- some type don't bother to include cases for floating point; there
- may be even more subtle ways this assumption exists. For
- example, the arguments to % must be integers.
+ some type don't bother to include cases for floating point; there
+ may be even more subtle ways this assumption exists. For
+ example, the arguments to % must be integers.
- We assume all subexpressions have a static, unchanging type. If
- we tried to support convenience variables, this would be a
- problem.
+ we tried to support convenience variables, this would be a
+ problem.
- All values on the stack should always be fully zero- or
- sign-extended.
-
- (I wasn't sure whether to choose this or its opposite --- that
- only addresses are assumed extended --- but it turns out that
- neither convention completely eliminates spurious extend
- operations (if everything is always extended, then you have to
- extend after add, because it could overflow; if nothing is
- extended, then you end up producing extends whenever you change
- sizes), and this is simpler.) */
-
+ sign-extended.
+
+ (I wasn't sure whether to choose this or its opposite --- that
+ only addresses are assumed extended --- but it turns out that
+ neither convention completely eliminates spurious extend
+ operations (if everything is always extended, then you have to
+ extend after add, because it could overflow; if nothing is
+ extended, then you end up producing extends whenever you change
+ sizes), and this is simpler.) */
\f
+
/* Generating bytecode from GDB expressions: the `trace' kludge */
/* The compiler in this file is a general-purpose mechanism for
{
case axs_rvalue:
/* We don't trace rvalues, just the lvalues necessary to
- produce them. So just dispose of this value. */
+ produce them. So just dispose of this value. */
ax_simple (ax, aop_pop);
break;
ax_const_l (ax, length);
ax_simple (ax, aop_trace);
}
- break;
+ break;
case axs_lvalue_register:
/* We need to mention the register somewhere in the bytecode,
/* If we're not tracing, just pop the value. */
ax_simple (ax, aop_pop);
}
+\f
-\f
/* Generating bytecode from GDB expressions: helper functions */
/* Assume that the lower bits of the top of the stack is a value of
struct type *type;
{
/* Do we need to sign-extend this? */
- if (! TYPE_UNSIGNED (type))
+ if (!TYPE_UNSIGNED (type))
ax_ext (ax, type->length * TARGET_CHAR_BIT);
}
many bytes long is it? */
switch (type->length)
{
- case 8 / TARGET_CHAR_BIT: ax_simple (ax, aop_ref8 ); break;
- case 16 / TARGET_CHAR_BIT: ax_simple (ax, aop_ref16); break;
- case 32 / TARGET_CHAR_BIT: ax_simple (ax, aop_ref32); break;
- case 64 / TARGET_CHAR_BIT: ax_simple (ax, aop_ref64); break;
+ case 8 / TARGET_CHAR_BIT:
+ ax_simple (ax, aop_ref8);
+ break;
+ case 16 / TARGET_CHAR_BIT:
+ ax_simple (ax, aop_ref16);
+ break;
+ case 32 / TARGET_CHAR_BIT:
+ ax_simple (ax, aop_ref32);
+ break;
+ case 64 / TARGET_CHAR_BIT:
+ ax_simple (ax, aop_ref64);
+ break;
/* Either our caller shouldn't have asked us to dereference
that pointer (other code's fault), or we're not
implementing something we should be (this code's fault).
In any case, it's a bug the user shouldn't see. */
default:
- error ("GDB bug: ax-gdb.c (gen_fetch): strange size");
+ internal_error ("ax-gdb.c (gen_fetch): strange size");
}
gen_sign_extend (ax, type);
default:
/* Either our caller shouldn't have asked us to dereference that
- pointer (other code's fault), or we're not implementing
- something we should be (this code's fault). In any case,
- it's a bug the user shouldn't see. */
- error ("GDB bug: ax-gdb.c (gen_fetch): bad type code");
+ pointer (other code's fault), or we're not implementing
+ something we should be (this code's fault). In any case,
+ it's a bug the user shouldn't see. */
+ internal_error ("ax-gdb.c (gen_fetch): bad type code");
}
}
ax_simple (ax, aop_rsh_unsigned);
}
}
+\f
-\f
/* Generating bytecode from GDB expressions: symbol references */
/* Generate code to push the base address of the argument portion of
gen_frame_args_address (ax)
struct agent_expr *ax;
{
- /* FIXME: I'm sure this is wrong for processors other than the 68k. */
- ax_reg (ax, FP_REGNUM);
+ long frame_reg, frame_offset;
+
+ TARGET_VIRTUAL_FRAME_POINTER (ax->scope, &frame_reg, &frame_offset);
+ ax_reg (ax, frame_reg);
+ gen_offset (ax, frame_offset);
}
gen_frame_locals_address (ax)
struct agent_expr *ax;
{
- /* FIXME: I'm sure this is wrong for processors other than the 68k. */
- ax_reg (ax, FP_REGNUM);
+ long frame_reg, frame_offset;
+
+ TARGET_VIRTUAL_FRAME_POINTER (ax->scope, &frame_reg, &frame_offset);
+ ax_reg (ax, frame_reg);
+ gen_offset (ax, frame_offset);
}
break;
case LOC_CONST_BYTES:
- error ("GDB bug: ax-gdb.c (gen_var_ref): LOC_CONST_BYTES symbols are not supported");
+ internal_error ("ax-gdb.c (gen_var_ref): LOC_CONST_BYTES symbols are not supported");
/* Variable at a fixed location in memory. Easy. */
case LOC_STATIC:
break;
/* A lot like LOC_REF_ARG, but the pointer lives directly in a
- register, not on the stack. Simpler than LOC_REGISTER and
- LOC_REGPARM, because it's just like any other case where the
- thing has a real address. */
+ register, not on the stack. Simpler than LOC_REGISTER and
+ LOC_REGPARM, because it's just like any other case where the
+ thing has a real address. */
case LOC_REGPARM_ADDR:
ax_reg (ax, SYMBOL_VALUE (var));
value->kind = axs_lvalue_memory;
case LOC_UNRESOLVED:
{
- struct minimal_symbol *msym
- = lookup_minimal_symbol (SYMBOL_NAME (var), NULL, NULL);
- if (! msym)
+ struct minimal_symbol *msym
+ = lookup_minimal_symbol (SYMBOL_NAME (var), NULL, NULL);
+ if (!msym)
error ("Couldn't resolve symbol `%s'.", SYMBOL_SOURCE_NAME (var));
-
+
/* Push the address of the variable. */
ax_const_l (ax, SYMBOL_VALUE_ADDRESS (msym));
value->kind = axs_lvalue_memory;
}
- break;
+ break;
case LOC_OPTIMIZED_OUT:
error ("The variable `%s' has been optimized out.",
break;
}
}
+\f
-\f
/* Generating bytecode from GDB expressions: literals */
static void
value->kind = axs_rvalue;
value->type = type;
}
+\f
-\f
/* Generating bytecode from GDB expressions: unary conversions, casts */
/* Take what's on the top of the stack (as described by VALUE), and
/* There's nothing on the stack, but value->u.reg is the
register number containing the value.
- When we add floating-point support, this is going to have to
- change. What about SPARC register pairs, for example? */
+ When we add floating-point support, this is going to have to
+ change. What about SPARC register pairs, for example? */
ax_reg (ax, value->u.reg);
gen_extend (ax, value->type);
break;
break;
/* Arrays get converted to a pointer to their first element, and
- are no longer an lvalue. */
+ are no longer an lvalue. */
case TYPE_CODE_ARRAY:
{
struct type *elements = TYPE_TARGET_TYPE (value->type);
/* We don't need to generate any code; the address of the array
is also the address of its first element. */
}
- break;
+ break;
- /* Don't try to convert structures and unions to rvalues. Let the
- consumer signal an error. */
+ /* Don't try to convert structures and unions to rvalues. Let the
+ consumer signal an error. */
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
return;
return (TYPE_LENGTH (type1) > TYPE_LENGTH (type2)
|| (TYPE_LENGTH (type1) == TYPE_LENGTH (type2)
&& TYPE_UNSIGNED (type1)
- && ! TYPE_UNSIGNED (type2)));
+ && !TYPE_UNSIGNED (type2)));
}
is_nontrivial_conversion (from, to)
struct type *from, *to;
{
- struct agent_expr *ax = new_agent_expr ();
+ struct agent_expr *ax = new_agent_expr (0);
int nontrivial;
/* Actually generate the code, and see if anything came out. At the
&& TYPE_CODE (value2->type) == TYPE_CODE_INT)
{
/* The ANSI integral promotions seem to work this way: Order the
- integer types by size, and then by signedness: an n-bit
- unsigned type is considered "wider" than an n-bit signed
- type. Promote to the "wider" of the two types, and always
- promote at least to int. */
+ integer types by size, and then by signedness: an n-bit
+ unsigned type is considered "wider" than an n-bit signed
+ type. Promote to the "wider" of the two types, and always
+ promote at least to int. */
struct type *target = max_type (builtin_type_int,
max_type (value1->type, value2->type));
struct agent_expr *ax;
struct axs_value *value;
{
- if (! type_wider_than (value->type, builtin_type_int))
+ if (!type_wider_than (value->type, builtin_type_int))
{
gen_conversion (ax, value->type, builtin_type_int);
value->type = builtin_type_int;
}
- else if (! type_wider_than (value->type, builtin_type_unsigned_int))
+ else if (!type_wider_than (value->type, builtin_type_unsigned_int))
{
gen_conversion (ax, value->type, builtin_type_unsigned_int);
value->type = builtin_type_unsigned_int;
cast like this? */
value->type = type;
break;
-
+
case TYPE_CODE_INT:
gen_conversion (ax, value->type, type);
break;
case TYPE_CODE_VOID:
/* We could pop the value, and rely on everyone else to check
- the type and notice that this value doesn't occupy a stack
- slot. But for now, leave the value on the stack, and
- preserve the "value == stack element" assumption. */
+ the type and notice that this value doesn't occupy a stack
+ slot. But for now, leave the value on the stack, and
+ preserve the "value == stack element" assumption. */
break;
default:
value->type = type;
}
+\f
-\f
/* Generating bytecode from GDB expressions: arithmetic */
/* Scale the integer on the top of the stack by the size of the target
ax_simple (ax, aop_swap);
gen_scale (ax, aop_mul, value2->type);
ax_simple (ax, aop_add);
- gen_extend (ax, value2->type); /* Catch overflow. */
+ gen_extend (ax, value2->type); /* Catch overflow. */
value->type = value2->type;
}
{
gen_scale (ax, aop_mul, value1->type);
ax_simple (ax, aop_add);
- gen_extend (ax, value1->type); /* Catch overflow. */
+ gen_extend (ax, value1->type); /* Catch overflow. */
value->type = value1->type;
}
&& value2->type->code == TYPE_CODE_INT)
{
ax_simple (ax, aop_add);
- gen_extend (ax, value1->type); /* Catch overflow. */
+ gen_extend (ax, value1->type); /* Catch overflow. */
value->type = value1->type;
}
struct agent_expr *ax;
struct axs_value *value, *value1, *value2;
{
- struct type *element;
-
if (value1->type->code == TYPE_CODE_PTR)
{
/* Is it PTR - INT? */
{
gen_scale (ax, aop_mul, value1->type);
ax_simple (ax, aop_sub);
- gen_extend (ax, value1->type); /* Catch overflow. */
+ gen_extend (ax, value1->type); /* Catch overflow. */
value->type = value1->type;
}
/* Is it PTR - PTR? Strictly speaking, the types ought to
- match, but this is what the normal GDB expression evaluator
- tests for. */
+ match, but this is what the normal GDB expression evaluator
+ tests for. */
else if (value2->type->code == TYPE_CODE_PTR
&& (TYPE_LENGTH (TYPE_TARGET_TYPE (value1->type))
== TYPE_LENGTH (TYPE_TARGET_TYPE (value2->type))))
{
ax_simple (ax, aop_sub);
gen_scale (ax, aop_div_unsigned, value1->type);
- value->type = builtin_type_long; /* FIXME --- should be ptrdiff_t */
+ value->type = builtin_type_long; /* FIXME --- should be ptrdiff_t */
}
else
error ("\
&& value2->type->code == TYPE_CODE_INT)
{
ax_simple (ax, aop_sub);
- gen_extend (ax, value1->type); /* Catch overflow. */
+ gen_extend (ax, value1->type); /* Catch overflow. */
value->type = value1->type;
}
-
+
else
error ("Illegal combination of types in subtraction.");
if ((value1->type->code != TYPE_CODE_INT)
|| (value2->type->code != TYPE_CODE_INT))
error ("Illegal combination of types in %s.", name);
-
+
ax_simple (ax,
TYPE_UNSIGNED (value1->type) ? op_unsigned : op);
if (may_carry)
- gen_extend (ax, value1->type); /* catch overflow */
+ gen_extend (ax, value1->type); /* catch overflow */
value->type = value1->type;
value->kind = axs_rvalue;
}
ax_simple (ax, aop_bit_not);
gen_extend (ax, value->type);
}
+\f
-\f
/* Generating bytecode from GDB expressions: * & . -> @ sizeof */
/* Dereference the value on the top of the stack. */
/* The caller should check the type, because several operators use
this, and we don't know what error message to generate. */
if (value->type->code != TYPE_CODE_PTR)
- error ("GDB bug: ax-gdb.c (gen_deref): expected a pointer");
+ internal_error ("ax-gdb.c (gen_deref): expected a pointer");
/* We've got an rvalue now, which is a pointer. We want to yield an
lvalue, whose address is exactly that pointer. So we don't
/* Make sure this isn't C++. */
if (TYPE_N_BASECLASSES (type) != 0)
- error ("GDB bug: ax-gdb.c (find_field): derived classes supported");
+ internal_error ("ax-gdb.c (find_field): derived classes supported");
for (i = 0; i < TYPE_NFIELDS (type); i++)
{
return i;
if (this_name[0] == '\0')
- error ("GDB bug: ax-gdb.c (find_field): anonymous unions not supported");
+ internal_error ("ax-gdb.c (find_field): anonymous unions not supported");
}
error ("Couldn't find member named `%s' in struct/union `%s'",
{
/* Note that ops[i] fetches 8 << i bits. */
static enum agent_op ops[]
- = { aop_ref8, aop_ref16, aop_ref32, aop_ref64 };
+ =
+ {aop_ref8, aop_ref16, aop_ref32, aop_ref64};
static int num_ops = (sizeof (ops) / sizeof (ops[0]));
/* We don't want to touch any byte that the bitfield doesn't
It takes some fancy footwork to get the stack to work the way
we'd like. Say we're retrieving a bitfield that requires three
fetches. Initially, the stack just contains the address:
- addr
+ addr
For the first fetch, we duplicate the address
- addr addr
+ addr addr
then add the byte offset, do the fetch, and shift and mask as
needed, yielding a fragment of the value, properly aligned for
the final bitwise or:
- addr frag1
+ addr frag1
then we swap, and repeat the process:
- frag1 addr --- address on top
- frag1 addr addr --- duplicate it
- frag1 addr frag2 --- get second fragment
- frag1 frag2 addr --- swap again
- frag1 frag2 frag3 --- get third fragment
+ frag1 addr --- address on top
+ frag1 addr addr --- duplicate it
+ frag1 addr frag2 --- get second fragment
+ frag1 frag2 addr --- swap again
+ frag1 frag2 frag3 --- get third fragment
Notice that, since the third fragment is the last one, we don't
bother duplicating the address this time. Now we have all the
fragments on the stack, and we can simply `or' them together,
/* The first and one-after-last bits in the field, but rounded down
and up to byte boundaries. */
int bound_start = (start / TARGET_CHAR_BIT) * TARGET_CHAR_BIT;
- int bound_end = (((end + TARGET_CHAR_BIT - 1)
- / TARGET_CHAR_BIT)
- * TARGET_CHAR_BIT);
+ int bound_end = (((end + TARGET_CHAR_BIT - 1)
+ / TARGET_CHAR_BIT)
+ * TARGET_CHAR_BIT);
/* current bit offset within the structure */
int offset;
/* Can we fetch the number of bits requested at all? */
if ((end - start) > ((1 << num_ops) * 8))
- error ("GDB bug: ax-gdb.c (gen_bitfield_ref): bitfield too wide");
+ internal_error ("ax-gdb.c (gen_bitfield_ref): bitfield too wide");
/* Note that we know here that we only need to try each opcode once.
That may not be true on machines with weird byte sizes. */
int op_size = 8 << op;
/* The stack at this point, from bottom to top, contains zero or
- more fragments, then the address. */
-
+ more fragments, then the address. */
+
/* Does this fetch fit within the bitfield? */
if (offset + op_size <= bound_end)
{
/* Is this the last fragment? */
int last_frag = (offset + op_size == bound_end);
- if (! last_frag)
- ax_simple (ax, aop_dup); /* keep a copy of the address */
-
+ if (!last_frag)
+ ax_simple (ax, aop_dup); /* keep a copy of the address */
+
/* Add the offset. */
gen_offset (ax, offset / TARGET_CHAR_BIT);
/* Perform the fetch. */
ax_simple (ax, ops[op]);
-
- /* Shift the bits we have to their proper position.
+
+ /* Shift the bits we have to their proper position.
gen_left_shift will generate right shifts when the operand
is negative.
- A big-endian field diagram to ponder:
- byte 0 byte 1 byte 2 byte 3 byte 4 byte 5 byte 6 byte 7
- +------++------++------++------++------++------++------++------+
- xxxxAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCxxxxxxxxxxx
- ^ ^ ^ ^
- bit number 16 32 48 53
+ A big-endian field diagram to ponder:
+ byte 0 byte 1 byte 2 byte 3 byte 4 byte 5 byte 6 byte 7
+ +------++------++------++------++------++------++------++------+
+ xxxxAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCxxxxxxxxxxx
+ ^ ^ ^ ^
+ bit number 16 32 48 53
These are bit numbers as supplied by GDB. Note that the
bit numbers run from right to left once you've fetched the
value!
- A little-endian field diagram to ponder:
- byte 7 byte 6 byte 5 byte 4 byte 3 byte 2 byte 1 byte 0
- +------++------++------++------++------++------++------++------+
- xxxxxxxxxxxAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCxxxx
- ^ ^ ^ ^ ^
- bit number 48 32 16 4 0
-
- In both cases, the most significant end is on the left
- (i.e. normal numeric writing order), which means that you
- don't go crazy thinking about `left' and `right' shifts.
-
- We don't have to worry about masking yet:
- - If they contain garbage off the least significant end, then we
- must be looking at the low end of the field, and the right
- shift will wipe them out.
- - If they contain garbage off the most significant end, then we
- must be looking at the most significant end of the word, and
- the sign/zero extension will wipe them out.
- - If we're in the interior of the word, then there is no garbage
- on either end, because the ref operators zero-extend. */
+ A little-endian field diagram to ponder:
+ byte 7 byte 6 byte 5 byte 4 byte 3 byte 2 byte 1 byte 0
+ +------++------++------++------++------++------++------++------+
+ xxxxxxxxxxxAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCxxxx
+ ^ ^ ^ ^ ^
+ bit number 48 32 16 4 0
+
+ In both cases, the most significant end is on the left
+ (i.e. normal numeric writing order), which means that you
+ don't go crazy thinking about `left' and `right' shifts.
+
+ We don't have to worry about masking yet:
+ - If they contain garbage off the least significant end, then we
+ must be looking at the low end of the field, and the right
+ shift will wipe them out.
+ - If they contain garbage off the most significant end, then we
+ must be looking at the most significant end of the word, and
+ the sign/zero extension will wipe them out.
+ - If we're in the interior of the word, then there is no garbage
+ on either end, because the ref operators zero-extend. */
if (TARGET_BYTE_ORDER == BIG_ENDIAN)
gen_left_shift (ax, end - (offset + op_size));
- else
+ else
gen_left_shift (ax, offset - start);
- if (! last_frag)
+ if (!last_frag)
/* Bring the copy of the address up to the top. */
ax_simple (ax, aop_swap);
error ("Structure does not live in memory.");
i = find_field (type, field);
-
+
/* Is this a bitfield? */
if (TYPE_FIELD_PACKED (type, i))
gen_bitfield_ref (ax, value, TYPE_FIELD_TYPE (type, i),
struct value *v = const_expr (pc);
int length;
- if (! v)
+ if (!v)
error ("Right operand of `@' must be a constant, in agent expressions.");
if (v->type->code != TYPE_CODE_INT)
error ("Right operand of `@' must be an integer.");
all we need to do is frob the type of the lvalue. */
{
/* FIXME-type-allocation: need a way to free this type when we are
- done with it. */
+ done with it. */
struct type *range
- = create_range_type (0, builtin_type_int, 0, length - 1);
+ = create_range_type (0, builtin_type_int, 0, length - 1);
struct type *array = create_array_type (0, value1.type, range);
value->kind = axs_lvalue_memory;
/* Throw away the code we just generated. */
ax->len = start;
-
+
ax_const_l (ax, TYPE_LENGTH (value->type));
value->kind = axs_rvalue;
value->type = builtin_type_int;
}
-
\f
+
/* Generating bytecode from GDB expressions: general recursive thingy */
/* A gen_expr function written by a Gen-X'er guy.
/* If we're looking at a constant expression, just push its value. */
{
struct value *v = maybe_const_expr (pc);
-
+
if (v)
{
ax_const_l (ax, value_as_long (v));
default:
/* We should only list operators in the outer case statement
- that we actually handle in the inner case statement. */
- error ("GDB bug: ax-gdb.c (gen_expr): op case sets don't match");
+ that we actually handle in the inner case statement. */
+ internal_error ("ax-gdb.c (gen_expr): op case sets don't match");
}
break;
/* Note that we need to be a little subtle about generating code
- for comma. In C, we can do some optimizations here because
- we know the left operand is only being evaluated for effect.
- However, if the tracing kludge is in effect, then we always
- need to evaluate the left hand side fully, so that all the
- variables it mentions get traced. */
+ for comma. In C, we can do some optimizations here because
+ we know the left operand is only being evaluated for effect.
+ However, if the tracing kludge is in effect, then we always
+ need to evaluate the left hand side fully, so that all the
+ variables it mentions get traced. */
case BINOP_COMMA:
(*pc)++;
gen_expr (pc, ax, &value1);
/* Don't just dispose of the left operand. We might be tracing,
- in which case we want to emit code to trace it if it's an
- lvalue. */
+ in which case we want to emit code to trace it if it's an
+ lvalue. */
gen_traced_pop (ax, &value1);
gen_expr (pc, ax, value);
/* It's the consumer's responsibility to trace the right operand. */
break;
-
+
case OP_LONG: /* some integer constant */
{
struct type *type = (*pc)[1].type;
(*pc) += 4;
gen_int_literal (ax, value, k, type);
}
- break;
+ break;
case OP_VAR_VALUE:
gen_var_ref (ax, value, (*pc)[2].symbol);
value->u.reg = reg;
value->type = REGISTER_VIRTUAL_TYPE (reg);
}
- break;
+ break;
case OP_INTERNALVAR:
error ("GDB agent expressions cannot use convenience variables.");
- /* Weirdo operator: see comments for gen_repeat for details. */
+ /* Weirdo operator: see comments for gen_repeat for details. */
case BINOP_REPEAT:
/* Note that gen_repeat handles its own argument evaluation. */
(*pc)++;
gen_expr (pc, ax, value);
gen_cast (ax, value, type);
}
- break;
+ break;
case UNOP_MEMVAL:
{
the given type, and dereference it. */
if (value->kind != axs_rvalue)
/* This would be weird. */
- error ("GDB bug: ax-gdb.c (gen_expr): OP_MEMVAL operand isn't an rvalue???");
+ internal_error ("ax-gdb.c (gen_expr): OP_MEMVAL operand isn't an rvalue???");
value->type = type;
value->kind = axs_lvalue_memory;
}
- break;
+ break;
case UNOP_NEG:
(*pc)++;
/* -FOO is equivalent to 0 - FOO. */
gen_int_literal (ax, &value1, (LONGEST) 0, builtin_type_int);
- gen_usual_unary (ax, &value1); /* shouldn't do much */
+ gen_usual_unary (ax, &value1); /* shouldn't do much */
gen_expr (pc, ax, &value2);
gen_usual_unary (ax, &value2);
gen_usual_arithmetic (ax, &value1, &value2);
case UNOP_SIZEOF:
(*pc)++;
/* Notice that gen_sizeof handles its own operand, unlike most
- of the other unary operator functions. This is because we
- have to throw away the code we generate. */
+ of the other unary operator functions. This is because we
+ have to throw away the code we generate. */
gen_sizeof (pc, ax, value);
break;
"pointer to a structure or union");
else
/* If this `if' chain doesn't handle it, then the case list
- shouldn't mention it, and we shouldn't be here. */
- error ("GDB bug: ax-gdb.c (gen_expr): unhandled struct case");
+ shouldn't mention it, and we shouldn't be here. */
+ internal_error ("ax-gdb.c (gen_expr): unhandled struct case");
}
- break;
+ break;
case OP_TYPE:
error ("Attempt to use a type name as an expression.");
error ("Unsupported operator in expression.");
}
}
-
-
\f
+
+
/* Generating bytecode from GDB expressions: driver */
/* Given a GDB expression EXPR, produce a string of agent bytecode
struct axs_value *value;
{
struct cleanup *old_chain = 0;
- struct agent_expr *ax = new_agent_expr ();
+ struct agent_expr *ax = new_agent_expr (0);
union exp_element *pc;
old_chain = make_cleanup ((make_cleanup_func) free_agent_expr, ax);
}
+#if 0 /* not used */
/* Given a GDB expression EXPR denoting an lvalue in memory, produce a
string of agent bytecode which will leave its address and size on
the top of stack. Return the agent expression.
return ax;
}
-
+#endif
/* Given a GDB expression EXPR, return bytecode to trace its value.
The result will use the `trace' and `trace_quick' bytecodes to
caller can then use the ax_reqs function to discover which
registers it relies upon. */
struct agent_expr *
-gen_trace_for_expr (expr)
+gen_trace_for_expr (scope, expr)
+ CORE_ADDR scope;
struct expression *expr;
{
struct cleanup *old_chain = 0;
- struct agent_expr *ax = new_agent_expr ();
+ struct agent_expr *ax = new_agent_expr (scope);
union exp_element *pc;
struct axs_value value;
discard_cleanups (old_chain);
return ax;
}
+\f
-\f
/* The "agent" command, for testing: compile and disassemble an expression. */
static void
print_axs_value (f, value)
- GDB_FILE *f;
+ struct ui_file *f;
struct axs_value *value;
{
switch (value->kind)
struct cleanup *old_chain = 0;
struct expression *expr;
struct agent_expr *agent;
- struct agent_reqs reqs;
+ struct frame_info *fi = get_current_frame (); /* need current scope */
/* We don't deal with overlay debugging at the moment. We need to
think more carefully about this. If you copy this code into
if (exp == 0)
error_no_arg ("expression to translate");
-
+
expr = parse_expression (exp);
old_chain = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
- agent = gen_trace_for_expr (expr);
+ agent = gen_trace_for_expr (fi->pc, expr);
make_cleanup ((make_cleanup_func) free_agent_expr, agent);
ax_print (gdb_stdout, agent);
- ax_reqs (agent, &reqs);
+
+ /* It would be nice to call ax_reqs here to gather some general info
+ about the expression, and then print out the result. */
do_cleanups (old_chain);
dont_repeat ();
}
-
\f
+
/* Initialization code. */
+void _initialize_ax_gdb PARAMS ((void));
+void
_initialize_ax_gdb ()
{
- struct cmd_list_element *c;
-
add_cmd ("agent", class_maintenance, agent_command,
"Translate an expression into remote agent bytecode.",
&maintenancelist);