This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Commands attached to breakpoints


Hi,

There's an annoying bug in the way commands attached to breakpoints are run.

Given a simple script:
  break main
  commands
    echo test\n
  end

invoke GDB like this:
  gdb -x breakscript -ex run a.out

it will only execute the echo command after the first interactive command (rather than when the breakpoint is hit).

This is because the commands are executed as part of the interactive command loop. This does not include commands executed using --eval-command or any MI commands.

The attached patch is one possible (partial) solution. It merely ensures that the commands are executed whenever a command of any sort is executed from anywhere.

However, there's clearly some subtleties here that I don't fully understand, because there are two further callers for bpstat_do_actions, in inf-loop.c and event-top.c, and both only use it conditionally.

I'm not sure what the right solution is here. Presumably the best place to do it would be in the breakpoint handling code (normal_stop?), but I'm guessing that there's issues with recursion there.

Any suggestions?

Andrew
2008-07-31  Andrew Stubbs  <andrew.stubbs@st.com>

	* top.c (command_loop): Move call to bpstat_do_actions ...
	(execute_command): ... to here, for other callers' benefit.


Index: gdb/top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.149
diff -u -p -r1.149 top.c
--- gdb/top.c	28 Jul 2008 17:53:52 -0000	1.149
+++ gdb/top.c	31 Jul 2008 13:52:53 -0000
@@ -488,6 +488,9 @@ Cannot execute this command without a li
 	  warned = 1;
 	}
     }
+
+    /* Do any commands attached to breakpoint we stopped at.  */
+    bpstat_do_actions (&stop_bpstat);
 }
 
 /* Read commands from `instream' and execute them
@@ -534,8 +537,6 @@ command_loop (void)
 	}
 
       execute_command (command, instream == stdin);
-      /* Do any commands attached to breakpoint we stopped at.  */
-      bpstat_do_actions (&stop_bpstat);
       do_cleanups (old_chain);
 
       if (display_time)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]