public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2 master/8.1] Fix GDB build failure when $development is false
@ 2018-01-05 10:35 Yao Qi
  2018-01-05 10:35 ` [PATCH 2/2 master/8.1] Fix GDBserver " Yao Qi
  2018-01-06 17:09 ` [PATCH 1/2 master/8.1] Fix GDB " Simon Marchi
  0 siblings, 2 replies; 6+ messages in thread
From: Yao Qi @ 2018-01-05 10:35 UTC (permalink / raw)
  To: gdb-patches

We don't build GDB selftests bits when $development is false.  However, if
we turn bfd/development.sh:$development to false, common/selftest.c is
compiled which is not expected.  It causes the build failure,

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

I fix this issue by putting selftest.o selftest-arch.o into CONFIG_OBS
only when $development is true.  After this is fixed, there are other
build failures in maint.c, this patch fixes them as well.

In the release mode, the output of these commands are:

(gdb) maintenance selftest
(gdb) maintenance selftest ffo
(gdb) maintenance info selftest
Registered selftests:
(gdb)

gdb:

2018-01-05  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (COMMON_SFILES): Remove selftest-arch.c and
	common/selftest.c.
	(COMMON_OBS): Remove selftest.o.
	* configure.ac: Append selftest-arch.c and common/selftest.c to
	CONFIG_SRCS.  Append selftest-arch.o and selftest.o to COMMON_OBS.
	* configure: Re-generated.
	* maint.c (maintenance_selftest): Wrap selftests::run_tests with
	GDB_SELF_TEST.
	(maintenance_info_selftests): Likewise.
---
 gdb/Makefile.in  | 3 ---
 gdb/configure    | 4 ++--
 gdb/configure.ac | 4 ++--
 gdb/maint.c      | 4 ++++
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index c0486c4..17b71c6 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1050,7 +1050,6 @@ COMMON_SFILES = \
 	remote-notif.c \
 	reverse.c \
 	rust-lang.c \
-	selftest-arch.c \
 	sentinel-frame.c \
 	ser-event.c \
 	serial.c \
@@ -1139,7 +1138,6 @@ 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 \
@@ -1555,7 +1553,6 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	ptid.o \
 	rsp-low.o \
 	run-time-clock.o \
-	selftest.o \
 	signals.o \
 	signals-state-save-restore.o \
 	vec.o \
diff --git a/gdb/configure b/gdb/configure
index 7b25007..db610f3 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -17599,8 +17599,8 @@ if $development; then
 
 $as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
 
-  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS)"
-  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS)"
+  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS) selftest.o selftest-arch.o"
+  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS) common/selftest.c selftest-arch.c"
 fi
 
 
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 3e073b5..3db44ae 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -2293,8 +2293,8 @@ AC_DEFINE(GDB_DEFAULT_HOST_CHARSET, "UTF-8",
 if $development; then
   AC_DEFINE(GDB_SELF_TEST, 1,
             [Define if self-testing features should be enabled])
-  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS)"
-  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS)"
+  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS) selftest.o selftest-arch.o"
+  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS) common/selftest.c selftest-arch.c"
 fi
 
 GDB_AC_TRANSFORM([gdb], [GDB_TRANSFORM_NAME])
diff --git a/gdb/maint.c b/gdb/maint.c
index a924f83..624a80e 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -939,16 +939,20 @@ show_per_command_cmd (const char *args, int from_tty)
 static void
 maintenance_selftest (const char *args, int from_tty)
 {
+#if GDB_SELF_TEST
   selftests::run_tests (args);
+#endif
 }
 
 static void
 maintenance_info_selftests (const char *arg, int from_tty)
 {
   printf_filtered ("Registered selftests:\n");
+#if GDB_SELF_TEST
   selftests::for_each_selftest ([] (const std::string &name) {
     printf_filtered (" - %s\n", name.c_str ());
   });
+#endif
 }
 
 \f
-- 
1.9.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2 master/8.1] Fix GDBserver build failure when $development is false
  2018-01-05 10:35 [PATCH 1/2 master/8.1] Fix GDB build failure when $development is false Yao Qi
