From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>,
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] gdb: allow specifying multiple filters when running selftests
Date: Thu, 13 Aug 2020 11:01:52 -0400 [thread overview]
Message-ID: <122366de-1378-ca30-4e95-3bcd45120018@polymtl.ca> (raw)
In-Reply-To: <878seihc75.fsf@tromey.com>
On 2020-08-13 10:06 a.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Simon> + selftests::run_tests (gdb::array_view<char *> (argv.get (), argv.count ()));
>
> I think it would be good to add a method to gdb_argv that returns an
> array view.
Hmm do you think it will happen often enough that we pass the parsed arguments straight to a
function taking an array view?
In any case, it's not difficult to do. Did you mean a simple method like the patch below, or
a conversion operator that could be implemented like this, to be able to transparently pass
a gdb_argv as an array_view?
using char_ptr_array_view = gdb::array_view<char *>;
operator char_ptr_array_view()
{
return gdb::array_view<char *> (this->get (), this->count ());
}
Personally I prefer things to be a bit more explicit, otherwise there's a bit too much hidden
magic.
From 79a9b29c1f08382ac790f2661fff55eade4d0174 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Thu, 13 Aug 2020 10:28:41 -0400
Subject: [PATCH] gdb: add gdb_argv::as_array_view method
Change-Id: I0645037613ed6549aabe60f14a36f3494513b177
---
gdb/maint.c | 2 +-
gdb/utils.c | 26 ++++++++++++++++++++++++++
gdb/utils.h | 8 ++++++++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/gdb/maint.c b/gdb/maint.c
index fd37acce5226..3368769ad96f 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1042,7 +1042,7 @@ maintenance_selftest (const char *args, int from_tty)
{
#if GDB_SELF_TEST
gdb_argv argv (args);
- selftests::run_tests (gdb::array_view<char *> (argv.get (), argv.count ()));
+ selftests::run_tests (argv.as_array_view ());
#else
printf_filtered (_("\
Selftests have been disabled for this build.\n"));
diff --git a/gdb/utils.c b/gdb/utils.c
index 102db28787fb..fb1308ac9ae3 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2991,6 +2991,31 @@ gdb_realpath_tests ()
gdb_realpath_check_trailer ("", "");
}
+/* Test the gdb_argv::as_array_view method. */
+
+static void
+gdb_argv_as_array_view_test ()
+{
+ {
+ gdb_argv argv;
+
+ gdb::array_view<char *> view = argv.as_array_view ();
+
+ SELF_CHECK (view.data () == nullptr);
+ SELF_CHECK (view.size () == 0);
+ }
+ {
+ gdb_argv argv ("une bonne 50");
+
+ gdb::array_view<char *> view = argv.as_array_view ();
+
+ SELF_CHECK (view.size () == 3);
+ SELF_CHECK (strcmp (view[0], "une") == 0);
+ SELF_CHECK (strcmp (view[1], "bonne") == 0);
+ SELF_CHECK (strcmp (view[2], "50") == 0);
+ }
+}
+
#endif /* GDB_SELF_TEST */
/* Allocation function for the libiberty hash table which uses an
@@ -3489,5 +3514,6 @@ When set, debugging messages will be marked with seconds and microseconds."),
#if GDB_SELF_TEST
selftests::register_test ("gdb_realpath", gdb_realpath_tests);
+ selftests::register_test ("gdb_argv_array_view", gdb_argv_as_array_view_test);
#endif
}
diff --git a/gdb/utils.h b/gdb/utils.h
index 3434ff1caa25..9a235b963272 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -22,6 +22,7 @@
#define UTILS_H
#include "exceptions.h"
+#include "gdbsupport/array-view.h"
#include "gdbsupport/scoped_restore.h"
#include <chrono>
@@ -210,6 +211,13 @@ class gdb_argv
return m_argv[arg];
}
+ /* Return the arguments array as an array view. */
+
+ gdb::array_view<char *> as_array_view ()
+ {
+ return gdb::array_view<char *> (this->get (), this->count ());
+ }
+
/* The iterator type. */
typedef char **iterator;
--
2.28.0
next prev parent reply other threads:[~2020-08-13 15:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-12 22:12 Simon Marchi
2020-08-13 1:46 ` Kevin Buettner
2020-08-13 12:06 ` Simon Marchi
2020-08-13 14:06 ` Tom Tromey
2020-08-13 15:01 ` Simon Marchi [this message]
2020-08-13 16:12 ` Tom Tromey
2020-08-13 22:24 ` [PATCH] gdb: add gdb_argv::as_array_view method Simon Marchi
2020-08-14 15:33 ` Tom Tromey
2020-08-14 16:33 ` 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=122366de-1378-ca30-4e95-3bcd45120018@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/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