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]

Re: [PATCH] Fix `rerun_to_main'


On 05/12/2012 01:14 AM, Sergio Durigan Junior wrote:
> Hi,
>
> As mentioned in:
>
>     http://sourceware.org/ml/gdb-patches/2012-05/msg00458.html
>
> I believe `rerun_to_main' is wrong for native GDB.  It does not certify
> that (a) there is a breakpoint on `main' and (b) this breakpoint is
> hit.  The proposed patch fixes this by always inserting a temporary
> breakpoint on `main' (even for GDBserver cases), and then checking that
> this breakpoint has hit in a native GDB environment.

I think it's called "RErun" exactly because it assumes that the breakpoint
at main already exists from a previous runto_main.  It has to be, otherwise
all users would be broken.

`runto' takes an optional argument that is passed to gdb_breakpoint, so to
get the "temporary breakpoint" behavior you've implemented, one can today
instead do:

 runto main temporary

Here's rerun_to_main as in the tree:

proc rerun_to_main {} {
  global gdb_prompt use_gdb_stub

  if $use_gdb_stub {
    gdb_run_cmd
    gdb_expect {
      -re ".*Breakpoint .*main .*$gdb_prompt $"\
	      {pass "rerun to main" ; return 0}
      -re "$gdb_prompt $"\
	      {fail "rerun to main" ; return 0}
      timeout {fail "(timeout) rerun to main" ; return 0}
    }
  } else {
    send_gdb "run\n"
    gdb_expect {
      -re "The program .* has been started already.*y or n. $" {
	  send_gdb "y\n"
	  exp_continue
      }
      -re "Starting program.*$gdb_prompt $"\
	      {pass "rerun to main" ; return 0}
      -re "$gdb_prompt $"\
	      {fail "rerun to main" ; return 0}
      timeout {fail "(timeout) rerun to main" ; return 0}
    }
  }
}

I can't see why is this sending a literal "run" here in the native
case instead of unconditionally calling gdb_run_cmd.  This is also
not catching internal errors, and probably other things runto or
gdb_run_cmd catches.  IMO, it'd be better to factor out from
runto everything starting from the gdb_run_cmd call to a separate
function, and make both runto and rerun_to_main call that.

-- 
Pedro Alves


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