mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-18 16:53:50 +08:00
Turn allocate_value_contents into a method
This turns the static function allocate_value_contents into a method on value. It is temporarily public, until some users are converted. set_limited_array_length is converted as well. Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
52
gdb/value.c
52
gdb/value.c
@ -901,39 +901,35 @@ calculate_limited_array_length (struct type *array_type)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to limit ourselves to only fetching the limited number of
|
/* See value.h. */
|
||||||
elements. However, if this limited number of elements still
|
|
||||||
puts us over max_value_size, then we still refuse it and
|
|
||||||
return failure here, which will ultimately throw an error. */
|
|
||||||
|
|
||||||
static bool
|
bool
|
||||||
set_limited_array_length (struct value *val)
|
value::set_limited_array_length ()
|
||||||
{
|
{
|
||||||
ULONGEST limit = val->m_limited_length;
|
ULONGEST limit = m_limited_length;
|
||||||
ULONGEST len = val->type ()->length ();
|
ULONGEST len = type ()->length ();
|
||||||
|
|
||||||
if (array_length_limiting_element_count.has_value ())
|
if (array_length_limiting_element_count.has_value ())
|
||||||
len = calculate_limited_array_length (val->type ());
|
len = calculate_limited_array_length (type ());
|
||||||
|
|
||||||
if (limit != 0 && len > limit)
|
if (limit != 0 && len > limit)
|
||||||
len = limit;
|
len = limit;
|
||||||
if (len > max_value_size)
|
if (len > max_value_size)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
val->m_limited_length = max_value_size;
|
m_limited_length = max_value_size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate the contents of VAL if it has not been allocated yet.
|
/* See value.h. */
|
||||||
If CHECK_SIZE is true, then apply the usual max-value-size checks. */
|
|
||||||
|
|
||||||
static void
|
void
|
||||||
allocate_value_contents (struct value *val, bool check_size)
|
value::allocate_contents (bool check_size)
|
||||||
{
|
{
|
||||||
if (!val->m_contents)
|
if (!m_contents)
|
||||||
{
|
{
|
||||||
struct type *enclosing_type = val->enclosing_type ();
|
struct type *enc_type = enclosing_type ();
|
||||||
ULONGEST len = enclosing_type->length ();
|
ULONGEST len = enc_type->length ();
|
||||||
|
|
||||||
if (check_size)
|
if (check_size)
|
||||||
{
|
{
|
||||||
@ -942,16 +938,16 @@ allocate_value_contents (struct value *val, bool check_size)
|
|||||||
an element limit in effect, then we can possibly try
|
an element limit in effect, then we can possibly try
|
||||||
to load only a sub-set of the array contents into
|
to load only a sub-set of the array contents into
|
||||||
GDB's memory. */
|
GDB's memory. */
|
||||||
if (val->type () == enclosing_type
|
if (type () == enc_type
|
||||||
&& val->type ()->code () == TYPE_CODE_ARRAY
|
&& type ()->code () == TYPE_CODE_ARRAY
|
||||||
&& len > max_value_size
|
&& len > max_value_size
|
||||||
&& set_limited_array_length (val))
|
&& set_limited_array_length ())
|
||||||
len = val->m_limited_length;
|
len = m_limited_length;
|
||||||
else
|
else
|
||||||
check_type_length_before_alloc (enclosing_type);
|
check_type_length_before_alloc (enc_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
val->m_contents.reset ((gdb_byte *) xzalloc (len));
|
m_contents.reset ((gdb_byte *) xzalloc (len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -963,7 +959,7 @@ value::allocate (struct type *type, bool check_size)
|
|||||||
{
|
{
|
||||||
struct value *val = value::allocate_lazy (type);
|
struct value *val = value::allocate_lazy (type);
|
||||||
|
|
||||||
allocate_value_contents (val, check_size);
|
val->allocate_contents (check_size);
|
||||||
val->m_lazy = 0;
|
val->m_lazy = 0;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -1027,7 +1023,7 @@ value::contents_raw ()
|
|||||||
{
|
{
|
||||||
int unit_size = gdbarch_addressable_memory_unit_size (arch ());
|
int unit_size = gdbarch_addressable_memory_unit_size (arch ());
|
||||||
|
|
||||||
allocate_value_contents (this, true);
|
allocate_contents (true);
|
||||||
|
|
||||||
ULONGEST length = type ()->length ();
|
ULONGEST length = type ()->length ();
|
||||||
return gdb::make_array_view
|
return gdb::make_array_view
|
||||||
@ -1037,7 +1033,7 @@ value::contents_raw ()
|
|||||||
gdb::array_view<gdb_byte>
|
gdb::array_view<gdb_byte>
|
||||||
value::contents_all_raw ()
|
value::contents_all_raw ()
|
||||||
{
|
{
|
||||||
allocate_value_contents (this, true);
|
allocate_contents (true);
|
||||||
|
|
||||||
ULONGEST length = enclosing_type ()->length ();
|
ULONGEST length = enclosing_type ()->length ();
|
||||||
return gdb::make_array_view (m_contents.get (), length);
|
return gdb::make_array_view (m_contents.get (), length);
|
||||||
@ -1574,7 +1570,7 @@ value_copy (const value *arg)
|
|||||||
const auto &arg_view
|
const auto &arg_view
|
||||||
= gdb::make_array_view (arg->m_contents.get (), length);
|
= gdb::make_array_view (arg->m_contents.get (), length);
|
||||||
|
|
||||||
allocate_value_contents (val, false);
|
val->allocate_contents (false);
|
||||||
gdb::array_view<gdb_byte> val_contents
|
gdb::array_view<gdb_byte> val_contents
|
||||||
= val->contents_all_raw ().slice (0, length);
|
= val->contents_all_raw ().slice (0, length);
|
||||||
|
|
||||||
@ -3963,7 +3959,7 @@ void
|
|||||||
value::fetch_lazy ()
|
value::fetch_lazy ()
|
||||||
{
|
{
|
||||||
gdb_assert (lazy ());
|
gdb_assert (lazy ());
|
||||||
allocate_value_contents (this, true);
|
allocate_contents (true);
|
||||||
/* A value is either lazy, or fully fetched. The
|
/* A value is either lazy, or fully fetched. The
|
||||||
availability/validity is only established as we try to fetch a
|
availability/validity is only established as we try to fetch a
|
||||||
value. */
|
value. */
|
||||||
|
13
gdb/value.h
13
gdb/value.h
@ -586,6 +586,19 @@ private:
|
|||||||
|
|
||||||
/* Helper for fetch_lazy when the value is in a register. */
|
/* Helper for fetch_lazy when the value is in a register. */
|
||||||
void fetch_lazy_register ();
|
void fetch_lazy_register ();
|
||||||
|
|
||||||
|
/* Try to limit ourselves to only fetching the limited number of
|
||||||
|
elements. However, if this limited number of elements still
|
||||||
|
puts us over max_value_size, then we still refuse it and
|
||||||
|
return failure here, which will ultimately throw an error. */
|
||||||
|
bool set_limited_array_length ();
|
||||||
|
|
||||||
|
public: /* Temporary */
|
||||||
|
|
||||||
|
/* Allocate the contents of this value if it has not been allocated
|
||||||
|
yet. If CHECK_SIZE is true, then apply the usual max-value-size
|
||||||
|
checks. */
|
||||||
|
void allocate_contents (bool check_size);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Returns value_type or value_enclosing_type depending on
|
/* Returns value_type or value_enclosing_type depending on
|
||||||
|
Reference in New Issue
Block a user