From patchwork Mon Jul 10 13:55:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 21504 Received: (qmail 33359 invoked by alias); 10 Jul 2017 13:56:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 33038 invoked by uid 89); 10 Jul 2017 13:56:08 -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=sk:server, obs, 2222, 12437 X-HELO: mail-it0-f45.google.com Received: from mail-it0-f45.google.com (HELO mail-it0-f45.google.com) (209.85.214.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Jul 2017 13:56:01 +0000 Received: by mail-it0-f45.google.com with SMTP id k192so39433245ith.1 for ; Mon, 10 Jul 2017 06:56:01 -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:subject:date:message-id:in-reply-to :references; bh=5BKdP5iqJetluFMdpyaTmFpWmM7wNK+0BxQILFwsIuM=; b=UsArJs1kwedEzANGCLBmZBCbvyAf2VPLoOIT3rX7m4pxL6Te8j2NfQSC7ZYRjT13on hdmBmsJdGWBmJPnPE6W4pwqU4EIeehBuQtG3Qo4HrvhLL5WLedaNVdDaBJPqjSUoeT/L Aychr7ojPno4FsOKaUgYua0Zi5X/8OY56ZajNwF08nMcYBKC1LqtyrVnVHA215soH23o L0fR/7z4zd6RMtGOUHu+RxL3GarmRgr678RgFfAfNfkjdpA2r+okC/6+tVRrZPt9E9xp YMdRXvpiJYJluNe5D/hTwkAjjrEgOZuMJDL4w9IaUy5UoKjbq7lB5foKqfiA5nR4P71O EWGA== X-Gm-Message-State: AIVw113xb8A+zmftKoIdH7d3/Pp8EUob6pOeNtRTGSPeCd1pn521na3p BqeZ1QtDyZ+jKRNj X-Received: by 10.36.19.5 with SMTP id 5mr11376133itz.65.1499694959762; Mon, 10 Jul 2017 06:55:59 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id v96sm5973996ioi.50.2017.07.10.06.55.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jul 2017 06:55:59 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 13/26] GDBserver self test Date: Mon, 10 Jul 2017 14:55:27 +0100 Message-Id: <1499694940-23564-14-git-send-email-yao.qi@linaro.org> In-Reply-To: <1499694940-23564-1-git-send-email-yao.qi@linaro.org> References: <1499694940-23564-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch uses GDB self test in GDBserver. The self tests are run if GDBserver is started with option --selftest. We decide to still reuse GDB's selftest in GDBserver, so this patch moves selftest.{c,h} to common/, and use some #ifdef as few as I can. gdb: 2017-07-07 Yao Qi * NEWS: Mention GDBserver's new option "--selftest". * Makefile.in (SFILES): Remove selftest.c, add common/selftest.c. * selftest.c: Move it common/selftest.c. * selftest.h: Move it common/selftest.h. gdb/gdbserver: 2017-07-07 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. (gdbserver_usage): Print usage for "--selftest". gdb/testsuite: 2017-05-26 Yao Qi * gdb.server/unittest.exp: New. gdb/doc: 2017-07-07 Yao Qi * gdb.texinfo (Server): Document "--selftest". --- gdb/Makefile.in | 2 +- gdb/NEWS | 21 +++++++++++------- gdb/{ => common}/selftest.c | 17 ++++++++++++--- gdb/{ => common}/selftest.h | 0 gdb/doc/gdb.texinfo | 9 ++++++++ gdb/gdbserver/Makefile.in | 1 + gdb/gdbserver/config.in | 3 +++ gdb/gdbserver/configure | 6 +++++ gdb/gdbserver/configure.ac | 5 +++++ gdb/gdbserver/server.c | 18 +++++++++++++-- gdb/testsuite/gdb.server/unittest.exp | 41 +++++++++++++++++++++++++++++++++++ 11 files changed, 109 insertions(+), 14 deletions(-) rename gdb/{ => common}/selftest.c (82%) rename gdb/{ => common}/selftest.h (100%) create mode 100644 gdb/testsuite/gdb.server/unittest.exp diff --git a/gdb/Makefile.in b/gdb/Makefile.in index b27f698..ece7de9 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1178,7 +1178,6 @@ SFILES = \ reverse.c \ rust-exp.y \ rust-lang.c \ - selftest.c \ selftest-arch.c \ sentinel-frame.c \ ser-base.c \ @@ -1244,6 +1243,7 @@ SFILES = \ 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 9cd1df1..8fca378 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,14 +3,19 @@ *** Changes since GDB 8.0 -* 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 release. + + ** 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 remote packets diff --git a/gdb/selftest.c b/gdb/common/selftest.c similarity index 82% rename from gdb/selftest.c rename to gdb/common/selftest.c index 14b76f6..d9c7ab0 100644 --- a/gdb/selftest.c +++ b/gdb/common/selftest.c @@ -16,7 +16,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "defs.h" +#include "common-defs.h" +#ifdef GDBSERVER +#define QUIT do {} while (0) +#else +#include "defs.h" /* for QUIT */ +#endif +#include "common-exceptions.h" +#include "common-debug.h" #include "selftest.h" #include @@ -50,15 +57,19 @@ run_self_tests (void) CATCH (ex, RETURN_MASK_ERROR) { ++failed; +#ifndef GDBSERVER exception_fprintf (gdb_stderr, ex, _("Self test failed: ")); +#endif } END_CATCH +#ifndef GDBSERVER /* Clear GDB internal state. */ registers_changed (); reinit_frame_cache (); +#endif } - printf_filtered (_("Ran %lu unit tests, %d failed\n"), - (long) tests.size (), failed); + debug_printf ("Ran %lu unit tests, %d failed\n", + (long) tests.size (), failed); } diff --git a/gdb/selftest.h b/gdb/common/selftest.h similarity index 100% rename from gdb/selftest.h rename to gdb/common/selftest.h diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 17b4c69..e26287d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20253,6 +20253,15 @@ environment: $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog @end smallexample +@cindex @option{--selftest} +The @option{--wrapper} 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} The basic procedure for connecting to the remote target is: diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index 89f91aa..9b5982b 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -258,6 +258,7 @@ OBS = \ 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 +/* 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 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 +if $development; then + +$as_echo "#define GDB_SELF_TEST 1" >>confdefs.h + +fi + case ${build_alias} in "") build_noncanonical=${build} ;; *) build_noncanonical=${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}) +if $development; then + AC_DEFINE(GDB_SELF_TEST, 1, + [Define if self-testing features should be enabled]) +fi + ACX_NONCANONICAL_TARGET ACX_NONCANONICAL_HOST diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 3838351..4ca09dd 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -40,6 +40,8 @@ #include "job-control.h" #include "environ.h" +#include "common/selftest.h" + /* The environment to pass to the inferior when creating it. */ static gdb_environ our_environ; @@ -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"); @@ -3521,6 +3524,7 @@ captured_main (int argc, char *argv[]) volatile int multi_mode = 0; volatile int attach = 0; int was_running; + bool selftest = false; while (*next_arg != NULL && **next_arg == '-') { @@ -3639,6 +3643,8 @@ captured_main (int argc, char *argv[]) startup_with_shell = false; else if (strcmp (*next_arg, "--once") == 0) run_once = 1; + else if (strcmp (*next_arg, "--selftest") == 0) + selftest = true; else { fprintf (stderr, "Unknown argument: %s\n", *next_arg); @@ -3654,7 +3660,8 @@ captured_main (int argc, char *argv[]) port = *next_arg; next_arg++; } - if (port == NULL || (!attach && !multi_mode && *next_arg == NULL)) + if ((port == NULL || (!attach && !multi_mode && *next_arg == NULL)) + && !selftest) { gdbserver_usage (stderr); exit (1); @@ -3670,7 +3677,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 != NULL) + remote_prepare (port); bad_attach = 0; pid = 0; @@ -3711,6 +3719,12 @@ captured_main (int argc, char *argv[]) own_buf = (char *) xmalloc (PBUFSIZ + 1); mem_buf = (unsigned char *) xmalloc (PBUFSIZ); + if (selftest) + { + run_self_tests (); + throw_quit ("Quit"); + } + if (pid == 0 && *next_arg != NULL) { int i, n; diff --git a/gdb/testsuite/gdb.server/unittest.exp b/gdb/testsuite/gdb.server/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" + } +}