[RFC] Support exec tracing on GNU/Linux and HP-UX

Joel Brobecker brobecker@adacore.com
Fri Dec 21 16:04:00 GMT 2007


Hi Daniel,

> > Actually, not so simple, because the EXEC event counts as
> > one of the 2 events we expect during the startup phase. So the EXEC
> > events must be activated at startup-time. The only option I can see
> > at this point is to add a static global that is set during the startup
> > phase, and would then cause the EXEC event to be translated into a
> > SIGTRAP vulgaris when set.  Another approach would be to have infrun
> > treat EXEC events as SIGTRAPs during the startup phase. I don't think
> > the second option is easier to implement (infrun needs to find out
> > whether we're in the middle of startup or not, and then we need to
> > redirect EXEC events into SIGTRAP events). What do you think of
> > option 1?
> 
> Actually, I like option 2 better.  Maybe we can push pending_execs
> into a global similar to the (slightly different, though unused at
> present) inferior_ignoring_leading_exec_events?

You may not remember as this was a couple of months ago (already!),
but we had determined at the time that we could not easily disable
exec events during inferior startup on HP/UX.  So we decided to find
a way to treat these exec events as SIGTRAPs.

Here is a possible solution that does not involve the use of a global.
It involves the addition of a new parameter to wait_for_inferior. Most
of the time, we will set it so that events are not handled as is. But
during the inferior startup sequence, we  tell it to translate EXEC
events into SIGTRAPs.  I should probably add a comment at the beginning
of wait_for_inferior explaining the intent of that new parameter -
I will do that if you like the idea.

2007-12-21  Joel Brobecker  <brobecker@adacore.com>

        * infrun.c (wait_for_inferior): Add treat_exec_as_sigtrap parameter
        and use it.
        (proceed, start_remote): Update call to wait_for_inferior.
        * inferior.h (wait_for_inferior): Update declaration.
        * fork-child.c, infcmd.c, solib-irix.c, solib-osf.c, solib-sunos.c,
        solib-svr4.c, win32-nat.c: Update calls to wait_for_inferior.
        * inf-ttrace.c (inf_ttrace_wait): Report TTEVT_EXEC events as
        TARGET_WAITKIND_EXECD instead of TARGET_WAITKIND_STOPPED.

Tested on hppa-hpux, no regression.

Another option along these lines that would avoid touching most of
the files is to renaming wait_for_inferior into wait_for_inferior_1,
and then have two new routines: wait_for_inferior that would call
wait_for_inferior_1 with treat_exec_as_sigtrap=0, and then
wait_for_inferior_during_startup that would call wait_for_inferior_1
with treat_exec_as_sigtrap=1. I don't think that the change is large
enough to be worth it. I don't think I've missed any call to
wfi(), and the change itself is completely straightforward.

What do you think of the approach? I'll re-apply your patch on top
of mine, and see what we get now.

Thanks,
-- 
Joel
-------------- next part --------------
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.260
diff -u -p -r1.260 infrun.c
--- infrun.c	19 Dec 2007 05:16:35 -0000	1.260
+++ infrun.c	21 Dec 2007 15:12:45 -0000
@@ -852,7 +852,7 @@ proceed (CORE_ADDR addr, enum target_sig
      does not support asynchronous execution. */
   if (!target_can_async_p ())
     {
-      wait_for_inferior ();
+      wait_for_inferior (0);
       normal_stop ();
     }
 }
@@ -882,7 +882,7 @@ start_remote (int from_tty)
      target_open() return to the caller an indication that the target
      is currently running and GDB state should be set to the same as
      for an async run. */
-  wait_for_inferior ();
+  wait_for_inferior (0);
 
   /* Now that the inferior has stopped, do any bookkeeping like
      loading shared libraries.  We want to do this before normal_stop,
@@ -995,14 +995,16 @@ static void print_stop_reason (enum infe
    should be left stopped and GDB should read more commands.  */
 
 void
