[1/2] testsuite: introduce 'default_gdb_start_post_cmd' as an overridable function

Message ID 6f9e6f6454aa63954b2c604d819eab4b5b5463f3.1587399322.git.tankut.baris.aktemur@intel.com
State New
Headers show
Series
  • Context-switch in finish-step-over flow
Related show

Commit Message

Rogerio Alves via Gdb-patches April 20, 2020, 4:24 p.m.
Introduce a function named 'default_gdb_start_post_cmd' that is
invoked at the end of 'default_gdb_start'.  The function is by default
empty and can be overridden in a board file or a test to perform
setup right after GDB starts.

The need for this function arose from the fact that doing
'maint set target-non-stop on' was not possible when using the
native-extended-gdbserver board file.  This board file overrides
gdb_start as below:

  proc gdb_start { } {
      # Spawn GDB.
      default_gdb_start

      # And then GDBserver, ready for extended-remote mode.
      gdbserver_start_multi

      return 0
  }

That is, GDB is started and an extended-remote target is defined
immediately following it.  However, to set the remote target to
non-stop mode, we would have to issue the 'maint set target-non-stop on'
code ...

  proc gdb_start { } {
      # Spawn GDB.
      default_gdb_start

-->   ### ... right here.

      # And then GDBserver, ready for extended-remote mode.
      gdbserver_start_multi

      return 0
  }

If the target-non-stop mode is set after making the connection,
we see the following problem:

   $ gdb
   (gdb) file a.out
   ...
   (gdb) set remote exec-file a.out
   (gdb) target extended-remote | gdbserver --once --multi -
   ...
   (gdb) maint set target-non-stop on
   (gdb) run
   ...
   Unexpected vCont reply in non-stop mode: T05swbreak:;06:f0dfffffff7f0000;07:10deffffff7f0000;10:d194ddf7ff7f0000;thread:p4706.4706;core:d;

This patch provides a generalized solution and gives the ability to do
custom setup after starting GDB but before connecting to the target.

gdb/testsuite/ChangeLog:
2020-04-20  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* lib/gdb.exp (default_gdb_start_post_cmd): New overridable
	function.
	(default_gdb_start): Invoke 'default_gdb_start_post_cmd'
	at the end.
---
 gdb/testsuite/lib/gdb.exp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

-- 
2.17.1

Patch

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 8418c3d8753..626edee6265 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1849,6 +1849,17 @@  proc default_gdb_spawn { } {
     return 0
 }
 
+# Overridable procedure that is called at the end of
+# default_gdb_start.
+
+proc default_gdb_start_post_cmd { } {
+    # Do nothing by default.
+    # You can override this in your board file or your test.
+    #
+    # E.g. Do "maint set target-non-stop on" to start in
+    # all-stop-on-top-of-non-stop mode.
+}
+
 # Default gdb_start procedure.
 
 proc default_gdb_start { } {
@@ -1919,6 +1930,7 @@  proc default_gdb_start { } {
     }
 
     gdb_debug_init
+    default_gdb_start_post_cmd
     return 0
 }