From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55145 invoked by alias); 18 Aug 2017 08:16:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 55124 invoked by uid 89); 18 Aug 2017 08:16:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=16,9 X-HELO: mail-it0-f67.google.com Received: from mail-it0-f67.google.com (HELO mail-it0-f67.google.com) (209.85.214.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Aug 2017 08:16:44 +0000 Received: by mail-it0-f67.google.com with SMTP id f16so5563798itb.5 for ; Fri, 18 Aug 2017 01:16:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=/WTydIY/mmjB3uQKtjbfVViwYPeKUrfVyMndd1oIFvs=; b=rNCPkJyNUujPMx8z1+ACrxLmss2f9f0ltDi6f22N/4Ct/wxrM/eSbj33nEsZjmjQkA wt+q3NC09Gc2oJMNAv/qDn+tF9Qiv3ykSqoR+v/qGMq16jkaqU534BGWQcIzgQENG/bK 5lej3LWkU9DKJZq1HJCtdJ7ceawRgTsAhyFSFQovtjlOsUOWQzeIxX75AmBRCUD+ulf5 vXAsWhkopFpPg7+O4LkZSCawlvn0Nce/dO9i6RRptT33nPoiOEo2FWRxcKdpDTv9hPqL jU5Xf20OFvvwnYKfH+05rNMmE0euzClGT3pRd+NZw2RNAT/d1dYUKjn+vU2nKAJHGtr/ SJdQ== X-Gm-Message-State: AHYfb5j+AWQAYTSDQDEPeQz0KgNsZl+lfVbYO+ELqinVrMjzVO57D/XA IzXGRyh1cX6xOYel X-Received: by 10.36.36.74 with SMTP id f71mr1178327ita.60.1503044202071; Fri, 18 Aug 2017 01:16:42 -0700 (PDT) Received: from E107787-LIN (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id t123sm489483itb.18.2017.08.18.01.16.40 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 18 Aug 2017 01:16:41 -0700 (PDT) From: Yao Qi To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/3] GDBserver self tests References: <1502465408-24668-1-git-send-email-yao.qi@linaro.org> <1502465408-24668-4-git-send-email-yao.qi@linaro.org> <68a9119e-208e-a0d7-0733-12896b7fc20b@redhat.com> Date: Fri, 18 Aug 2017 08:16:00 -0000 In-Reply-To: <68a9119e-208e-a0d7-0733-12896b7fc20b@redhat.com> (Pedro Alves's message of "Fri, 11 Aug 2017 18:09:52 +0100") Message-ID: <86ziaxl28t.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00356.txt.bz2 Pedro Alves writes: >> 2017-05-26 Yao Qi >>=20 >> * gdb.server/unittest.exp: New. > > This is missing from the patch. > Added it back. >> +* New features in the GDB remote stub, GDBserver >> + >> + ** New "--selftest" command line option runs some GDBserver self >> + tests. These self tests are disabled in release. > > "disabled in release mode." or "disabled in releases." ? > The latter, "disabled in releases". >> @@ -3357,6 +3359,7 @@ gdbserver_usage (FILE *stream) >> " Options:\n" >> " vCont, Tthread, qC, qfThreadInfo and \= n" >> " threads (disable all threading packets).\n" >> + " --selftest Run self tests.\n" >> "\n" >> "For more information, consult the GDB manual (available as >> on-line \n" >> "info or a printed manual).\n"); > > > I wonder whether "gdbserver --help" should really advertise --selftests, > given it's a maintenance command and essentially does nothing in=20 > release mode. > I thought since "--selftests" is documented in gdb.texinfo, it is better to show it in the gdbserver usage. However, I agree that this is a maintenance command, don't have to mention it in "gdbserver --help". >> +@cindex @option{--selftest} >> +The @option{--wrapper} option runs the self tests in @code{gdbserver}: >> + > > Pasto: "--wrapper" should be "--selftest". Fixed. Patch below is what I pushed in. --=20 Yao (=E9=BD=90=E5=B0=A7) =46rom bf72c259134cc3a5cc7c8e22a679b3d5f0fe7ce7 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Wed, 9 Aug 2017 17:48:47 +0100 Subject: [PATCH] GDBserver self tests This patch uses GDB self test in GDBserver. The self tests are run if GDBserver is started with option --selftest. gdb: 2017-08-18 Yao Qi * NEWS: Mention GDBserver's new option "--selftest". * Makefile.in (SFILES): Remove selftest.c, add common/selftest.c. * selftest.c: Move it to common/selftest.c. * selftest.h: Move it to common/selftest.h. * selftest-arch.c (reset): New function. (tests_with_arch): Call reset. gdb/gdbserver: 2017-08-18 Yao Qi * Makefile.in (OBS): Add selftest.o. * configure.ac: AC_DEFINE GDB_SELF_TEST if $development. * configure, config.in: Re-generated. * server.c: Include common/sefltest.h. (captured_main): Handle option --selftest. gdb/testsuite: 2017-08-18 Yao Qi * gdb.server/unittest.exp: New. gdb/doc: 2017-08-18 Yao Qi * gdb.texinfo (Server): Document "--selftest". diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4a0f3e7..2581935 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2017-08-18 Yao Qi =20 + * NEWS: Mention GDBserver's new option "--selftest". + * Makefile.in (SFILES): Remove selftest.c, add common/selftest.c. + * selftest.c: Move it to common/selftest.c. + * selftest.h: Move it to common/selftest.h. + * selftest-arch.c (reset): New function. + (tests_with_arch): Call reset. + +2017-08-18 Yao Qi + * selftest.c (run_tests): Don't call QUIT. Call debug_printf instead of exception_fprintf and printf_filtered. =20 diff --git a/gdb/Makefile.in b/gdb/Makefile.in index c6e618a..85de646 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1178,7 +1178,6 @@ SFILES =3D \ reverse.c \ rust-exp.y \ rust-lang.c \ - selftest.c \ selftest-arch.c \ sentinel-frame.c \ ser-base.c \ @@ -1244,6 +1243,7 @@ SFILES =3D \ common/ptid.c \ common/rsp-low.c \ common/run-time-clock.c \ + common/selftest.c \ common/signals.c \ common/signals-state-save-restore.c \ common/vec.c \ diff --git a/gdb/NEWS b/gdb/NEWS index 341e934..4b0a956 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,14 +3,19 @@ =20 *** Changes since GDB 8.0 =20 -* On Unix systems, GDBserver now does globbing expansion and variable - substitution in inferior command line arguments. - - This is done by starting inferiors using a shell, like GDB does. - See "set startup-with-shell" in the user manual for how to disable - this from GDB when using "target extended-remote". When using - "target remote", you can disable the startup with shell by using the - new "--no-startup-with-shell" GDBserver command line option. +* New features in the GDB remote stub, GDBserver + + ** New "--selftest" command line option runs some GDBserver self + tests. These self tests are disabled in releases. + + ** On Unix systems, GDBserver now does globbing expansion and variable + substitution in inferior command line arguments. + + This is done by starting inferiors using a shell, like GDB does. + See "set startup-with-shell" in the user manual for how to disable + this from GDB when using "target extended-remote". When using + "target remote", you can disable the startup with shell by using the + new "--no-startup-with-shell" GDBserver command line option. =20 * New remote packets =20 diff --git a/gdb/selftest.c b/gdb/common/selftest.c similarity index 92% rename from gdb/selftest.c rename to gdb/common/selftest.c index eb7728b..0fb8f2a 100644 --- a/gdb/selftest.c +++ b/gdb/common/selftest.c @@ -16,7 +16,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . = */ =20 -#include "defs.h" +#include "common-defs.h" +#include "common-exceptions.h" +#include "common-debug.h" #include "selftest.h" #include =20 @@ -55,9 +57,7 @@ run_tests (void) } END_CATCH =20 - /* Clear GDB internal state. */ - registers_changed (); - reinit_frame_cache (); + reset (); } =20 debug_printf ("Ran %lu unit tests, %d failed\n", diff --git a/gdb/selftest.h b/gdb/common/selftest.h similarity index 95% rename from gdb/selftest.h rename to gdb/common/selftest.h index 8a01a5d..e211c34 100644 --- a/gdb/selftest.h +++ b/gdb/common/selftest.h @@ -36,6 +36,9 @@ extern void register_test (self_test_function *function); =20 extern void run_tests (void); =20 +/* Reset GDB or GDBserver's internal state. */ +extern void reset (); + } =20 /* Check that VALUE is true, and, if not, throw an exception. */ diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 8e3e5ce..32c9425 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2017-08-18 Yao Qi + + * gdb.texinfo (Server): Document "--selftest". + 2017-08-16 Ruslan Kabatsayev =20 * gdb.texinfo (TUI Single Key Mode): Document the new shortcuts in diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 0d39a55..620d11d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20253,6 +20253,15 @@ environment: $ gdbserver --wrapper env LD_PRELOAD=3Dlibtest.so -- :2222 ./testprog @end smallexample =20 +@cindex @option{--selftest} +The @option{--selftest} option runs the self tests in @code{gdbserver}: + +@smallexample +$ gdbserver --selftest +Ran 2 unit tests, 0 failed +@end smallexample + +These tests are disabled in release. @subsection Connecting to @code{gdbserver} =20 The basic procedure for connecting to the remote target is: diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 0059b91..04dac06 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,11 @@ +2017-08-18 Yao Qi + + * Makefile.in (OBS): Add selftest.o. + * configure.ac: AC_DEFINE GDB_SELF_TEST if $development. + * configure, config.in: Re-generated. + * server.c: Include common/sefltest.h. + (captured_main): Handle option --selftest. + 2017-08-09 Yao Qi =20 * configure.srv (srv_i386_regobj): Remove i386-avx.o, diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index 4e0080e..6cd0959 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -258,6 +258,7 @@ OBS =3D \ regcache.o \ remote-utils.o \ rsp-low.o \ + selftest.o \ server.o \ signals.o \ signals-state-save-restore.o \ diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in index 34a7443..5dacbac 100644 --- a/gdb/gdbserver/config.in +++ b/gdb/gdbserver/config.in @@ -8,6 +8,9 @@ /* Define to 1 if using `alloca.c'. */ #undef C_ALLOCA =20 +/* Define if self-testing features should be enabled */ +#undef GDB_SELF_TEST + /* Define to 1 if you have `alloca', as a function or macro. */ #undef HAVE_ALLOCA =20 diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure index 35aeabc..30aa95b 100755 --- a/gdb/gdbserver/configure +++ b/gdb/gdbserver/configure @@ -5813,6 +5813,12 @@ fi fi =20 =20 +if $development; then + +$as_echo "#define GDB_SELF_TEST 1" >>confdefs.h + +fi + case ${build_alias} in "") build_noncanonical=3D${build} ;; *) build_noncanonical=3D${build_alias} ;; diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac index 4ea7913..36e21c5 100644 --- a/gdb/gdbserver/configure.ac +++ b/gdb/gdbserver/configure.ac @@ -56,6 +56,11 @@ else fi GDB_AC_LIBMCHECK(${libmcheck_default}) =20 +if $development; then + AC_DEFINE(GDB_SELF_TEST, 1, + [Define if self-testing features should be enabled]) +fi + ACX_NONCANONICAL_TARGET ACX_NONCANONICAL_HOST =20 diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 3838351..8200aa1 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -40,6 +40,8 @@ #include "job-control.h" #include "environ.h" =20 +#include "common/selftest.h" + /* The environment to pass to the inferior when creating it. */ =20 static gdb_environ our_environ; @@ -3521,6 +3523,7 @@ captured_main (int argc, char *argv[]) volatile int multi_mode =3D 0; volatile int attach =3D 0; int was_running; + bool selftest =3D false; =20 while (*next_arg !=3D NULL && **next_arg =3D=3D '-') { @@ -3639,6 +3642,8 @@ captured_main (int argc, char *argv[]) startup_with_shell =3D false; else if (strcmp (*next_arg, "--once") =3D=3D 0) run_once =3D 1; + else if (strcmp (*next_arg, "--selftest") =3D=3D 0) + selftest =3D true; else { fprintf (stderr, "Unknown argument: %s\n", *next_arg); @@ -3654,7 +3659,8 @@ captured_main (int argc, char *argv[]) port =3D *next_arg; next_arg++; } - if (port =3D=3D NULL || (!attach && !multi_mode && *next_arg =3D=3D NULL= )) + if ((port =3D=3D NULL || (!attach && !multi_mode && *next_arg =3D=3D NUL= L)) + && !selftest) { gdbserver_usage (stderr); exit (1); @@ -3670,7 +3676,8 @@ captured_main (int argc, char *argv[]) starting the inferior. Inferiors created in this scenario have stdin,stdout redirected. So do this here before we call start_inferior. */ - remote_prepare (port); + if (port !=3D NULL) + remote_prepare (port); =20 bad_attach =3D 0; pid =3D 0; @@ -3711,6 +3718,12 @@ captured_main (int argc, char *argv[]) own_buf =3D (char *) xmalloc (PBUFSIZ + 1); mem_buf =3D (unsigned char *) xmalloc (PBUFSIZ); =20 + if (selftest) + { + selftests::run_tests (); + throw_quit ("Quit"); + } + if (pid =3D=3D 0 && *next_arg !=3D NULL) { int i, n; @@ -4507,3 +4520,14 @@ handle_target_event (int err, gdb_client_data client= _data) =20 return 0; } + +#if GDB_SELF_TEST +namespace selftests +{ + +void +reset () +{} + +} // namespace selftests +#endif /* GDB_SELF_TEST */ diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c index dfcbe27..9a19f76 100644 --- a/gdb/selftest-arch.c +++ b/gdb/selftest-arch.c @@ -33,6 +33,14 @@ register_test_foreach_arch (self_test_foreach_arch_funct= ion *function) gdbarch_tests.push_back (function); } =20 +void +reset () +{ + /* Clear GDB internal state. */ + registers_changed (); + reinit_frame_cache (); +} + static void tests_with_arch () { @@ -82,9 +90,7 @@ tests_with_arch () } END_CATCH =20 - /* Clear GDB internal state. */ - registers_changed (); - reinit_frame_cache (); + reset (); } } =20 diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 39c49b8..d188f83 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-08-18 Yao Qi + + * gdb.server/unittest.exp: New. + 2017-08-15 Sergio Durigan Junior =20 PR gdb/21954 diff --git a/gdb/testsuite/gdb.server/unittest.exp b/gdb/testsuite/gdb.serv= er/unittest.exp new file mode 100644 index 0000000..584a23d --- /dev/null +++ b/gdb/testsuite/gdb.server/unittest.exp @@ -0,0 +1,41 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib gdbserver-support.exp + +standard_testfile + +if { [skip_gdbserver_tests] } { + return 0 +} + +global server_spawn_id + +set gdbserver [find_gdbserver] +set gdbserver_command "$gdbserver --selftest" + +set server_spawn_id [remote_spawn target $gdbserver_command] + +gdb_expect { + -i $server_spawn_id + -re "Ran $decimal unit tests, 0 failed" { + pass "unit tests" + } + default { + fail "unit tests" + } +}