@ 2018-01-05 10:35 ` Yao Qi
  2018-01-06 17:21   ` Simon Marchi
  2018-01-06 17:09 ` [PATCH 1/2 master/8.1] Fix GDB " Simon Marchi
  1 sibling, 1 reply; 6+ messages in thread
From: Yao Qi @ 2018-01-05 10:35 UTC (permalink / raw)
  To: gdb-patches

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
$ ./gdbserver --selftest
$

gdb/gdbserver:

2018-01-05  Yao Qi  <yao.qi@linaro.org>

	* 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/gdbserver/Makefile.in  | 1 -
 gdb/gdbserver/configure    | 3 ++-
 gdb/gdbserver/configure.ac | 3 ++-
 gdb/gdbserver/server.c     | 6 ++++++
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index caa94a6..3ce086d 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -261,7 +261,6 @@ 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/configure b/gdb/gdbserver/configure
index 835dcca..ca51321 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -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
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 916384e..7ea3654 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -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.
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 3367555..b6eefb4 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3560,7 +3560,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 == '-')
     {
@@ -3684,7 +3686,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
 	{
@@ -3762,7 +3766,9 @@ captured_main (int argc, char *argv[])
 
   if (selftest)
     {
+#if GDB_SELF_TEST
       selftests::run_tests (selftest_filter);
+#endif
       throw_quit ("Quit");
     }
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2 master/8.1] Fix GDB build failure when $development is false
  2018-01-05 10:35 [PATCH 1/2 master/8.1] Fix GDB build failure when $development is false Yao Qi
  2018-01-05 10:35 ` [PATCH 2/2 master/8.1] Fix GDBserver " Yao Qi
@ 2018-01-06 17:09 ` Simon Marchi
  2018-01-08  9:53   ` Yao Qi
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2018-01-06 17:09 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 2018-01-05 05:34 AM, Yao Qi wrote:
> We don't build GDB selftests bits when $development is false.  However, if
> we turn bfd/development.sh:$development to false, common/selftest.c is
> compiled which is not expected.  It causes the build failure,
> 
> selftest.o: In function `selftests::run_tests(char const*)':
> binutils-gdb/gdb/common/selftest.c:97: undefined reference to `selftests::reset()'
> collect2: error: ld returned 1 exit status
> 
> I fix this issue by putting selftest.o selftest-arch.o into CONFIG_OBS
> only when $development is true.  After this is fixed, there are other
> build failures in maint.c, this patch fixes them as well.
> 
> In the release mode, the output of these commands are:
> 
> (gdb) maintenance selftest
> (gdb) maintenance selftest ffo
> (gdb) maintenance info selftest
> Registered selftests:
> (gdb)

I would suggest printing a message when selftests are not available, instead
of doing nothing.  It could help people figure out why they are not running
as they would expect.

Also, it would allow changing gdb.gdb/unittest.exp to report "unsupported"
when make checking a non-development build, which is a bit more precise
than reporting a pass.

Otherwise, the patch LGTM.

Here's a fixup patch that does this, feel free to use it if you like the
idea.  Just as a sanity check, I added an assert in unittest.exp to make sure
that when tests are ran, we run at least one test.

Simon


From 19aaacbe970594e077f502e3212a5a22d4dc716e Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Sat, 6 Jan 2018 11:49:09 -0500
Subject: [PATCH] Print message when selftests are not available

---
 gdb/maint.c                        |  8 +++++++-
 gdb/testsuite/gdb.gdb/unittest.exp | 13 ++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gdb/maint.c b/gdb/maint.c
index 624a80e..70e0011 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -941,17 +941,23 @@ maintenance_selftest (const char *args, int from_tty)
 {
 #if GDB_SELF_TEST
   selftests::run_tests (args);
+#else
+  printf_filtered (_("\
+Selftests are not available in a non-development build.\n"));
 #endif
 }

 static void
 maintenance_info_selftests (const char *arg, int from_tty)
 {
-  printf_filtered ("Registered selftests:\n");
 #if GDB_SELF_TEST
+  printf_filtered ("Registered selftests:\n");
   selftests::for_each_selftest ([] (const std::string &name) {
     printf_filtered (" - %s\n", name.c_str ());
   });
+#else
+  printf_filtered (_("\
+Selftests are not available in a non-development build.\n"));
 #endif
 }

diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp
index 44e9329..1c83585 100644
--- a/gdb/testsuite/gdb.gdb/unittest.exp
+++ b/gdb/testsuite/gdb.gdb/unittest.exp
@@ -16,7 +16,18 @@
 set do_xml_test [expr ![gdb_skip_xml_test]]

 gdb_start
