From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id ACA5F3861893 for ; Thu, 13 Aug 2020 15:02:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ACA5F3861893 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 07DF23ZZ013811 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Aug 2020 11:02:08 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 07DF23ZZ013811 Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 351721E594; Thu, 13 Aug 2020 11:02:03 -0400 (EDT) Subject: Re: [PATCH] gdb: allow specifying multiple filters when running selftests To: Tom Tromey , Simon Marchi via Gdb-patches References: <20200812221245.69493-1-simon.marchi@polymtl.ca> <878seihc75.fsf@tromey.com> From: Simon Marchi Message-ID: <122366de-1378-ca30-4e95-3bcd45120018@polymtl.ca> Date: Thu, 13 Aug 2020 11:01:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <878seihc75.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 13 Aug 2020 15:02:03 +0000 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-DCC: : antispam2020.polymtl.ca 1102; Body=1 Fuz1=1 Fuz2=1 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Aug 2020 15:02:13 -0000 On 2020-08-13 10:06 a.m., Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches writes: > > Simon> + selftests::run_tests (gdb::array_view (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; operator char_ptr_array_view() { return gdb::array_view (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 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 (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 view = argv.as_array_view (); + + SELF_CHECK (view.data () == nullptr); + SELF_CHECK (view.size () == 0); + } + { + gdb_argv argv ("une bonne 50"); + + gdb::array_view 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 @@ -210,6 +211,13 @@ class gdb_argv return m_argv[arg]; } + /* Return the arguments array as an array view. */ + + gdb::array_view as_array_view () + { + return gdb::array_view (this->get (), this->count ()); + } + /* The iterator type. */ typedef char **iterator; -- 2.28.0