aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-valprint.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-10-04 20:47:06 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-10-25 14:51:44 -0400
commit50888e42dcd32b30e1144c0aa6d1c1490da45cd9 (patch)
tree72fad89d67057ecb53f26bac0464542829053e3e /gdb/ada-valprint.c
parentd9f82e931394efed68858eb7c7bb5832ad888482 (diff)
downloadgdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.zip
gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.gz
gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.bz2
gdb: change functions returning value contents to use gdb::array_view
The bug fixed by this [1] patch was caused by an out-of-bounds access to a value's content. The code gets the value's content (just a pointer) and then indexes it with a non-sensical index. This made me think of changing functions that return value contents to return array_views instead of a plain pointer. This has the advantage that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view are checked, making bugs more apparent / easier to find. This patch changes the return types of these functions, and updates callers to call .data() on the result, meaning it's not changing anything in practice. Additional work will be needed (which can be done little by little) to make callers propagate the use of array_view and reap the benefits. [1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
Diffstat (limited to 'gdb/ada-valprint.c')
-rw-r--r--gdb/ada-valprint.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index e725cd3..17cace0 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -747,7 +747,7 @@ ada_value_print_num (struct value *val, struct ui_file *stream, int recurse,
const struct value_print_options *options)
{
struct type *type = ada_check_typedef (value_type (val));
- const gdb_byte *valaddr = value_contents_for_printing (val);
+ const gdb_byte *valaddr = value_contents_for_printing (val).data ();
if (type->code () == TYPE_CODE_RANGE
&& (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ENUM
@@ -827,7 +827,7 @@ ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse,
}
struct type *type = ada_check_typedef (value_type (value));
- const gdb_byte *valaddr = value_contents_for_printing (value);
+ const gdb_byte *valaddr = value_contents_for_printing (value).data ();
int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
len = type->num_fields ();
@@ -895,7 +895,7 @@ ada_value_print_array (struct value *val, struct ui_file *stream, int recurse,
if (ada_is_string_type (type)
&& (options->format == 0 || options->format == 's'))
{
- const gdb_byte *valaddr = value_contents_for_printing (val);
+ const gdb_byte *valaddr = value_contents_for_printing (val).data ();
int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
ada_val_print_string (type, valaddr, offset_aligned, stream, recurse,
@@ -910,7 +910,7 @@ ada_value_print_array (struct value *val, struct ui_file *stream, int recurse,
val_print_optimized_out (val, stream);
else if (TYPE_FIELD_BITSIZE (type, 0) > 0)
{
- const gdb_byte *valaddr = value_contents_for_printing (val);
+ const gdb_byte *valaddr = value_contents_for_printing (val).data ();
int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
val_print_packed_array_elements (type, valaddr, offset_aligned,
stream, recurse, options);
@@ -1009,7 +1009,7 @@ ada_value_print_1 (struct value *val, struct ui_file *stream, int recurse,
type = value_type (val);
struct type *saved_type = type;
- const gdb_byte *valaddr = value_contents_for_printing (val);
+ const gdb_byte *valaddr = value_contents_for_printing (val).data ();
CORE_ADDR address = value_address (val);
gdb::array_view<const gdb_byte> view
= gdb::make_array_view (valaddr, TYPE_LENGTH (type));