-gdb_test "maintenance selftest" "Ran $decimal unit tests, 0 failed"
+
+set test "maintenance selftest"
+gdb_test_multiple $test $test {
+  -re "Ran ($decimal) unit tests, 0 failed\r\n$gdb_prompt $" {
+	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$gdb_prompt $" {
+	unsupported $test
+  }
+}

 if { ![is_remote host] && $do_xml_test } {
     gdb_test "maintenance check xml-descriptions ${srcdir}/../features" \
-- 
2.7.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2 master/8.1] Fix GDBserver build failure when $development is false
  2018-01-05 10:35 ` [PATCH 2/2 master/8.1] Fix GDBserver " Yao Qi
@ 2018-01-06 17:21   ` Simon Marchi
  2018-01-08  9:55     ` Yao Qi
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2018-01-06 17:21 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 2018-01-05 05:34 AM, Yao Qi wrote:
> 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
> $ ./gdbserver --selftest
> $

Hi Yao,

Same comment as the for the GDB patch, and here's a fixup patch that does what
I suggest.

Simon


From 1f610a553d226e00ef3832c518c45e36da6d0702 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Sat, 6 Jan 2018 12:17:18 -0500
Subject: [PATCH] Same for gdbserver

---
 gdb/gdbserver/server.c                |  2 ++
 gdb/testsuite/gdb.server/unittest.exp | 13 ++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 881ee48..3a4661d 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3768,6 +3768,8 @@ captured_main (int argc, char *argv[])
     {
 #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");
     }
diff --git a/gdb/testsuite/gdb.server/unittest.exp b/gdb/testsuite/gdb.server/unittest.exp
index 646babc..e947ff2 100644
--- a/gdb/testsuite/gdb.server/unittest.exp
+++ b/gdb/testsuite/gdb.server/unittest.exp
@@ -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
     }
 }
-- 
2.7.4



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2 master/8.1] Fix GDB build failure when $development is false
  2018-01-06 17:09 ` [PATCH 1/2 master/8.1] Fix GDB " Simon Marchi
@ 2018-01-08  9:53   ` Yao Qi
  0 siblings, 0 replies; 6+ messages in thread
From: Yao Qi @ 2018-01-08  9:53 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi <simon.marchi@ericsson.com> writes:

> Otherwise, the patch LGTM.
>
> Here's a fixup patch that does this, feel free to use it if you like the
> idea.  Just as a sanity check, I added an assert in unittest.exp to make sure
> that when tests are ran, we run at least one test.

It is good to make the output more explicit.  I take your fixup patch
in, and I'll push the patch below in.

-- 
Yao (齐尧)

From 90234dc5a200dfe08a32f22dfc47752b87e3e7a1 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Fri, 5 Jan 2018 09:32:20 +0000
Subject: [PATCH 1/2] Fix GDB build failure when $development is false

We don't build GDB selftests bits when $development is false.  However, if
we turn bfd/development.sh:$development to false, common/selftest.c is
compiled which is not expected.  It causes the build failure,

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

I fix this issue by putting selftest.o selftest-arch.o into CONFIG_OBS
only when $development is true.  After this is fixed, there are other
build failures in maint.c, this patch fixes them as well.

In the release mode, the output of these commands are:

(gdb) maintenance selftest
Selftests are not available in a non-development build.
(gdb) maintenance selftest foo
Selftests are not available in a non-development build.
(gdb) maintenance info selftests
Selftests are not available in a non-development build.

gdb:

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

	* Makefile.in (COMMON_SFILES): Remove selftest-arch.c and
	common/selftest.c.
	(COMMON_OBS): Remove selftest.o.
	* configure.ac: Append selftest-arch.c and common/selftest.c to
	CONFIG_SRCS.  Append selftest-arch.o and selftest.o to COMMON_OBS.
	* configure: Re-generated.
	* maint.c (maintenance_selftest): Wrap selftests::run_tests with
	GDB_SELF_TEST.
	(maintenance_info_selftests): Likewise.

gdb/testsuite:

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

	* gdb.gdb/unittest.exp: Match output in non-development mode.
---
 gdb/Makefile.in                    |  3 ---
 gdb/configure                      |  4 ++--
 gdb/configure.ac                   |  4 ++--
 gdb/maint.c                        | 10 ++++++++++
 gdb/testsuite/gdb.gdb/unittest.exp | 13 ++++++++++++-
 5 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index c0486c4..17b71c6 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1050,7 +1050,6 @@ COMMON_SFILES = \
 	remote-notif.c \
 	reverse.c \
 	rust-lang.c \
-	selftest-arch.c \
 	sentinel-frame.c \
 	ser-event.c \
 	serial.c \
@@ -1139,7 +1138,6 @@ 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 \
@@ -1555,7 +1553,6 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	ptid.o \
 	rsp-low.o \
 	run-time-clock.o \
-	selftest.o \
 	signals.o \
 	signals-state-save-restore.o \
 	vec.o \
diff --git a/gdb/configure b/gdb/configure
index 7b25007..db610f3 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -17599,8 +17599,8 @@ if $development; then
 
 $as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
 
-  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS)"
-  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS)"
+  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS) selftest.o selftest-arch.o"
+  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS) common/selftest.c selftest-arch.c"
 fi
 
 
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 3e073b5..3db44ae 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -2293,8 +2293,8 @@ AC_DEFINE(GDB_DEFAULT_HOST_CHARSET, "UTF-8",
 if $development; then
   AC_DEFINE(GDB_SELF_TEST, 1,
             [Define if self-testing features should be enabled])
-  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS)"
-  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS)"
+  CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_UNITTESTS_OBS) selftest.o selftest-arch.o"
+  CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_UNITTESTS_SRCS) common/selftest.c selftest-arch.c"
 fi
 
 GDB_AC_TRANSFORM([gdb], [GDB_TRANSFORM_NAME])
diff --git a/gdb/maint.c b/gdb/maint.c
index a924f83..70e0011 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -939,16 +939,26 @@ show_per_command_cmd (const char *args, int from_tty)
 static void
 maintenance_selftest (const char *args, int from_tty)
 {
+#if GDB_SELF_TEST
   selftests::run_tests (args);
+#else
+  printf_filtered (_("\
+Selftests are not available in a non-development build.\n"));
+#endif
 }
 
 static void
 maintenance_info_selftests (const char *arg, int from_tty)
 {
+#if GDB_SELF_TEST
   printf_filtered ("Registered selftests:\n");
   selftests::for_each_selftest ([] (const std::string &name) {
     printf_filtered (" - %s\n", name.c_str ());
   });
+#else
+  printf_filtered (_("\
+Selftests are not available in a non-development build.\n"));
+#endif
 }
 
 \f
diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp
index 44e9329..1c83585 100644
--- a/gdb/testsuite/gdb.gdb/unittest.exp
+++ b/gdb/testsuite/gdb.gdb/unittest.exp
@@ -16,7 +16,18 @@
 set do_xml_test [expr ![gdb_skip_xml_test]]
 
 gdb_start
-gdb_test "maintenance selftest" "Ran $decimal unit tests, 0 failed"
+
+set test "maintenance selftest"
+gdb_test_multiple $test $test {
+  -re "Ran ($decimal) unit tests, 0 failed\r\n$gdb_prompt $" {
+	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$gdb_prompt $" {
+	unsupported $test
+  }
+}
 
 if { ![is_remote host] && $do_xml_test } {
     gdb_test "maintenance check xml-descriptions ${srcdir}/../features" \
-- 
1.9.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2 master/8.1] Fix GDBserver build failure when $development is false
  2018-01-06 17:21   ` Simon Marchi
