gdb: add gdb_argv::as_array_view method

Introduce the gdb_argv::as_array_view method, as a way to easily pass
the parsed arguments array to a function taking an array view.  There is
currently one caller where we can use this (which prompted the
suggestion to implement this method).

Add some selftests for the new method, which at the same time test a
little bit gdb_argv.  As far as I know, it's not tested currently.

gdb/ChangeLog:

	* 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.

Change-Id: I0645037613ed6549aabe60f14a36f3494513b177
This commit is contained in:
Simon Marchi
2020-08-14 12:27:22 -04:00
committed by Simon Marchi
parent 19bddbe95c
commit d369b608a1
4 changed files with 42 additions and 1 deletions

View File

@ -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
}