[PATCH] gdb: allow specifying multiple filters when running selftests
Simon Marchi
simon.marchi@polymtl.ca
Thu Aug 13 15:01:52 GMT 2020
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
More information about the Gdb-patches
mailing list