-wait_for_inferior (void)
+wait_for_inferior (int treat_exec_as_sigtrap)
 {
   struct cleanup *old_cleanups;
   struct execution_control_state ecss;
   struct execution_control_state *ecs;
 
   if (debug_infrun)
-    fprintf_unfiltered (gdb_stdlog, "infrun: wait_for_inferior\n");
+    fprintf_unfiltered
+      (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
+       treat_exec_as_sigtrap);
 
   old_cleanups = make_cleanup (delete_step_resume_breakpoint,
 			       &step_resume_breakpoint);
@@ -1034,6 +1036,13 @@ wait_for_inferior (void)
       else
 	ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp);
 
+      if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
+        {
+          xfree (ecs->ws.value.execd_pathname);
+          ecs->ws.kind = TARGET_WAITKIND_STOPPED;
+          ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
+        }
+
       /* Now figure out what to do with the result of the result.  */
       handle_inferior_event (ecs);
 
Index: inferior.h
===================================================================
RCS file: /cvs/src/src/gdb/inferior.h,v
retrieving revision 1.85
diff -u -p -r1.85 inferior.h
--- inferior.h	23 Aug 2007 18:08:35 -0000	1.85
+++ inferior.h	21 Dec 2007 15:02:58 -0000
@@ -166,7 +166,7 @@ extern CORE_ADDR signed_pointer_to_addre
 extern void address_to_signed_pointer (struct type *type, gdb_byte *buf,
 				       CORE_ADDR addr);
 
-extern void wait_for_inferior (void);
+extern void wait_for_inferior (int treat_exec_as_sigtrap);
 
 extern void fetch_inferior_event (void *);
 
