aboutsummaryrefslogtreecommitdiff
path: root/gdb/value.h
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/value.h
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/value.h')
-rw-r--r--gdb/value.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/gdb/value.h b/gdb/value.h
index 4501237..aa10564 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -360,7 +360,7 @@ extern void error_value_optimized_out (void);
get to the real subobject, if the value happens to represent
something embedded in a larger run-time object. */
-extern gdb_byte *value_contents_raw (struct value *);
+extern gdb::array_view<gdb_byte> value_contents_raw (struct value *);
/* Actual contents of the value. For use of this value; setting it
uses the stuff above. Not valid if lazy is nonzero. Target
@@ -368,24 +368,24 @@ extern gdb_byte *value_contents_raw (struct value *);
value. Note that a value therefore extends beyond what is
declared here. */
-extern const gdb_byte *value_contents (struct value *);
-extern gdb_byte *value_contents_writeable (struct value *);
+extern gdb::array_view<const gdb_byte> value_contents (struct value *);
+extern gdb::array_view<gdb_byte> value_contents_writeable (struct value *);
/* The ALL variants of the above two macros do not adjust the returned
pointer by the embedded_offset value. */
-extern gdb_byte *value_contents_all_raw (struct value *);
-extern const gdb_byte *value_contents_all (struct value *);
+extern gdb::array_view<gdb_byte> value_contents_all_raw (struct value *);
+extern gdb::array_view<const gdb_byte> value_contents_all (struct value *);
/* Like value_contents_all, but does not require that the returned
bits be valid. This should only be used in situations where you
plan to check the validity manually. */
-extern const gdb_byte *value_contents_for_printing (struct value *value);
+extern gdb::array_view<const gdb_byte> value_contents_for_printing (struct value *value);
/* Like value_contents_for_printing, but accepts a constant value
pointer. Unlike value_contents_for_printing however, the pointed
value must _not_ be lazy. */
-extern const gdb_byte *
+extern gdb::array_view<const gdb_byte>
value_contents_for_printing_const (const struct value *value);
extern void value_fetch_lazy (struct value *val);