aboutsummaryrefslogtreecommitdiff
path: root/gdb/value.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-04-04 16:34:33 -0600
committerTom Tromey <tom@tromey.com>2018-04-06 15:44:51 -0600
commit14c88955a138c24577e703d11f4d25c44a64d0be (patch)
tree6c1b275b72663c6b95436427ed9d0fc8ead1383c /gdb/value.c
parent0c7e6dd852f01b3ea38b98c39a2bb36280b02b55 (diff)
downloadgdb-14c88955a138c24577e703d11f4d25c44a64d0be.zip
gdb-14c88955a138c24577e703d11f4d25c44a64d0be.tar.gz
gdb-14c88955a138c24577e703d11f4d25c44a64d0be.tar.bz2
Change value::contents to be a unique_xmalloc_ptr
This changes value::contents to be a unique_xmalloc_ptr, removing a small bit of manual memory management. gdb/ChangeLog 2018-04-06 Tom Tromey <tom@tromey.com> * value.c (~value): Update. (struct value) <contents>: Now unique_xmalloc_ptr. (value_contents_bits_eq, allocate_value_contents) (value_contents_raw, value_contents_all_raw) (value_contents_for_printing, value_contents_for_printing_const) (set_value_enclosing_type): Update.
Diffstat (limited to 'gdb/value.c')
-rw-r--r--gdb/value.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/gdb/value.c b/gdb/value.c
index c30cedc..3d6595f 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -186,8 +186,6 @@ struct value
}
else if (VALUE_LVAL (this) == lval_xcallable)
delete location.xm_worker;
-
- xfree (contents);
}
DISABLE_COPY_AND_ASSIGN (value);
@@ -332,7 +330,7 @@ struct value
/* Actual contents of the value. Target byte-order. NULL or not
valid if lazy is nonzero. */
- gdb_byte *contents = nullptr;
+ gdb::unique_xmalloc_ptr<gdb_byte> contents;
/* Unavailable ranges in CONTENTS. We mark unavailable ranges,
rather than available, since the common and default case is for a
@@ -875,8 +873,8 @@ value_contents_bits_eq (const struct value *val1, int offset1,
}
/* Compare the available/valid contents. */
- if (memcmp_with_bit_offsets (val1->contents, offset1,
- val2->contents, offset2, l) != 0)
+ if (memcmp_with_bit_offsets (val1->contents.get (), offset1,
+ val2->contents.get (), offset2, l) != 0)
return false;
length -= h;
@@ -1012,8 +1010,8 @@ allocate_value_contents (struct value *val)
if (!val->contents)
{
check_type_length_before_alloc (val->enclosing_type);
- val->contents
- = (gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type));
+ val->contents.reset
+ ((gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type)));
}
}
@@ -1137,14 +1135,14 @@ value_contents_raw (struct value *value)
int unit_size = gdbarch_addressable_memory_unit_size (arch);
allocate_value_contents (value);
- return value->contents + value->embedded_offset * unit_size;
+ return value->contents.get () + value->embedded_offset * unit_size;
}
gdb_byte *
value_contents_all_raw (struct value *value)
{
allocate_value_contents (value);
- return value->contents;
+ return value->contents.get ();
}
struct type *
@@ -1227,14 +1225,14 @@ value_contents_for_printing (struct value *value)
{
if (value->lazy)
value_fetch_lazy (value);
- return value->contents;
+ return value->contents.get ();
}
const gdb_byte *
value_contents_for_printing_const (const struct value *value)
{
gdb_assert (!value->lazy);
- return value->contents;
+ return value->contents.get ();
}
const gdb_byte *
@@ -2877,7 +2875,8 @@ set_value_enclosing_type (struct value *val, struct type *new_encl_type)
{
check_type_length_before_alloc (new_encl_type);
val->contents
- = (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
+ .reset ((gdb_byte *) xrealloc (val->contents.release (),
+ TYPE_LENGTH (new_encl_type)));
}
val->enclosing_type = new_encl_type;