public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Improve constraints on gdb::array_view::array_view
@ 2021-10-20 20:05 Lancelot SIX
  2021-10-20 20:05 ` [PATCH 1/2] Add a const version of gdb_argv:as_array_view Lancelot SIX
  2021-10-20 20:05 ` [PATCH 2/2] Improve gdb::array_view ctor from contiguous containers Lancelot SIX
  0 siblings, 2 replies; 14+ messages in thread
From: Lancelot SIX @ 2021-10-20 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Lancelot SIX

Hi,

Wile reading around, I realized that the gdb::array_view interface has a
potential of being miss-used.  No worry, it is not miss-used in practice
in the current codebase, but fixing this might save debugging time in
the future.

It is possible to create a gdb::array_view<T> to refer to data inside a
std::vector<U> (or any contiguous container of U) if a U* is convertible
to a T*.  If U is a class that inherits from T this condition holds but
U and T most likely do not have the same memory layout. In such
situation the array_view will get it wrong (the second patch gives an
example of a miss-use of a gdb::array_view).

In this series I propose to change slightly the requirements on the
gdb::array_view::array_view constructor so this scenario cannot
compile.  No change is expected from this series.

The first patch just adds a const version of gdb_argv::as_array_view that
will be used in the second patch.  The second patch implements the
change on the gdb::array_view and makes minor adjustments so everything
still compiles.

All feedback are welcome.

Best,
Lancelot.

P.S.  Since I started this series, Simon Marchi have sent another series
dealing with array_view[1].  I have applied this series on top of mine
and check that everything still compiles.

[1] https://sourceware.org/pipermail/gdb-patches/2021-October/182657.html

Lancelot SIX (2):
  Add a const version of gdb_argv:as_array_view
  Improve gdb::array_view ctor from contiguous containers

 gdb/dwarf2/read.c       |  2 +-
 gdb/maint.c             |  2 +-
 gdb/utils.h             | 10 ++++++++++
 gdbsupport/array-view.h |  7 ++++---
 4 files changed, 16 insertions(+), 5 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-11-09 22:48 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20 20:05 [PATCH 0/2] Improve constraints on gdb::array_view::array_view Lancelot SIX
2021-10-20 20:05 ` [PATCH 1/2] Add a const version of gdb_argv:as_array_view Lancelot SIX
2021-10-30  2:03   ` Simon Marchi
2021-10-20 20:05 ` [PATCH 2/2] Improve gdb::array_view ctor from contiguous containers Lancelot SIX
2021-10-30  2:09   ` Simon Marchi
2021-11-02 14:10     ` Tom Tromey
2021-11-02 16:00   ` Pedro Alves
2021-11-02 22:51     ` Lancelot SIX
2021-11-03 22:20     ` [PATCH v2 " Lancelot SIX
2021-11-04 13:04       ` Pedro Alves
2021-11-08 23:02         ` Lancelot SIX
2021-11-09 17:52           ` [PATCH] gdb::array_view slicing/container selftest - test std::array too (Re: [PATCH v2 2/2] Improve gdb::array_view ctor from contiguous containers) Pedro Alves
2021-11-09 21:58             ` Lancelot SIX
2021-11-09 22:48               ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).