aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2020-08-14 12:27:22 -0400
committerSimon Marchi <simon.marchi@efficios.com>2020-08-14 12:27:22 -0400
commitd369b608a1fc84813762e71a40a6cafb3ab828fe (patch)
tree65ec08506192d4cc54c9f49b11a7243b66863457 /gdb
parent19bddbe95c156a4883213a57d4437b75318b6875 (diff)
downloadgdb-d369b608a1fc84813762e71a40a6cafb3ab828fe.zip
gdb-d369b608a1fc84813762e71a40a6cafb3ab828fe.tar.gz
gdb-d369b608a1fc84813762e71a40a6cafb3ab828fe.tar.bz2
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
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/maint.c2
-rw-r--r--gdb/utils.c26
-rw-r--r--gdb/utils.h8
4 files changed, 42 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 038d117..63d1bab 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+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
diff --git a/gdb/maint.c b/gdb/maint.c
index fd37acc..3368769 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 102db28..fb1308a 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 3434ff1..9a235b9 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 @@ public:
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;