+2020-08-14  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * utils.h (class gdb_argv) <as_array_view>: New method.
+       * utils.c (gdb_argv_as_array_view_test): New.
+       (_initialize_utils): Register selftest.
+       * maint.c (maintenance_selftest): Use the new method.
+
 2020-08-13  Kamil Rytarowski  <n54@gmx.com>
 
        * target.h (supports_dumpcore, dumpcore): New
 
 {
 #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"));
 
   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
 
 #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
 }
 
 #define UTILS_H
 
 #include "exceptions.h"
+#include "gdbsupport/array-view.h"
 #include "gdbsupport/scoped_restore.h"
 #include <chrono>
 
     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;