aboutsummaryrefslogtreecommitdiff
path: root/gdb/ax-gdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/ax-gdb.c')
-rw-r--r--gdb/ax-gdb.c510
1 files changed, 260 insertions, 250 deletions
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index f9265e4..6dea775 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1,21 +1,22 @@
/* GDB-specific functions for operating on agent expressions
Copyright 1998 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. */
+ 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"
@@ -43,20 +44,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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. */
+
-
/* 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 *));
@@ -66,91 +67,91 @@ static void gen_fetch PARAMS ((struct agent_expr *, struct type *));
static void gen_left_shift PARAMS ((struct agent_expr *, int));
-static void gen_frame_args_address PARAMS ((struct agent_expr *));
+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 PARAMS ((GDB_FILE * f, struct axs_value * value));
static void agent_command PARAMS ((char *exp, int from_tty));
-
+
/* Detecting constant expressions. */
/* If the variable reference at *PC is a constant, return its value.
@@ -219,7 +220,7 @@ const_expr (pc)
return v;
}
- /* We could add more operators in here. */
+ /* We could add more operators in here. */
case UNOP_NEG:
(*pc)++;
@@ -247,11 +248,11 @@ maybe_const_expr (pc)
/* If we got a value, then update the real PC. */
if (v)
*pc = tentative_pc;
-
+
return v;
}
-
+
/* Generating bytecode from GDB expressions: general assumptions */
/* Here are a few general assumptions made throughout the code; if you
@@ -259,43 +260,43 @@ maybe_const_expr (pc)
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.) */
+
/* Generating bytecode from GDB expressions: the `trace' kludge */
/* The compiler in this file is a general-purpose mechanism for
@@ -334,7 +335,7 @@ gen_traced_pop (ax, value)
{
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;
@@ -350,7 +351,7 @@ gen_traced_pop (ax, value)
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,
@@ -364,9 +365,9 @@ gen_traced_pop (ax, value)
/* If we're not tracing, just pop the value. */
ax_simple (ax, aop_pop);
}
+
-
/* Generating bytecode from GDB expressions: helper functions */
/* Assume that the lower bits of the top of the stack is a value of
@@ -377,7 +378,7 @@ gen_sign_extend (ax, type)
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);
}
@@ -420,10 +421,18 @@ gen_fetch (ax, type)
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
@@ -438,9 +447,9 @@ gen_fetch (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. */
+ 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");
}
}
@@ -465,9 +474,9 @@ gen_left_shift (ax, distance)
ax_simple (ax, aop_rsh_unsigned);
}
}
+
-
/* Generating bytecode from GDB expressions: symbol references */
/* Generate code to push the base address of the argument portion of
@@ -479,7 +488,7 @@ gen_frame_args_address (ax)
long frame_reg, frame_offset;
TARGET_VIRTUAL_FRAME_POINTER (ax->scope, &frame_reg, &frame_offset);
- ax_reg (ax, frame_reg);
+ ax_reg (ax, frame_reg);
gen_offset (ax, frame_offset);
}
@@ -493,7 +502,7 @@ gen_frame_locals_address (ax)
long frame_reg, frame_offset;
TARGET_VIRTUAL_FRAME_POINTER (ax->scope, &frame_reg, &frame_offset);
- ax_reg (ax, frame_reg);
+ ax_reg (ax, frame_reg);
gen_offset (ax, frame_offset);
}
@@ -620,9 +629,9 @@ gen_var_ref (ax, value, var)
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;
@@ -630,16 +639,16 @@ gen_var_ref (ax, value, var)
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.",
@@ -652,9 +661,9 @@ gen_var_ref (ax, value, var)
break;
}
}
+
-
/* Generating bytecode from GDB expressions: literals */
static void
@@ -668,9 +677,9 @@ gen_int_literal (ax, value, k, type)
value->kind = axs_rvalue;
value->type = type;
}
+
-
/* Generating bytecode from GDB expressions: unary conversions, casts */
/* Take what's on the top of the stack (as described by VALUE), and
@@ -696,8 +705,8 @@ require_rvalue (ax, value)
/* 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;
@@ -742,7 +751,7 @@ gen_usual_unary (ax, value)
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);
@@ -751,10 +760,10 @@ gen_usual_unary (ax, value)
/* 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;
@@ -779,7 +788,7 @@ type_wider_than (type1, type2)
return (TYPE_LENGTH (type1) > TYPE_LENGTH (type2)
|| (TYPE_LENGTH (type1) == TYPE_LENGTH (type2)
&& TYPE_UNSIGNED (type1)
- && ! TYPE_UNSIGNED (type2)));
+ && !TYPE_UNSIGNED (type2)));
}
@@ -860,10 +869,10 @@ gen_usual_arithmetic (ax, value1, value2)
&& 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));
@@ -893,12 +902,12 @@ gen_integral_promotions (ax, value)
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;
@@ -940,16 +949,16 @@ gen_cast (ax, value, type)
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:
@@ -958,9 +967,9 @@ gen_cast (ax, value, type)
value->type = type;
}
+
-
/* Generating bytecode from GDB expressions: arithmetic */
/* Scale the integer on the top of the stack by the size of the target
@@ -1000,7 +1009,7 @@ gen_add (ax, value, value1, value2, name)
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;
}
@@ -1010,7 +1019,7 @@ gen_add (ax, value, value1, value2, name)
{
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;
}
@@ -1020,7 +1029,7 @@ gen_add (ax, value, value1, value2, name)
&& 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;
}
@@ -1049,20 +1058,20 @@ gen_sub (ax, value, value1, value2)
{
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 ("\
@@ -1075,10 +1084,10 @@ an integer nor a pointer of the same type.");
&& 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.");
@@ -1103,11 +1112,11 @@ gen_binop (ax, value, value1, value2, op, op_unsigned, may_carry, name)
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;
}
@@ -1141,9 +1150,9 @@ gen_complement (ax, value)
ax_simple (ax, aop_bit_not);
gen_extend (ax, value->type);
}
+
-
/* Generating bytecode from GDB expressions: * & . -> @ sizeof */
/* Dereference the value on the top of the stack. */
@@ -1247,7 +1256,8 @@ gen_bitfield_ref (ax, value, type, start, end)
{
/* 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
@@ -1258,19 +1268,19 @@ gen_bitfield_ref (ax, value, type, start, end)
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,
@@ -1279,9 +1289,9 @@ gen_bitfield_ref (ax, value, type, start, end)
/* 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;
@@ -1310,17 +1320,17 @@ gen_bitfield_ref (ax, value, type, start, end)
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);
@@ -1332,47 +1342,47 @@ gen_bitfield_ref (ax, value, type, start, end)
/* 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);
@@ -1433,7 +1443,7 @@ gen_struct_ref (ax, value, field, operator_name, operand_name)
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),
@@ -1478,7 +1488,7 @@ gen_repeat (pc, ax, value)
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.");
@@ -1490,9 +1500,9 @@ gen_repeat (pc, ax, value)
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;
@@ -1521,13 +1531,13 @@ gen_sizeof (pc, ax, value)
/* 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;
}
-
+
/* Generating bytecode from GDB expressions: general recursive thingy */
/* A gen_expr function written by a Gen-X'er guy.
@@ -1545,7 +1555,7 @@ gen_expr (pc, ax, value)
/* 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));
@@ -1617,28 +1627,28 @@ gen_expr (pc, ax, value)
default:
/* We should only list operators in the outer case statement
- that we actually handle in the inner 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");
}
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;
@@ -1646,7 +1656,7 @@ gen_expr (pc, ax, value)
(*pc) += 4;
gen_int_literal (ax, value, k, type);
}
- break;
+ break;
case OP_VAR_VALUE:
gen_var_ref (ax, value, (*pc)[2].symbol);
@@ -1661,12 +1671,12 @@ gen_expr (pc, ax, value)
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)++;
@@ -1680,7 +1690,7 @@ gen_expr (pc, ax, value)
gen_expr (pc, ax, value);
gen_cast (ax, value, type);
}
- break;
+ break;
case UNOP_MEMVAL:
{
@@ -1697,13 +1707,13 @@ gen_expr (pc, ax, value)
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);
@@ -1740,8 +1750,8 @@ gen_expr (pc, ax, value)
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;
@@ -1760,10 +1770,10 @@ gen_expr (pc, ax, value)
"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. */
+ shouldn't mention it, and we shouldn't be here. */
error ("GDB bug: ax-gdb.c (gen_expr): unhandled struct case");
}
- break;
+ break;
case OP_TYPE:
error ("Attempt to use a type name as an expression.");
@@ -1772,10 +1782,10 @@ gen_expr (pc, ax, value)
error ("Unsupported operator in expression.");
}
}
-
-
-#if 0 /* not used */
+
+
+#if 0 /* not used */
/* Generating bytecode from GDB expressions: driver */
/* Given a GDB expression EXPR, produce a string of agent bytecode
@@ -1863,9 +1873,9 @@ gen_trace_for_expr (scope, expr)
discard_cleanups (old_chain);
return ax;
}
+
-
/* The "agent" command, for testing: compile and disassemble an expression. */
static void
@@ -1901,7 +1911,7 @@ agent_command (exp, from_tty)
struct cleanup *old_chain = 0;
struct expression *expr;
struct agent_expr *agent;
- struct frame_info *fi = get_current_frame (); /* need current scope */
+ 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
@@ -1912,7 +1922,7 @@ agent_command (exp, from_tty)
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 (fi->pc, expr);
@@ -1925,8 +1935,8 @@ agent_command (exp, from_tty)
do_cleanups (old_chain);
dont_repeat ();
}
-
+
/* Initialization code. */
void _initialize_ax_gdb PARAMS ((void));