+2013-10-02  Pedro Alves  <palves@redhat.com>
+
+       * README (Board Settings): Document "exit_is_reliable".
+       * lib/gdb.exp (gdb_continue_to_end): Check whether the board says
+       running to exit reliably reports program exits.
+       * boards/native-gdbserver.exp: Set exit_is_reliable in the board
+       info.
+       * boards/native-stdio-gdbserver.exp: Likewise.
+
 2013-10-01  Doug Evans  <dje@google.com>
 
        * gdb.python/python.exp: Remove redundant print-stack tests.
 
 
   The tests are running with a GDB stub.
 
+exit_is_reliable
+
+  Set to true if GDB can assume that letting the program run to end
+  reliably results in program exits being reported as such, as opposed
+  to, e.g., the program ending in an infinite loop or the board
+  crashing/resetting.  If not set, this defaults to $use_gdb_stub.  In
+  other words, native targets are assumed reliable by default, and
+  remote stubs assumed unreliable.
+
 gdb,predefined_tsv
 
   The predefined trace state variables the board has.
 
 
 set_board_info sockethost "localhost:"
 set_board_info use_gdb_stub 1
+set_board_info exit_is_reliable 1
 
 # We will be using the standard GDB remote protocol.
 set_board_info gdb_protocol "remote"
 
 set_board_info gdb,socketport ""
 set_board_info gdb,get_remote_address ${board}_get_remote_address
 set_board_info use_gdb_stub 1
+set_board_info exit_is_reliable 1
 
 # We will be using the standard GDB remote protocol.
 set_board_info gdb_protocol "remote"
 
     return $found
 }
 
-# gdb_continue_to_end:
-#      The case where the target uses stubs has to be handled specially. If a
-#       stub is used, we set a breakpoint at exit because we cannot rely on
-#       exit() behavior of a remote target.
-# 
+# Continue the program until it ends.
+#
 # MSSG is the error message that gets printed.  If not given, a
 #      default is used.
 # COMMAND is the command to invoke.  If not given, "continue" is
   } else {
       set extra ""
   }
-  if $use_gdb_stub {
+
+  # By default, we don't rely on exit() behavior of remote stubs --
+  # it's common for exit() to be implemented as a simple infinite
+  # loop, or a forced crash/reset.  For native targets, by default, we
+  # assume process exit is reported as such.  If a non-reliable target
+  # is used, we set a breakpoint at exit, and continue to that.
+  if { [target_info exists exit_is_reliable] } {
+      set exit_is_reliable [target_info exit_is_reliable]
+  } else {
+      set exit_is_reliable [expr ! $use_gdb_stub]
+  }
+
+  if { ! $exit_is_reliable } {
     if {![gdb_breakpoint "exit"]} {
       return 0
     }