+2015-01-09 Pedro Alves <palves@redhat.com>
+
+ * lib/gdb.exp (can_spawn_for_attach): New procedure.
+ (spawn_wait_for_attach): Error out if can_spawn_for_attach returns
+ false.
+ * gdb.base/attach.exp: Use can_spawn_for_attach instead of
+ checking whether the target board is remote.
+ * gdb.multi/multi-attach.exp: Likewise.
+ * gdb.python/py-sync-interp.exp: Likewise.
+ * gdb.server/ext-attach.exp: Likewise.
+ * gdb.python/py-prompt.exp: Use can_spawn_for_attach before the
+ tests that need to attach, instead of checking whether the target
+ board is remote at the top of the file.
+
2015-01-08 Yao Qi <yao@codesourcery.com>
* gdb.trace/entry-values.exp: Set call_insn for MIPS target.
return 0
}
-# are we on a target board
-if [is_remote target] then {
+if {![can_spawn_for_attach]} {
return 0
}
return 0
}
-# Are we on a target board? It is required for attaching to a process.
-if [is_remote target] {
+if {![can_spawn_for_attach]} {
return 0
}
standard_testfile
-# We need to use TCL's exec to get the pid.
-if [is_remote target] then {
+if {![can_spawn_for_attach]} {
return 0
}
standard_testfile
-# We need to use TCL's exec to get the pid.
-if [is_remote target] then {
- return 0
-}
-
load_lib gdb-python.exp
load_lib prompt.exp
"prompt_hook argument is default prompt. 2"
gdb_exit
+if {![can_spawn_for_attach]} {
+ return 0
+}
+
set testpid [spawn_wait_for_attach $binfile]
set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
standard_testfile
-# We need to use TCL's exec to get the pid.
-if [is_remote target] then {
+if {![can_spawn_for_attach]} {
return 0
}
return 0
}
-# We need to use TCL's exec to get the pid.
-if [is_remote target] then {
+if {![can_spawn_for_attach]} {
return 0
}
catch default_gdb_exit
}
+# Return true if we can spawn a program on the target and attach to
+# it.
+
+proc can_spawn_for_attach { } {
+ # We use TCL's exec to get the inferior's pid.
+ if [is_remote target] then {
+ return 0
+ }
+
+ # The "attach" command doesn't make sense when the target is
+ # stub-like, where GDB finds the program already started on
+ # initial connection.
+ if {[target_info exists use_gdb_stub]} {
+ return 0
+ }
+
+ # Assume yes.
+ return 1
+}
+
# Start a set of programs running and then wait for a bit, to be sure
# that they can be attached to. Return a list of the processes' PIDs.
+# It's a test error to call this when [can_spawn_for_attach] is false.
proc spawn_wait_for_attach { executable_list } {
set pid_list {}
+ if ![can_spawn_for_attach] {
+ # The caller should have checked can_spawn_for_attach itself
+ # before getting here.
+ error "can't spawn for attach with this target/board"
+ }
+
foreach {executable} $executable_list {
lappend pid_list [eval exec $executable &]
}