This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: add build_executable_from_specs and prepare_for_testing_full
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 12 Jul 2012 09:09:18 -0600
- Subject: FYI: add build_executable_from_specs and prepare_for_testing_full
I'm checking this in.
This patch adds a couple of new convenience procs to the test suite.
They are like build_executable and prepare_for_testing, but they give
the caller more control over which options are passed to which compile.
A subsequent patch uses this to fix up some bad compiles in gdb.dwarf2;
and my cleanup of gdb.base will also use this.
Tom
2012-07-12 Tom Tromey <tromey@redhat.com>
* lib/gdb.exp (build_executable_from_specs): New proc, from
build_executable.
(build_executable): Use it.
(prepare_for_testing_full): New proc.
Index: lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.211
diff -u -r1.211 gdb.exp
--- lib/gdb.exp 10 Jul 2012 14:41:16 -0000 1.211
+++ lib/gdb.exp 12 Jul 2012 15:05:45 -0000
@@ -3734,29 +3734,31 @@
}
}
-# Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
-# provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
-# to pass to untested, if something is wrong. OPTIONS are passed
-# to gdb_compile directly.
-proc build_executable { testname executable {sources ""} {options {debug}} } {
-
- global objdir
+# Build executable named EXECUTABLE from specifications that allow
+# different options to be passed to different sub-compilations.
+# TESTNAME is the name of the test; this is passed to 'untested' if
+# something fails.
+# OPTIONS is passed to the final link, using gdb_compile.
+# ARGS is a flat list of source specifications, of the form:
+# { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
+# Each SOURCE is compiled to an object file using its OPTIONS,
+# using gdb_compile.
+# Returns 0 on success, -1 on failure.
+proc build_executable_from_specs {testname executable options args} {
global subdir
global srcdir
- if {[llength $sources]==0} {
- set sources ${executable}.c
- }
set binfile [standard_output_file $executable]
set objects {}
- for {set i 0} "\$i<[llength $sources]" {incr i} {
- set s [lindex $sources $i]
- if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
+ set i 0
+ foreach {s local_options} $args {
+ if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $local_options] != "" } {
untested $testname
return -1
}
lappend objects "${binfile}${i}.o"
+ incr i
}
if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
@@ -3774,6 +3776,23 @@
return 0
}
+# Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
+# provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
+# to pass to untested, if something is wrong. OPTIONS are passed
+# to gdb_compile directly.
+proc build_executable { testname executable {sources ""} {options {debug}} } {
+ if {[llength $sources]==0} {
+ set sources ${executable}.c
+ }
+
+ set arglist [list $testname $executable $options]
+ foreach source $sources {
+ lappend arglist $source $options
+ }
+
+ return [eval build_executable_from_specs $arglist]
+}
+
# Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
# the basename of the binary.
proc clean_restart { executable } {
@@ -3788,6 +3807,25 @@
gdb_load ${binfile}
}
+# Prepares for testing by calling build_executable_full, then
+# clean_restart.
+# TESTNAME is the name of the test.
+# Each element in ARGS is a list of the form
+# { EXECUTABLE OPTIONS SOURCE_SPEC... }
+# These are passed to build_executable_from_specs, which see.
+# The last EXECUTABLE is passed to clean_restart.
+# Returns 0 on success, non-zero on failure.
+proc prepare_for_testing_full {testname args} {
+ foreach spec $args {
+ if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
+ return -1
+ }
+ set executable [lindex $spec 0]
+ }
+ clean_restart $executable
+ return 0
+}
+
# Prepares for testing, by calling build_executable, and then clean_restart.
# Please refer to build_executable for parameter description.
proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {