From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12743 invoked by alias); 5 Aug 2006 16:43:15 -0000 Received: (qmail 12733 invoked by uid 22791); 5 Aug 2006 16:43:13 -0000 X-Spam-Check-By: sourceware.org Received: from ip-85-160-210-8.eurotel.cz (HELO host0.dyn.jankratochvil.net) (85.160.210.8) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 05 Aug 2006 16:43:07 +0000 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.13.7/8.13.7) with ESMTP id k75GgG2f023870; Sat, 5 Aug 2006 18:42:17 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.13.7/8.13.7/Submit) id k75GfiOw023869; Sat, 5 Aug 2006 18:41:44 +0200 Date: Sat, 05 Aug 2006 16:43:00 -0000 From: Jan Kratochvil To: Mark Kettenis Cc: drow@false.org, gdb-patches@sourceware.org Subject: Re: [patch] Linux MAY_FOLLOW_EXEC #2 Message-ID: <20060805164144.GA23819@host0.dyn.jankratochvil.net> References: <20060614105510.GA12067@host0.dyn.jankratochvil.net> <20060614142552.GA15021@nevyn.them.org> <20060615203519.GA9603@host0.dyn.jankratochvil.net> <20060721181556.GA9150@lace.redhat.com> <20060721184421.GA22820@nevyn.them.org> <20060722123102.GA1936@lace.redhat.com> <20060724190332.GA13612@nevyn.them.org> <20060729185317.GA16200@host0.dyn.jankratochvil.net> <200607312038.k6VKchKj018729@elgar.sibelius.xs4all.nl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e" Content-Disposition: inline In-Reply-To: <200607312038.k6VKchKj018729@elgar.sibelius.xs4all.nl> User-Agent: Mutt/1.4.2.1i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-08/txt/msg00032.txt.bz2 --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 810 Hi Mark, On Mon, 31 Jul 2006 22:38:43 +0200, Mark Kettenis wrote: ... > That WNOHANG is wrong; In fact yes, the patch is more correct without that WNOHANG hack there. 2006-07-29 Jan Kratochvil * inf-ptrace.c (inf_ptrace_mourn_inferior): waitpid(2) only if there is valid inferior_ptid to wait for. * linux-fork.c (linux_fork_mourn_inferior): Ditto. * infrun.c (follow_exec): Unconditionally enabled by MAY_FOLLOW_EXEC. Provide restoration of exec_bfd and symfile_objfile for any new "run". * linux-thread-db.c (thread_db_wait): Handle TARGET_WAITKIND_EXECD. * linux-thread-db.c (thread_db_mourn_inferior): Turn off threading. * foll-exec.exp: Uncoditionally enabled for all platforms. Relaxed regex to apply besides HP-UX also for GNU/Linux backtrace. Thanks, Jan --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-6.5-follow-exec-v2.patch" Content-length: 7255 Index: inf-ptrace.c =================================================================== RCS file: /cvs/src/src/gdb/inf-ptrace.c,v retrieving revision 1.32 diff -u -p -r1.32 inf-ptrace.c --- inf-ptrace.c 24 Jan 2006 22:34:34 -0000 1.32 +++ inf-ptrace.c 5 Aug 2006 15:49:22 -0000 @@ -167,7 +167,8 @@ inf_ptrace_mourn_inferior (void) Do not check whether this succeeds though, since we may be dealing with a process that we attached to. Such a process will only report its exit status to its original parent. */ - waitpid (ptid_get_pid (inferior_ptid), &status, 0); + if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution) + waitpid (ptid_get_pid (inferior_ptid), &status, 0); unpush_target (ptrace_ops_hack); generic_mourn_inferior (); Index: infrun.c =================================================================== RCS file: /cvs/src/src/gdb/infrun.c,v retrieving revision 1.213 diff -u -p -r1.213 infrun.c --- infrun.c 22 Jul 2006 14:48:03 -0000 1.213 +++ infrun.c 5 Aug 2006 15:49:28 -0000 @@ -47,6 +47,7 @@ #include "language.h" #include "solib.h" #include "main.h" +#include "objfiles.h" #include "gdb_assert.h" #include "mi/mi-common.h" @@ -109,10 +110,10 @@ int sync_execution = 0; static ptid_t previous_inferior_ptid; /* This is true for configurations that may follow through execl() and - similar functions. At present this is only true for HP-UX native. */ + similar functions. */ #ifndef MAY_FOLLOW_EXEC -#define MAY_FOLLOW_EXEC (0) +#define MAY_FOLLOW_EXEC (1) #endif static int may_follow_exec = MAY_FOLLOW_EXEC; @@ -375,6 +376,37 @@ follow_inferior_reset_breakpoints (void) insert_breakpoints (); } +static void +follow_exec_restore_execfile (void *filename_new_untyped) +{ + char *filename_new = filename_new_untyped; + + /* filename_new == NULL is not expected. */ + if (filename_new == NULL && exec_bfd != NULL) + exec_file_clear (0); + /* exec_bfd == NULL is not expected. */ + if (filename_new != NULL && + (exec_bfd == NULL || strcmp (get_exec_file (0), filename_new))) + exec_file_attach (filename_new, 0); + + free (filename_new); +} + +static void +follow_exec_restore_symfile (void *filename_new_untyped) +{ + char *filename_new = filename_new_untyped; + + /* symfile_objfile == NULL is not expected. */ + if (filename_new == NULL && symfile_objfile != NULL) + symbol_file_clear (0); + if (filename_new != NULL && (symfile_objfile == NULL + || strcmp (symfile_objfile->name, filename_new))) + symbol_file_add_main (filename_new, 0); + + free (filename_new); +} + /* EXECD_PATHNAME is assumed to be non-NULL. */ static void @@ -382,6 +414,7 @@ follow_exec (int pid, char *execd_pathna { int saved_pid = pid; struct target_ops *tgt; + struct objfile *objfile, *objfile_temp; if (!may_follow_exec) return; @@ -427,6 +460,32 @@ follow_exec (int pid, char *execd_pathna error (_("Could find run target to save before following exec")); gdb_flush (gdb_stdout); + + /* During the common "run" bare command we should run again the original + * program spawning us. Stacking ordering is correct this way. */ + make_run_cleanup (follow_exec_restore_execfile, + (!exec_bfd ? NULL : xstrdup (exec_bfd->filename))); + make_run_cleanup (follow_exec_restore_symfile, (!symfile_objfile ? NULL : + xstrdup (symfile_objfile->name))); + + /* As symbol_file_add_main()->thread_db_new_objfile()->check_for_thread_db() + * would fine already loaded libpthread.so while the threading structures + * would not be yet initialized for this early inferior. + * Call before target_mourn_inferior() as it will breakpoint_re_set(). */ +#ifdef CLEAR_SOLIB + CLEAR_SOLIB (); +#else + clear_solib (); +#endif + /* Do not: symbol_file_clear()->clear_symtab_users()->breakpoint_re_set(). */ + ALL_OBJFILES_SAFE (objfile, objfile_temp) + { + free_objfile (objfile); + } + symfile_objfile = NULL; + + /* Avoid stucked waitpid(2) as PID inferior_ptid is still running. */ + inferior_ptid = null_ptid; target_mourn_inferior (); inferior_ptid = pid_to_ptid (saved_pid); /* Because mourn_inferior resets inferior_ptid. */ Index: linux-fork.c =================================================================== RCS file: /cvs/src/src/gdb/linux-fork.c,v retrieving revision 1.7 diff -u -p -r1.7 linux-fork.c --- linux-fork.c 27 Apr 2006 23:03:41 -0000 1.7 +++ linux-fork.c 5 Aug 2006 15:49:45 -0000 @@ -366,7 +366,8 @@ linux_fork_mourn_inferior (void) only report its exit status to its original parent. */ int status; - waitpid (ptid_get_pid (inferior_ptid), &status, 0); + if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution) + waitpid (ptid_get_pid (inferior_ptid), &status, 0); /* OK, presumably inferior_ptid is the one who has exited. We need to delete that one from the fork_list, and switch Index: linux-thread-db.c =================================================================== RCS file: /cvs/src/src/gdb/linux-thread-db.c,v retrieving revision 1.19 diff -u -p -r1.19 linux-thread-db.c --- linux-thread-db.c 2 Aug 2006 10:24:00 -0000 1.19 +++ linux-thread-db.c 5 Aug 2006 15:50:49 -0000 @@ -884,6 +884,10 @@ thread_db_wait (ptid_t ptid, struct targ return pid_to_ptid (GET_PID (ptid)); } + /* Threading structures got reset. Return as nonthreaded. */ + if (ourstatus->kind == TARGET_WAITKIND_EXECD) + return pid_to_ptid (GET_PID (ptid)); + if (ourstatus->kind == TARGET_WAITKIND_STOPPED && ourstatus->value.sig == TARGET_SIGNAL_TRAP) /* Check for a thread event. */ @@ -975,6 +979,9 @@ thread_db_mourn_inferior (void) the inferior, so that we don't try to uninsert them. */ remove_thread_event_breakpoints (); + /* Destroy thread info; it's no longer valid. */ + init_thread_list (); + /* Detach thread_db target ops. */ unpush_target (&thread_db_ops); using_thread_db = 0; Index: testsuite/gdb.base/foll-exec.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/foll-exec.exp,v retrieving revision 1.2 diff -u -p -r1.2 foll-exec.exp --- testsuite/gdb.base/foll-exec.exp 6 Mar 2001 08:21:50 -0000 1.2 +++ testsuite/gdb.base/foll-exec.exp 5 Aug 2006 15:50:50 -0000 @@ -45,12 +45,6 @@ if { [gdb_compile "${srcdir}/${subdir}/ } -# Until "catch exec" is implemented on other targets... -# -if ![istarget "hppa*-hp-hpux*"] then { - continue -} - proc zap_session {} { global gdb_prompt global binfile @@ -212,7 +206,9 @@ proc do_exec_tests {} { setup_xfail hppa2.0w-hp-hpux* CLLbs16760 send_gdb "continue\n" gdb_expect { - -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\ + # It is OS dependent and no symbols may be found, GNU/Linux has "_start" + # while HP-UX has " in .START..*$gdb_prompt" etc. + -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .*$gdb_prompt $"\ {pass "hit catch exec"} -re "$gdb_prompt $" {fail "hit catch exec"} timeout {fail "(timeout) hit catch exec"} --cNdxnHkX5QqsyA0e--