public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH 0/4] Add variant type
Date: Tue,  1 Feb 2022 09:07:13 -0500	[thread overview]
Message-ID: <20220201140717.3046952-1-simon.marchi@polymtl.ca> (raw)

I sometimes encounter situations where I think using std::variant would
be useful.  The benefits would be to be able to use non-POD types in the
alternatives, have them automatically constructed when making an
alternative active, and automatically destructing them when switching to
another alternative of destroying the variant.  Also, the validation of
access to the alternatives, to prevent accessing an alternative that is
not the current one.

However, std::variant is only available in C++17.  I suggest that we
import a variant implementation to allow us to use it right now, a bit
like we did for optional and string_view.  We could maybe import the
implementation from libstdc++, like we did for these last two types, but
that sounds really tedious (we would also want to import any tests).
Instead, we can take advantage of a popular implementation distributed
as a single header file.  I chose this one:

  https://github.com/martinmoene/variant-lite

because it is close to the std implementation, and the license (Boost
Software License) is clear and compatible with the GPL v3.

The first two patches of this series make minor adjustements.

The third patch adds the variant-lite header file, but does not use it
yet.

The fourth patch changes the internalval implementation to use a
variant, to show how it can be used, and so that we can discuss on how
we would like our usage of variant to look like.  This usage will then
probably be used as a template for future uses.

Simon Marchi (4):
  gdb: remove internalvar_funcs::destroy
  gdb: constify parameter of value_copy
  gdbsupport: add variant-lite
  gdb: make internalvar use a variant

 gdb/break-catch-throw.c        |    1 -
 gdb/inferior.c                 |    1 -
 gdb/infrun.c                   |    1 -
 gdb/probe.c                    |    1 -
 gdb/thread.c                   |    2 -
 gdb/tracepoint.c               |    1 -
 gdb/value.c                    |  352 ++--
 gdb/value.h                    |    8 +-
 gdb/windows-tdep.c             |    1 -
 gdbsupport/variant/README      |   11 +
 gdbsupport/variant/variant.hpp | 2742 ++++++++++++++++++++++++++++++++
 11 files changed, 2946 insertions(+), 175 deletions(-)
 create mode 100644 gdbsupport/variant/README
 create mode 100644 gdbsupport/variant/variant.hpp


base-commit: e327c35ef5768789d3ba41a629f178f5eec32790
-- 
2.34.1


             reply	other threads:[~2022-02-01 14:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 14:07 Simon Marchi [this message]
2022-02-01 14:07 ` [PATCH 1/4] gdb: remove internalvar_funcs::destroy Simon Marchi
2022-03-04 16:15   ` Tom Tromey
2022-03-06 16:33     ` Simon Marchi
2022-02-01 14:07 ` [PATCH 2/4] gdb: constify parameter of value_copy Simon Marchi
2022-03-04 16:16   ` Tom Tromey
2022-03-06 16:33     ` Simon Marchi
2022-02-01 14:07 ` [PATCH 3/4] gdbsupport: add variant-lite header Simon Marchi
2022-02-01 14:07 ` [PATCH 4/4] gdb: make internalvar use a variant Simon Marchi
2022-03-04 16:23   ` Tom Tromey
2022-03-07 12:12     ` Pedro Alves
2022-03-16  2:06       ` Simon Marchi
2022-03-16 13:26         ` Pedro Alves
2022-03-16 13:28           ` Simon Marchi
2022-02-03  0:02 ` [PATCH 0/4] Add variant type Andrew Burgess
2022-02-03  1:32   ` Simon Marchi
2022-02-04 12:44     ` Andrew Burgess
2022-02-04 13:19       ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220201140717.3046952-1-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).