[PATCH 1/2] Detect and report incompatible gdb_compile options

Gary Benson gbenson@redhat.com
Tue Oct 13 17:26:17 GMT 2020


In commits 221db974e653659edb280787af1b3efdd1615083 and
68d654afdfcff840ebb3ae432ed72dca0521d670, these patches:

    2020-06-24  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_compile): Pass "-x c++" explicitly when
	compiling C++ programs.

    2020-09-25  Gary Benson <gbenson@redhat.com>

	* lib/gdb.exp (gdb_compile): Pass "-x c++" earlier, and only
	for .c files.

attempted to fix problems with testcases that compile .c files
using the C++ compiler.  These patches cause gdb_compile to add
"-x c++" to the compiler options when using Clang.  This fix does
not work for gdb.base/print-file-var.exp, however, which attempts
to compile a .c input file to an executable linked with shared
libraries: the resulting command caused the compiler to attempt
to parse the .so files as C++.  This patch causes gdb_compile
to reject this combination of options.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_compile): Inhibit passing "-x c++"
	for .c files compiled as C++ with Clang if any shared
	libraries are specified.
---
 gdb/testsuite/ChangeLog   |  6 ++++++
 gdb/testsuite/lib/gdb.exp | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 6084699..999fd63 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3946,6 +3946,22 @@ proc gdb_compile {source dest type options} {
 	 && [lsearch -exact $options c++] != -1
 	 && [string match *.c $source] != 0
 	 && [test_compiler_info "clang-*"] } {
+
+	# gdb_compile cannot handle this combination of options, the
+	# result is a command like "clang -x c++ foo.c bar.so -o baz"
+	# which tells Clang to treat bar.so as C++.  The solution is
+	# to call gdb_compile twice--once to compile, once to link--
+	# either directly, or via build_executable_from_specs.
+	if { [lsearch $options shlib=*] != -1 } {
+	    set result "incompatible gdb_compile options"
+
+	    if {[lsearch $options quiet] < 0} {
+		clone_output "gdb compile failed, $result"
+	    }
+
+	    return $result
+	}
+
 	lappend new_options early_flags=-x\ c++
     }
 
-- 
1.8.3.1



More information about the Gdb-patches mailing list