forked from Imagelibrary/binutils-gdb
Implement 'Object_Size
This patch started as an attempt to allow the 'Size attribute to be applied to types, and not just objects. However, that turns out to be difficult due to the Ada semantcs of 'Size. In particular, Ada requires 'Size to denote the size of the representation of the value, so for example Boolean'Size must be 1. Implementing this properly requires information not readily available to gdb... and while we could synthesize this information in many cases, it also seemed to me that this wasn't strictly very useful when debugging. So instead, this patch adds support for the 'Object_Size attribute, which is somewhat closer to 'sizeof'. Note also that while 'Object_Size is defined for some dynamic types, I chose not to implement this here, as again this information is not readily available -- and I think it's preferable to error than to print something that might be incorrect. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This commit is contained in:
@@ -10101,15 +10101,28 @@ ada_atr_tag (struct type *expect_type,
|
||||
return ada_value_tag (arg1);
|
||||
}
|
||||
|
||||
/* A helper function for OP_ATR_SIZE. */
|
||||
namespace expr
|
||||
{
|
||||
|
||||
value *
|
||||
ada_atr_size (struct type *expect_type,
|
||||
struct expression *exp,
|
||||
enum noside noside, enum exp_opcode op,
|
||||
struct value *arg1)
|
||||
ada_atr_size_operation::evaluate (struct type *expect_type,
|
||||
struct expression *exp,
|
||||
enum noside noside)
|
||||
{
|
||||
struct type *type = arg1->type ();
|
||||
bool is_type = std::get<0> (m_storage)->opcode () == OP_TYPE;
|
||||
bool is_size = std::get<1> (m_storage);
|
||||
|
||||
enum noside sub_noside = is_type ? EVAL_AVOID_SIDE_EFFECTS : noside;
|
||||
value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, sub_noside);
|
||||
struct type *type = ada_check_typedef (val->type ());
|
||||
|
||||
if (is_type)
|
||||
{
|
||||
if (is_size)
|
||||
error (_("gdb cannot apply 'Size to a type"));
|
||||
if (is_dynamic_type (type) || find_base_type (type) != nullptr)
|
||||
error (_("cannot apply 'Object_Size to dynamic type"));
|
||||
}
|
||||
|
||||
/* If the argument is a reference, then dereference its type, since
|
||||
the user is really asking for the size of the actual object,
|
||||
@@ -10124,6 +10137,8 @@ ada_atr_size (struct type *expect_type,
|
||||
TARGET_CHAR_BIT * type->length ());
|
||||
}
|
||||
|
||||
} /* namespace expr */
|
||||
|
||||
/* A helper function for UNOP_ABS. */
|
||||
|
||||
value *
|
||||
|
||||
Reference in New Issue
Block a user