This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Handle reference types in agent expressions
- From: Stan Shebs <stan at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 29 Dec 2009 16:00:18 -0800
- Subject: [PATCH] Handle reference types in agent expressions
Another beefing-up of C++ support in tracepoint agent expressions -
reference types. At this level in GDB they are basically identical to
pointers, and in fact there was a long-commented-out routine in
language.c that's perfect for the task! Committed to trunk.
Stan
2009-12-29 Stan Shebs <stan@codesourcery.com>
* language.c (pointer_type): Un-comment out.
* ax-gdb.c: Include language.h, use pointer_type throughout
instead of testing TYPE_CODE_PTR.
(gen_fetch): Include TYPE_CODE_REF.
(gen_cast): Ditto.
Index: ax-gdb.c
===================================================================
RCS file: /cvs/src/src/gdb/ax-gdb.c,v
retrieving revision 1.58
diff -p -r1.58 ax-gdb.c
*** ax-gdb.c 29 Dec 2009 23:21:38 -0000 1.58
--- ax-gdb.c 29 Dec 2009 23:28:34 -0000
***************
*** 22,27 ****
--- 22,28 ----
#include "symtab.h"
#include "symfile.h"
#include "gdbtypes.h"
+ #include "language.h"
#include "value.h"
#include "expression.h"
#include "command.h"
*************** gen_fetch (struct agent_expr *ax, struct
*** 401,406 ****
--- 402,408 ----
switch (TYPE_CODE (type))
{
case TYPE_CODE_PTR:
+ case TYPE_CODE_REF:
case TYPE_CODE_ENUM:
case TYPE_CODE_INT:
case TYPE_CODE_CHAR:
*************** gen_cast (struct agent_expr *ax, struct
*** 901,906 ****
--- 903,909 ----
switch (TYPE_CODE (type))
{
case TYPE_CODE_PTR:
+ case TYPE_CODE_REF:
/* It's implementation-defined, and I'll bet this is what GCC
does. */
break;
*************** static void
*** 961,967 ****
gen_ptradd (struct agent_expr *ax, struct axs_value *value,
struct axs_value *value1, struct axs_value *value2)
{
! gdb_assert (TYPE_CODE (value1->type) == TYPE_CODE_PTR);
gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
gen_scale (ax, aop_mul, value1->type);
--- 964,970 ----
gen_ptradd (struct agent_expr *ax, struct axs_value *value,
struct axs_value *value1, struct axs_value *value2)
{
! gdb_assert (pointer_type (value1->type));
gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
gen_scale (ax, aop_mul, value1->type);
*************** static void
*** 977,983 ****
gen_ptrsub (struct agent_expr *ax, struct axs_value *value,
struct axs_value *value1, struct axs_value *value2)
{
! gdb_assert (TYPE_CODE (value1->type) == TYPE_CODE_PTR);
gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
gen_scale (ax, aop_mul, value1->type);
--- 980,986 ----
gen_ptrsub (struct agent_expr *ax, struct axs_value *value,
struct axs_value *value1, struct axs_value *value2)
{
! gdb_assert (pointer_type (value1->type));
gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
gen_scale (ax, aop_mul, value1->type);
*************** gen_ptrdiff (struct agent_expr *ax, stru
*** 994,1001 ****
struct axs_value *value1, struct axs_value *value2,
struct type *result_type)
{
! gdb_assert (TYPE_CODE (value1->type) == TYPE_CODE_PTR);
! gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_PTR);
if (TYPE_LENGTH (TYPE_TARGET_TYPE (value1->type))
!= TYPE_LENGTH (TYPE_TARGET_TYPE (value2->type)))
--- 997,1004 ----
struct axs_value *value1, struct axs_value *value2,
struct type *result_type)
{
! gdb_assert (pointer_type (value1->type));
! gdb_assert (pointer_type (value2->type));
if (TYPE_LENGTH (TYPE_TARGET_TYPE (value1->type))
!= TYPE_LENGTH (TYPE_TARGET_TYPE (value2->type)))
*************** gen_deref (struct agent_expr *ax, struct
*** 1068,1074 ****
{
/* The caller should check the type, because several operators use
this, and we don't know what error message to generate. */
! if (TYPE_CODE (value->type) != TYPE_CODE_PTR)
internal_error (__FILE__, __LINE__,
_("gen_deref: expected a pointer"));
--- 1071,1077 ----
{
/* The caller should check the type, because several operators use
this, and we don't know what error message to generate. */
! if (!pointer_type (value->type))
internal_error (__FILE__, __LINE__,
_("gen_deref: expected a pointer"));
*************** gen_struct_ref (struct expression *exp,
*** 1327,1333 ****
/* Follow pointers until we reach a non-pointer. These aren't the C
semantics, but they're what the normal GDB evaluator does, so we
should at least be consistent. */
! while (TYPE_CODE (value->type) == TYPE_CODE_PTR)
{
require_rvalue (ax, value);
gen_deref (ax, value);
--- 1330,1336 ----
/* Follow pointers until we reach a non-pointer. These aren't the C
semantics, but they're what the normal GDB evaluator does, so we
should at least be consistent. */
! while (pointer_type (value->type))
{
require_rvalue (ax, value);
gen_deref (ax, value);
*************** gen_expr (struct expression *exp, union
*** 1753,1759 ****
(*pc)++;
gen_expr (exp, pc, ax, value);
gen_usual_unary (exp, ax, value);
! if (TYPE_CODE (value->type) != TYPE_CODE_PTR)
error (_("Argument of unary `*' is not a pointer."));
gen_deref (ax, value);
break;
--- 1756,1762 ----
(*pc)++;
gen_expr (exp, pc, ax, value);
gen_usual_unary (exp, ax, value);
! if (!pointer_type (value->type))
error (_("Argument of unary `*' is not a pointer."));
gen_deref (ax, value);
break;
*************** gen_expr_binop_rest (struct expression *
*** 1840,1852 ****
{
case BINOP_ADD:
if (TYPE_CODE (value1->type) == TYPE_CODE_INT
! && TYPE_CODE (value2->type) == TYPE_CODE_PTR)
{
/* Swap the values and proceed normally. */
ax_simple (ax, aop_swap);
gen_ptradd (ax, value, value2, value1);
}
! else if (TYPE_CODE (value1->type) == TYPE_CODE_PTR
&& TYPE_CODE (value2->type) == TYPE_CODE_INT)
gen_ptradd (ax, value, value1, value2);
else
--- 1843,1855 ----
{
case BINOP_ADD:
if (TYPE_CODE (value1->type) == TYPE_CODE_INT
! && pointer_type (value2->type))
{
/* Swap the values and proceed normally. */
ax_simple (ax, aop_swap);
gen_ptradd (ax, value, value2, value1);
}
! else if (pointer_type (value1->type)
&& TYPE_CODE (value2->type) == TYPE_CODE_INT)
gen_ptradd (ax, value, value1, value2);
else
*************** gen_expr_binop_rest (struct expression *
*** 1854,1864 ****
aop_add, aop_add, 1, "addition");
break;
case BINOP_SUB:
! if (TYPE_CODE (value1->type) == TYPE_CODE_PTR
&& TYPE_CODE (value2->type) == TYPE_CODE_INT)
gen_ptrsub (ax,value, value1, value2);
! else if (TYPE_CODE (value1->type) == TYPE_CODE_PTR
! && TYPE_CODE (value2->type) == TYPE_CODE_PTR)
/* FIXME --- result type should be ptrdiff_t */
gen_ptrdiff (ax, value, value1, value2,
builtin_type (exp->gdbarch)->builtin_long);
--- 1857,1867 ----
aop_add, aop_add, 1, "addition");
break;
case BINOP_SUB:
! if (pointer_type (value1->type)
&& TYPE_CODE (value2->type) == TYPE_CODE_INT)
gen_ptrsub (ax,value, value1, value2);
! else if (pointer_type (value1->type)
! && pointer_type (value2->type))
/* FIXME --- result type should be ptrdiff_t */
gen_ptrdiff (ax, value, value1, value2,
builtin_type (exp->gdbarch)->builtin_long);
*************** gen_expr_binop_rest (struct expression *
*** 1880,1886 ****
break;
case BINOP_SUBSCRIPT:
gen_ptradd (ax, value, value1, value2);
! if (TYPE_CODE (value->type) != TYPE_CODE_PTR)
error (_("Invalid combination of types in array subscripting."));
gen_deref (ax, value);
break;
--- 1883,1889 ----
break;
case BINOP_SUBSCRIPT:
gen_ptradd (ax, value, value1, value2);
! if (!pointer_type (value->type))
error (_("Invalid combination of types in array subscripting."));
gen_deref (ax, value);
break;
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.91
diff -p -r1.91 language.c
*** language.c 25 Sep 2009 21:39:52 -0000 1.91
--- language.c 29 Dec 2009 23:28:34 -0000
*************** float_type (struct type *type)
*** 696,701 ****
--- 696,702 ----
CHECK_TYPEDEF (type);
return TYPE_CODE (type) == TYPE_CODE_FLT;
}
+ #endif
/* Returns non-zero if the value is a pointer type */
int
*************** pointer_type (struct type *type)
*** 705,710 ****
--- 706,712 ----
TYPE_CODE (type) == TYPE_CODE_REF;
}
+ #if 0
/* Returns non-zero if the value is a structured type */
int
structured_type (struct type *type)