@ 2018-01-08  9:55     ` Yao Qi
  0 siblings, 0 replies; 6+ messages in thread
From: Yao Qi @ 2018-01-08  9:55 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi <simon.marchi@ericsson.com> writes:

> Hi Yao,
>
> Same comment as the for the GDB patch, and here's a fixup patch that does what
> I suggest.

Thanks for the fixup, patch below is what I am going to push.

-- 
Yao (齐尧)
From e5a4da1a85a3833cf9c87a5b69bb90325a363d38 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Fri, 5 Jan 2018 09:33:20 +0000
Subject: [PATCH 2/2] Fix GDBserver build failure when $development is false

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/Makefile.in             |  1 -
 gdb/gdbserver/configure               |  3 ++-
 gdb/gdbserver/configure.ac            |  3 ++-
 gdb/gdbserver/server.c                |  8 ++++++++
 gdb/testsuite/gdb.server/unittest.exp | 13 ++++++++++---
 5 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index caa94a6..3ce086d 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -261,7 +261,6 @@ 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/configure b/gdb/gdbserver/configure
index 835dcca..ca51321 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -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
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 916384e..7ea3654 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -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.
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 3367555..890ba3c 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3560,7 +3560,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 == '-')
     {
@@ -3684,7 +3686,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
 	{
@@ -3762,7 +3766,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");
     }
 
diff --git a/gdb/testsuite/gdb.server/unittest.exp b/gdb/testsuite/gdb.server/unittest.exp
index 646babc..e947ff2 100644
--- a/gdb/testsuite/gdb.server/unittest.exp
+++ b/gdb/testsuite/gdb.server/unittest.exp
@@ -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
     }
 }
-- 
1.9.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-08  9:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-05 10:35 [PATCH 1/2 master/8.1] Fix GDB build failure when $development is false Yao Qi
2018-01-05 10:35 ` [PATCH 2/2 master/8.1] Fix GDBserver " Yao Qi
2018-01-06 17:21   ` Simon Marchi
2018-01-08  9:55     ` Yao Qi
2018-01-06 17:09 ` [PATCH 1/2 master/8.1] Fix GDB " Simon Marchi
2018-01-08  9:53   ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).