[PATCH] GDB/testsuite: Add a way to send multiple init commands

Maciej W. Rozycki
2014-06-10T18:24:07Z

Hi,

We've been using this change since time immemorial, in fact our recorded
original internal ChangeLog entry date is 2005-08-15. I've thought this
piece might be useful for other people so I'm sharing it here.

Right now we provide a board info entry, `gdb_init_command', that allows
one to send a single command to GDB before the program to be debugged is
started. This is useful e.g. for slow remote targets to change the
default "remotetimeout" setting. Occasionally I found a need to send
multiple commands instead, however this cannot be achieved with
`gdb_init_command'.

This change therefore extends the mechanism by adding a TCL list of GDB
commands to send, via a board info entry called `gdb_init_commands'.
There is no limit as to the number of commands put there. The old
`gdb_init_command' mechanism remains supported for compatibility with
existing people's environments. I have a separate change for DejaGNU too,
being posted right away, that adds an `add_board_info' procedure that
makes it easy to append entries there; it's not strictly needed here or
anywhere in our testsuite though.

There's nothing really to regression-test here, beside checking that TCL
doesn't choke on it (it doesn't), it's worked for me in real uses for
years too. OK to apply?

2014-06-10 Maciej W. Rozycki <macro@mips.com>
Maciej W. Rozycki <macro@codesourcery.com>

* lib/gdb.exp (gdb_run_cmd): Process `gdb_init_commands'.
* lib/mi-support.exp (mi_run_cmd): Process `gdb_init_commands'.

Maciej

gdb-init-commands.diff
Index: gdb-fsf-trunk-quilt/gdb/testsuite/lib/gdb.exp
===================================================================
--- gdb-fsf-trunk-quilt.orig/gdb/testsuite/lib/gdb.exp 2014-06-06 15:04:15.000000000 +0100
+++ gdb-fsf-trunk-quilt/gdb/testsuite/lib/gdb.exp 2014-06-06 15:05:05.867648960 +0100
@@ -219,6 +219,19 @@ proc gdb_run_cmd {args} {
}
}
}
+ if [target_info exists gdb_init_commands] {
+ set commands [target_info gdb_init_commands];
+ for { set x 0; } { $x < [llength $commands] } { incr x } {
+ send_gdb "[lindex $commands $x]\n";
+ gdb_expect 30 {
+ -re "$gdb_prompt $" { }
+ default {
+ perror "gdb_init_command for target failed";
+ return;
+ }
+ }
+ }
+ }

if $use_gdb_stub {
if [target_info exists gdb,do_reload_on_run] {
Index: gdb-fsf-trunk-quilt/gdb/testsuite/lib/mi-support.exp
===================================================================
--- gdb-fsf-trunk-quilt.orig/gdb/testsuite/lib/mi-support.exp 2014-06-03 15:23:23.000000000 +0100
+++ gdb-fsf-trunk-quilt/gdb/testsuite/lib/mi-support.exp 2014-06-06 15:05:05.867648960 +0100
@@ -869,6 +869,19 @@ proc mi_run_cmd_full {use_mi_command arg
}
}
}
+ if [target_info exists gdb_init_commands] {
+ set commands [target_info gdb_init_commands];
+ for { set x 0; } { $x < [llength $commands] } { incr x } {
+ send_gdb "[lindex $commands $x]\n";
+ gdb_expect 30 {
+ -re "$mi_gdb_prompt$" { }
+ default {
+ perror "gdb_init_command for target failed";
+ return -1;
+ }
+ }
+ }
+ }

if { [mi_gdb_target_load] < 0 } {
return -1