[PATCH] Disallow non-scalars as rvalues in agent expressions

Stan Shebs
2010-03-18T05:00:35Z

[-- Attachment #1: Type: text/plain, Size: 759 bytes --]

Bad Stuff(tm) happens when you try to compile an agent expression that
wants to use a non-scalar object like a struct. (We're talking about
the struct itself, not a pointer to it.) Now, it actually works in GDB
to say "print (int)bigstruct" - the first 32 bits of the struct get made
into an integer, and the rest is discarded. While in theory the
bytecode compiler could do likewise, and perhaps someone will make that
happen someday (it's not as simple as taking address, struct might be
partly in registers), in the meantime we need to prevent non-scalar
types from triggering internal errors all over the place. Committed to
trunk.

Stan

2010-03-17 Stan Shebs <stan@codesourcery.com>

* ax-gdb.c (require_rvalue): Disallow non-scalars.

[-- Attachment #2: nonscalar-patch-1 --]
[-- Type: text/plain, Size: 908 bytes --]

Index: ax-gdb.c
===================================================================
RCS file: /cvs/src/src/gdb/ax-gdb.c,v
retrieving revision 1.69
diff -p -r1.69 ax-gdb.c
*** ax-gdb.c 17 Mar 2010 22:04:43 -0000 1.69
--- ax-gdb.c 18 Mar 2010 01:44:44 -0000
*************** gen_int_literal (struct agent_expr *ax,
*** 745,750 ****
--- 745,759 ----
static void
require_rvalue (struct agent_expr *ax, struct axs_value *value)
{
+ /* Only deal with scalars, structs and such may be too large
+ to fit in a stack entry. */
+ value->type = check_typedef (value->type);
+ if (TYPE_CODE (value->type) == TYPE_CODE_ARRAY
+ || TYPE_CODE (value->type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (value->type) == TYPE_CODE_UNION
+ || TYPE_CODE (value->type) == TYPE_CODE_FUNC)
+ error ("Value not scalar: cannot be an rvalue.");
+
switch (value->kind)
{