GDB/testsuite: Add a way to send multiple init commands
Commit Message
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
Comments
On 06/10/2014 11:22 AM, Maciej W. Rozycki wrote:
> 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";
The "normal" Tcl idiom for this is foreach:
foreach cmd $commands {
send_gdb $cmd
# ...
> + gdb_expect 30 {
> + -re "$gdb_prompt $" { }
> + default {
> + perror "gdb_init_command for target failed";
> + return;
> + }
> + }
> + }
> + }
Keith
>>>>> "Maciej" == Maciej W Rozycki <macro@codesourcery.com> writes:
Maciej> 2014-06-10 Maciej W. Rozycki <macro@mips.com>
Maciej> Maciej W. Rozycki <macro@codesourcery.com>
Maciej> * lib/gdb.exp (gdb_run_cmd): Process `gdb_init_commands'.
Maciej> * lib/mi-support.exp (mi_run_cmd): Process `gdb_init_commands'.
I like Keith's proposed cleanup.
Maciej> + set commands [target_info gdb_init_commands];
Extraneous ";". There are a few of these.
I think this patch should also update testsuite/README to document the
new setting.
thanks,
Tom
===================================================================
@@ -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] {
===================================================================
@@ -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