This is the mail archive of the gdb@sourceware.cygnus.com mailing list for the GDB project. See the GDB home page for more information.


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

Portability Issue in infrun.c


I'm going through infrun.c clearing out some nonportabilities, and
came across a tricky one in follow_exec.  For those of you just tuning
in, follow_exec() is a recent HP addition that allows GDB to follow
the inferior across system calls like execl() and friends.  While this
is cool, HP's original implemention put it inside #ifdef HPUXHPPA,
which is a no-no.  So one way to fix this would be declare all the
code nonportable and move it to hppah-nat.c.  However, I'm sure that
other configs (Linux anyone?) would like to have this capability,
so I'd like to keep the code generic and just not have it activate
if the config doesn't support.

So I tweaked follow_exec to only run if exec following is available,
but then ran into an interesting nonportability:

 /* We've followed the inferior through an exec.  Therefore, the
     inferior has essentially been killed & reborn. */
  gdb_flush (gdb_stdout);
  target_mourn_inferior ();
  inferior_pid = saved_pid;   /* Because mourn_inferior resets inferior_pid. */
  push_target (&child_ops);
  
  /* That a.out is now the one to use. */
  exec_file_attach (execd_pathname, 0);

The problem is so obvious that anyone on this list should see it right
away :-), but I have to admit I didn't see it until the compiler
complained; child_ops only exists for certain native configs.  What
this code *should* be doing is to push whatever the run target was
before the mourn_inferior call - but I don't think a create_inferior
is quite right, because it does too many other things as well.

So I'm thinking about using this code:

  /* We've followed the inferior through an exec.  Therefore, the
     inferior has essentially been killed & reborn. */
  /* Collect the run target in effect */
  tgt = find_default_run_target ("run");
  gdb_flush (gdb_stdout);
  target_mourn_inferior ();
  inferior_pid = saved_pid;   /* Because mourn_inferior resets inferior_pid. */
  push_target (tgt);
  
  /* That a.out is now the one to use. */
  exec_file_attach (execd_pathname, 0);

However, find_default_run_target is normally a private function used by
other things in target.c, so to make this work, it has to be exported.
It also doesn't seem really reliable, and that maybe a custom-written
function would be more appropriate.

Anyway, before going further, I'd like to hear what people think about
this.

							Stan