Fix GDBserver build failure when $development is false
authorYao Qi <yao.qi@linaro.org>
Mon, 8 Jan 2018 10:09:33 +0000 (10:09 +0000)
committerYao Qi <yao.qi@linaro.org>
Mon, 8 Jan 2018 10:09:33 +0000 (10:09 +0000)
When we set bfd/development.sh:$development to false, GDBserver failed to
build,

selftest.o: In function `selftests::run_tests(char const*)':
binutils-gdb/gdb/gdbserver/../common/selftest.c:97:undefined reference to `selftests::reset()'
collect2: error: ld returned 1 exit status

selftest.o shouldn't be compiled and linked when $development is false.
With this patch, in release mode, GDBserver doesn't nothing with option
--selftest,

$ ./gdbserver --selftest=foo
Selftests are not available in a non-development build.
$ ./gdbserver --selftest
Selftests are not available in a non-development build.

gdb/gdbserver:

2018-01-08  Yao Qi  <yao.qi@linaro.org>
    Simon Marchi  <simon.marchi@ericsson.com>

* Makefile.in (OBS): Remove selftest.o.
* configure.ac: Set srv_selftest_objs if $development is true.
(GDBSERVER_DEPFILES): Append $srv_selftest_objs.
* configure: Re-generated.
* server.c (captured_main): Wrap variable selftest_filter with
GDB_SELF_TEST.

gdb/testsuite:

2018-01-08  Simon Marchi  <simon.marchi@ericsson.com>

* gdb.server/unittest.exp: Match the output in non-development
mode.

gdb/gdbserver/ChangeLog
gdb/gdbserver/Makefile.in
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/gdbserver/server.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.server/unittest.exp

index b9757c3ba48ab8f2f082bdcd0368a5b1ac0e0bb0..32a515728f327fd64e2a82c31a693ce93b8e0b8b 100644 (file)
@@ -1,3 +1,13 @@
+2018-01-08  Yao Qi  <yao.qi@linaro.org>
+           Simon Marchi  <simon.marchi@ericsson.com>
+
+       * Makefile.in (OBS): Remove selftest.o.
+       * configure.ac: Set srv_selftest_objs if $development is true.
+       (GDBSERVER_DEPFILES): Append $srv_selftest_objs.
+       * configure: Re-generated.
+       * server.c (captured_main): Wrap variable selftest_filter with
+       GDB_SELF_TEST.
+
 2018-01-07  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * server.c (parse_debug_format_options): Return std::string.
index caa94a65240a9a4813e672b5e052584e2cab7f6d..3ce086d70f23df445b174c49c489ec8415d7614a 100644 (file)
@@ -261,7 +261,6 @@ OBS = \
        regcache.o \
        remote-utils.o \
        rsp-low.o \
-       selftest.o \
        server.o \
        signals.o \
        signals-state-save-restore.o \
index 835dcca31446834e9eedd8b4c226ab6263afcfef..ca51321c8469282a54dbc1adc8cf52ced64dc290 100755 (executable)
@@ -5815,6 +5815,7 @@ fi
 
 
 if $development; then
+  srv_selftest_objs="selftest.o"
 
 $as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
 
@@ -8287,7 +8288,7 @@ $as_echo "#define USE_XML 1" >>confdefs.h
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs $srv_selftest_objs"
 GDBSERVER_LIBS="$srv_libs"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target supports __sync_*_compare_and_swap" >&5
index 916384ea6215a365e93e5b19fc5692cb0a634581..7ea3654f63a5fbbb4419c926df1e15ea1222ae14 100644 (file)
@@ -57,6 +57,7 @@ fi
 GDB_AC_LIBMCHECK(${libmcheck_default})
 
 if $development; then
+  srv_selftest_objs="selftest.o"
   AC_DEFINE(GDB_SELF_TEST, 1,
             [Define if self-testing features should be enabled])
 fi
@@ -410,7 +411,7 @@ if test "$srv_xmlfiles" != ""; then
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs $srv_selftest_objs"
 GDBSERVER_LIBS="$srv_libs"
 
 dnl Check whether the target supports __sync_*_compare_and_swap.
index 665d9aac6f4e9ae024566669024239f50debae2a..9d12ce6f7069ad23cc95ed91a10a37536410deb0 100644 (file)
@@ -3559,7 +3559,9 @@ captured_main (int argc, char *argv[])
   volatile int attach = 0;
   int was_running;
   bool selftest = false;
+#if GDB_SELF_TEST
   const char *selftest_filter = NULL;
+#endif
 
   while (*next_arg != NULL && **next_arg == '-')
     {
@@ -3683,7 +3685,9 @@ captured_main (int argc, char *argv[])
       else if (startswith (*next_arg, "--selftest="))
        {
          selftest = true;
+#if GDB_SELF_TEST
          selftest_filter = *next_arg + strlen ("--selftest=");
+#endif
        }
       else
        {
@@ -3761,7 +3765,11 @@ captured_main (int argc, char *argv[])
 
   if (selftest)
     {
+#if GDB_SELF_TEST
       selftests::run_tests (selftest_filter);
+#else
+      printf (_("Selftests are not available in a non-development build.\n"));
+#endif
       throw_quit ("Quit");
     }
 
index c1223dbd13a6b5bfe470dc4712ab790842e55b5d..71424a96d32139d8ffcf4cbabafd13a32c3cc0e2 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-08  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * gdb.server/unittest.exp: Match the output in non-development
+       mode.
+
 2018-01-08  Simon Marchi  <simon.marchi@ericsson.com>
 
        * gdb.gdb/unittest.exp: Match output in non-development mode.
index 646babcaa5fcae7aa4e189a14f927e75b931d3df..e947ff2c30f97651f70b3f8cb1d98062d1133a2e 100644 (file)
@@ -30,12 +30,19 @@ set gdbserver_command "$gdbserver --selftest"
 
 set server_spawn_id [remote_spawn target $gdbserver_command]
 
+set test "unit tests"
 gdb_expect {
     -i $server_spawn_id
-    -re "Ran $decimal unit tests, 0 failed" {
-       pass "unit tests"
+    -re "Ran ($decimal) unit tests, 0 failed" {
+       set num_ran $expect_out(1,string)
+       gdb_assert "$num_ran > 0" $test
     }
+
+    -re "Selftests are not available in a non-development build.\r\n$" {
+       unsupported $test
+    }
+
     default {
-       fail "unit tests"
+       fail $test
     }
 }