Index: fork-child.c
===================================================================
RCS file: /cvs/src/src/gdb/fork-child.c,v
retrieving revision 1.35
diff -u -p -r1.35 fork-child.c
--- fork-child.c	23 Aug 2007 18:08:31 -0000	1.35
+++ fork-child.c	21 Dec 2007 15:02:40 -0000
@@ -419,7 +419,7 @@ startup_inferior (int ntraps)
     {
       /* Make wait_for_inferior be quiet. */
       stop_soon = STOP_QUIETLY;
-      wait_for_inferior ();
+      wait_for_inferior (1);
       if (stop_signal != TARGET_SIGNAL_TRAP)
 	{
 	  /* Let shell child handle its own signals in its own way.
Index: infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.164
diff -u -p -r1.164 infcmd.c
--- infcmd.c	15 Nov 2007 06:24:17 -0000	1.164
+++ infcmd.c	21 Dec 2007 15:02:58 -0000
@@ -1908,7 +1908,7 @@ attach_command (char *args, int from_tty
      way for handle_inferior_event to reset the stop_signal variable
      after an attach, and this is what STOP_QUIETLY_NO_SIGSTOP is for.  */
   stop_soon = STOP_QUIETLY_NO_SIGSTOP;
-  wait_for_inferior ();
+  wait_for_inferior (0);
   stop_soon = NO_STOP_QUIETLY;
 #endif
 
Index: solib-irix.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-irix.c,v
retrieving revision 1.16
diff -u -p -r1.16 solib-irix.c
--- solib-irix.c	24 Oct 2007 21:15:35 -0000	1.16
+++ solib-irix.c	21 Dec 2007 15:03:38 -0000
@@ -438,7 +438,7 @@ irix_solib_create_inferior_hook (void)
   do
     {
       target_resume (pid_to_ptid (-1), 0, stop_signal);
-      wait_for_inferior ();
+      wait_for_inferior (0);
     }
   while (stop_signal != TARGET_SIGNAL_TRAP);
 
Index: solib-osf.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-osf.c,v
retrieving revision 1.12
diff -u -p -r1.12 solib-osf.c
--- solib-osf.c	22 Sep 2007 19:33:31 -0000	1.12
+++ solib-osf.c	21 Dec 2007 15:03:39 -0000
@@ -324,7 +324,7 @@ osf_solib_create_inferior_hook (void)
   do
     {
       target_resume (minus_one_ptid, 0, stop_signal);
-      wait_for_inferior ();
+      wait_for_inferior (0);
     }
   while (stop_signal != TARGET_SIGNAL_TRAP);
 
Index: solib-sunos.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-sunos.c,v
retrieving revision 1.25
diff -u -p -r1.25 solib-sunos.c
--- solib-sunos.c	23 Aug 2007 18:08:38 -0000	1.25
+++ solib-sunos.c	21 Dec 2007 15:03:40 -0000
@@ -765,7 +765,7 @@ sunos_solib_create_inferior_hook (void)
   do
     {
       target_resume (pid_to_ptid (-1), 0, stop_signal);
-      wait_for_inferior ();
+      wait_for_inferior (0);
     }
   while (stop_signal != TARGET_SIGNAL_TRAP);
   stop_soon = NO_STOP_QUIETLY;
Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.79
diff -u -p -r1.79 solib-svr4.c
--- solib-svr4.c	24 Oct 2007 21:22:08 -0000	1.79
+++ solib-svr4.c	21 Dec 2007 15:03:40 -0000
@@ -1364,7 +1364,7 @@ svr4_solib_create_inferior_hook (void)
   do
     {
       target_resume (pid_to_ptid (-1), 0, stop_signal);
-      wait_for_inferior ();
+      wait_for_inferior (0);
     }
   while (stop_signal != TARGET_SIGNAL_TRAP);
   stop_soon = NO_STOP_QUIETLY;
Index: win32-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/win32-nat.c,v
retrieving revision 1.143
diff -u -p -r1.143 win32-nat.c
--- win32-nat.c	6 Dec 2007 11:17:03 -0000	1.143
+++ win32-nat.c	21 Dec 2007 15:04:02 -0000
@@ -1517,7 +1517,7 @@ do_initial_win32_stuff (DWORD pid)
   while (1)
     {
       stop_after_trap = 1;
-      wait_for_inferior ();
+      wait_for_inferior (0);
       if (stop_signal != TARGET_SIGNAL_TRAP)
 	resume (0, stop_signal);
       else
Index: inf-ttrace.c
===================================================================
RCS file: /cvs/src/src/gdb/inf-ttrace.c,v
retrieving revision 1.24
diff -u -p -r1.24 inf-ttrace.c
--- inf-ttrace.c	18 Sep 2007 12:42:22 -0000	1.24
+++ inf-ttrace.c	21 Dec 2007 15:12:45 -0000
@@ -896,10 +896,6 @@ inf_ttrace_wait (ptid_t ptid, struct tar
 #endif
 
     case TTEVT_EXEC:
-      /* FIXME: kettenis/20051029: GDB doesn't really know how to deal
-	 with TARGET_WAITKIND_EXECD events yet.  So we make it look
-	 like a SIGTRAP instead.  */
-#if 0
       ourstatus->kind = TARGET_WAITKIND_EXECD;
       ourstatus->value.execd_pathname =
 	xmalloc (tts.tts_u.tts_exec.tts_pathlen + 1);
@@ -908,10 +904,6 @@ inf_ttrace_wait (ptid_t ptid, struct tar
 		  tts.tts_u.tts_exec.tts_pathlen, 0) == -1)
 	perror_with_name (("ttrace"));
       ourstatus->value.execd_pathname[tts.tts_u.tts_exec.tts_pathlen] = 0;
-#else
-      ourstatus->kind = TARGET_WAITKIND_STOPPED;
-      ourstatus->value.sig = TARGET_SIGNAL_TRAP;
-#endif
       break;
 
     case TTEVT_EXIT:


More information about the Gdb-patches mailing list