/* Parse expressions for GDB.
Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
- 1998, 1999, 2000, 2001, 2004, 2005, 2007, 2008
+ 1998, 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
Modified from expread.y by the Department of Computer Science at the
during the process of parsing; the lower levels of the tree always
come first in the result. */
-#include <ctype.h>
-
#include "defs.h"
+#include <ctype.h>
+#include "arch-utils.h"
#include "gdb_string.h"
#include "symtab.h"
#include "gdbtypes.h"
strings with embedded null bytes, as is required for some languages.
Don't be fooled by the fact that the string is null byte terminated,
- this is strictly for the convenience of debugging gdb itself. Gdb
+ this is strictly for the convenience of debugging gdb itself.
Gdb does not depend up the string being null terminated, since the
actual length is recorded in expression elements at each end of the
string. The null byte is taken into consideration when computing how
write_exp_elt_longcst ((LONGEST) len);
}
+/* Add a vector of string constants to the end of the expression.
+
+ This adds an OP_STRING operation, but encodes the contents
+ differently from write_exp_string. The language is expected to
+ handle evaluation of this expression itself.
+
+ After the usual OP_STRING header, TYPE is written into the
+ expression as a long constant. The interpretation of this field is
+ up to the language evaluator.
+
+ Next, each string in VEC is written. The length is written as a
+ long constant, followed by the contents of the string. */
+
+void
+write_exp_string_vector (int type, struct stoken_vector *vec)
+{
+ int i, n_slots, len;
+
+ /* Compute the size. We compute the size in number of slots to
+ avoid issues with string padding. */
+ n_slots = 0;
+ for (i = 0; i < vec->len; ++i)
+ {
+ /* One slot for the length of this element, plus the number of
+ slots needed for this string. */
+ n_slots += 1 + BYTES_TO_EXP_ELEM (vec->tokens[i].length);
+ }
+
+ /* One more slot for the type of the string. */
+ ++n_slots;
+
+ /* Now compute a phony string length. */
+ len = EXP_ELEM_TO_BYTES (n_slots) - 1;
+
+ n_slots += 4;
+ if ((expout_ptr + n_slots) >= expout_size)
+ {
+ expout_size = max (expout_size * 2, expout_ptr + n_slots + 10);
+ expout = (struct expression *)
+ xrealloc ((char *) expout, (sizeof (struct expression)
+ + EXP_ELEM_TO_BYTES (expout_size)));
+ }
+
+ write_exp_elt_opcode (OP_STRING);
+ write_exp_elt_longcst (len);
+ write_exp_elt_longcst (type);
+
+ for (i = 0; i < vec->len; ++i)
+ {
+ write_exp_elt_longcst (vec->tokens[i].length);
+ memcpy (&expout->elts[expout_ptr], vec->tokens[i].ptr,
+ vec->tokens[i].length);
+ expout_ptr += BYTES_TO_EXP_ELEM (vec->tokens[i].length);
+ }
+
+ write_exp_elt_longcst (len);
+ write_exp_elt_opcode (OP_STRING);
+}
+
/* Add a bitstring constant to the end of the expression.
Bitstring constants are stored by first writing an expression element
write_exp_elt_opcode (OP_LONG);
/* Let's make the type big enough to hold a 64-bit address. */
- write_exp_elt_type (builtin_type (gdbarch)->builtin_core_addr);
+ write_exp_elt_type (objfile_type (objfile)->builtin_core_addr);
write_exp_elt_longcst ((LONGEST) addr);
write_exp_elt_opcode (OP_LONG);
{
write_exp_elt_opcode (UNOP_MEMVAL_TLS);
write_exp_elt_objfile (objfile);
- write_exp_elt_type (builtin_type (gdbarch)->nodebug_tls_symbol);
+ write_exp_elt_type (objfile_type (objfile)->nodebug_tls_symbol);
write_exp_elt_opcode (UNOP_MEMVAL_TLS);
return;
}
case mst_text:
case mst_file_text:
case mst_solib_trampoline:
- write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol);
+ write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
break;
case mst_data:
case mst_file_data:
case mst_bss:
case mst_file_bss:
- write_exp_elt_type (builtin_type (gdbarch)->nodebug_data_symbol);
+ write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol);
break;
default:
- write_exp_elt_type (builtin_type (gdbarch)->nodebug_unknown_symbol);
+ write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol);
break;
}
write_exp_elt_opcode (UNOP_MEMVAL);
/* Handle tokens that refer to machine registers:
$ followed by a register name. */
- i = user_reg_map_name_to_regnum (current_gdbarch,
+ i = user_reg_map_name_to_regnum (parse_gdbarch,
str.ptr + 1, str.length - 1);
if (i >= 0)
goto handle_register;
args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
break;
+ case TYPE_INSTANCE:
+ oplen = 4 + longest_to_int (expr->elts[endpos - 2].longconst);
+ args = 1;
+ break;
+
case OP_OBJC_MSGCALL: /* Objective C message (method) call */
oplen = 4;
args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
case BINOP_VAL:
case UNOP_CAST:
+ case UNOP_DYNAMIC_CAST:
+ case UNOP_REINTERPRET_CAST:
case UNOP_MEMVAL:
oplen = 3;
args = 1;
expout = (struct expression *)
xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size));
expout->language_defn = current_language;
- expout->gdbarch = current_gdbarch;
+ expout->gdbarch = get_current_arch ();
TRY_CATCH (except, RETURN_MASK_ALL)
{
/* Parse STRING as an expression. If parsing ends in the middle of a
field reference, return the type of the left-hand-side of the
reference; furthermore, if the parsing ends in the field name,
- return the field name in *NAME. In all other cases, return NULL. */
+ return the field name in *NAME. In all other cases, return NULL.
+ Returned non-NULL *NAME must be freed by the caller. */
struct type *
parse_field_expression (char *string, char **name)
xfree (exp);
return NULL;
}
+ /* (*NAME) is a part of the EXP memory block freed below. */
+ *name = xstrdup (*name);
+
val = evaluate_subexpression_type (exp, subexp);
xfree (exp);
void
push_type_address_space (char *string)
{
- push_type_int (address_space_name_to_int (string));
+ push_type_int (address_space_name_to_int (parse_gdbarch, string));
}
enum type_pieces
int make_volatile = 0;
int make_addr_space = 0;
int array_size;
- struct type *range_type;
while (!done)
switch (pop_type ())
array_size = pop_type_int ();
/* FIXME-type-allocation: need a way to free this type when we are
done with it. */
- range_type =
- create_range_type ((struct type *) NULL,
- builtin_type_int32, 0,
- array_size >= 0 ? array_size - 1 : 0);
follow_type =
- create_array_type ((struct type *) NULL,
- follow_type, range_type);
+ lookup_array_range_type (follow_type,
+ 0, array_size >= 0 ? array_size - 1 : 0);
if (array_size < 0)
- TYPE_ARRAY_UPPER_BOUND_TYPE (follow_type)
- = BOUND_CANNOT_BE_DETERMINED;
+ TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (follow_type) = 1;
break;
case tp_function:
/* FIXME-type-allocation: need a way to free this type when we are