Use unique_xmalloc_ptr for read_string
This changes read_string's "buffer" out-parameter to be a unique_xmalloc_ptr, then updates the users. This allows for the removal of some cleanups. I chose unique_xmalloc_ptr rather than byte_vector here due to the way Guile unwinding seems to work. Tested by the buildbot. gdb/ChangeLog 2018-06-18 Tom Tromey <tom@tromey.com> * valprint.h (read_string): Update. * valprint.c (read_string): Change type of "buffer". (val_print_string): Update. * python/py-value.c (valpy_string): Update. * language.h (struct language_defn) <la_get_string>: Change type of "buffer". (default_get_string, c_get_string): Update. * language.c (default_get_string): Change type of "buffer". * guile/scm-value.c (gdbscm_value_to_string): Update. * c-lang.c (c_get_string): Change type of "buffer".
This commit is contained in:
parent
3f0dbd670b
commit
b4be9fadea
8 changed files with 64 additions and 55 deletions
13
gdb/c-lang.c
13
gdb/c-lang.c
|
@ -234,7 +234,7 @@ c_printstr (struct ui_file *stream, struct type *type,
|
|||
target charset. */
|
||||
|
||||
void
|
||||
c_get_string (struct value *value, gdb_byte **buffer,
|
||||
c_get_string (struct value *value, gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
|
||||
int *length, struct type **char_type,
|
||||
const char **charset)
|
||||
{
|
||||
|
@ -300,8 +300,8 @@ c_get_string (struct value *value, gdb_byte **buffer,
|
|||
/* I is now either a user-defined length, the number of non-null
|
||||
characters, or FETCHLIMIT. */
|
||||
*length = i * width;
|
||||
*buffer = (gdb_byte *) xmalloc (*length);
|
||||
memcpy (*buffer, contents, *length);
|
||||
buffer->reset ((gdb_byte *) xmalloc (*length));
|
||||
memcpy (buffer->get (), contents, *length);
|
||||
err = 0;
|
||||
}
|
||||
else
|
||||
|
@ -326,10 +326,7 @@ c_get_string (struct value *value, gdb_byte **buffer,
|
|||
err = read_string (addr, *length, width, fetchlimit,
|
||||
byte_order, buffer, length);
|
||||
if (err != 0)
|
||||
{
|
||||
xfree (*buffer);
|
||||
memory_error (TARGET_XFER_E_IO, addr);
|
||||
}
|
||||
memory_error (TARGET_XFER_E_IO, addr);
|
||||
}
|
||||
|
||||
/* If the LENGTH is specified at -1, we want to return the string
|
||||
|
@ -339,7 +336,7 @@ c_get_string (struct value *value, gdb_byte **buffer,
|
|||
if (req_length == -1)
|
||||
/* If the last character is null, subtract it from LENGTH. */
|
||||
if (*length > 0
|
||||
&& extract_unsigned_integer (*buffer + *length - width,
|
||||
&& extract_unsigned_integer (buffer->get () + *length - width,
|
||||
width, byte_order) == 0)
|
||||
*length -= width;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue