]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/build] Fix build with --disable-unit-tests
authorTom de Vries <tdevries@suse.de>
Fri, 29 Oct 2021 12:11:08 +0000 (14:11 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 29 Oct 2021 12:11:08 +0000 (14:11 +0200)
A build with --disable-unit-tests currently run into:
...
ld: maint.o: in function \
  `maintenance_selftest_completer(cmd_list_element*, completion_tracker&,
                                  char const*, char const*)':
src/gdb/maint.c:1183: undefined reference to \
  `selftests::for_each_selftest(
    gdb::function_view<
      void (std::__cxx11::basic_string<char,std::char_traits<char>,
                                       std::allocator<char> > const&)>)'
...

Fix this by guarding the call to selftests::for_each_selftest in
maintenance_selftest_completer with GDB_SELF_TEST, such that the "-verbose"
completion still works.

Rebuild on x86_64-linux and ran gdb.gdb/unittest.exp.

gdb/maint.c
gdb/testsuite/gdb.gdb/unittest.exp

index 85fa18c34a07a899fe7f88e99bd524cf2d249e4d..bcc71aab579f8b1bcd7161491856224c9aff66c2 100644 (file)
@@ -1180,11 +1180,13 @@ maintenance_selftest_completer (cmd_list_element *cmd,
        (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp))
     return;
 
+#if GDB_SELF_TEST
   selftests::for_each_selftest ([&tracker, text] (const std::string &name)
     {
       if (startswith (name.c_str (), text))
        tracker.add_completion (make_unique_xstrdup (name.c_str ()));
     });
+#endif
 }
 
 static void
index 0ddd20683773376b0c4d628764594b22f2f31e44..bcb4bbd2a821ae7a177c6b2a0a386ec25cb7c2ac 100644 (file)
@@ -40,6 +40,7 @@ proc run_selftests { binfile } {
        clean_restart ${binfile}
     }
 
+    set enabled 1
     set test "maintenance selftest"
     gdb_test_multiple $test $test {
        -re ".*Running selftest \[^\n\r\]+\." {
@@ -57,23 +58,35 @@ proc run_selftests { binfile } {
        }
        -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
            unsupported $test
+           set enabled 0
        }
     }
+
+    return $enabled
 }
 
 # Test completion of command "maintenance selftest".
 
 proc_with_prefix test_completion {} {
+    global self_tests_enabled
+
     clean_restart
-    test_gdb_complete_tab_multiple "maintenance selftest string_v" "" \
-       {string_vappendf string_view string_vprintf}
-    test_gdb_complete_tab_unique "maintenance selftest string_vie" "maintenance selftest string_view" " "
+
+    if { $self_tests_enabled } {
+       test_gdb_complete_tab_multiple "maintenance selftest string_v" "" \
+           {string_vappendf string_view string_vprintf}
+       test_gdb_complete_tab_unique "maintenance selftest string_vie" \
+           "maintenance selftest string_view" " "
+    } else {
+       test_gdb_complete_tab_none "maintenance selftest string_v"
+       test_gdb_complete_tab_none "maintenance selftest string_vie"
+    }
     test_gdb_complete_tab_unique "maintenance selftest -ver" "maintenance selftest -verbose" " "
     test_gdb_complete_tab_none "maintenance selftest name_that_does_not_exist"
 }
 
 with_test_prefix "no executable loaded" {
-    run_selftests ""
+    set self_tests_enabled [run_selftests ""]
 }
 
 with_test_prefix "executable loaded" {