Subject: Re: make: print real reason for exec failure
To: None <root@garbled.net>
From: Simon J. Gerraty <sjg@quick.com.au>
List: tech-toolchain
Date: 05/31/2001 17:38:40
OK, diff below makes -dx run sh -x.
This works nicely for compat mode, but I can't work out how to
suppress all the duplicate '+'s you get in -jN mode.  They are caused
by all the set -, set -v's etc.

Again the diffs are against bmake, if people like it I'll work it into
our make.

--sjg

Index: make.h
===================================================================
RCS file: /share/cvsroot/bmake/make.h,v
retrieving revision 1.10
diff -u -p -r1.10 make.h
--- make.h	2001/05/29 10:00:11	1.10
+++ make.h	2001/05/31 21:55:35
@@ -404,6 +404,7 @@ extern int debug;
 #define	DEBUG_TARG	0x0100
 #define	DEBUG_VAR	0x0200
 #define DEBUG_FOR	0x0400
+#define DEBUG_SHELL	0x0800
 
 #if defined(__STDC__) || defined(__cplusplus) || defined(_AIX)
 #define CONCAT(a,b)	a##b
Index: main.c
===================================================================
RCS file: /share/cvsroot/bmake/main.c,v
retrieving revision 1.15
diff -u -p -r1.15 main.c
--- main.c	2001/05/29 10:03:10	1.15
+++ main.c	2001/05/31 21:55:57
@@ -322,6 +322,9 @@ rearg:	while((c = getopt(argc, argv, OPT
 				case 'v':
 					debug |= DEBUG_VAR;
 					break;
+				case 'x':
+					debug |= DEBUG_SHELL;
+					break;
 				default:
 					(void)fprintf(stderr,
 				"%s: illegal argument to d option -- %c\n",
Index: compat.c
===================================================================
RCS file: /share/cvsroot/bmake/compat.c,v
retrieving revision 1.11
diff -u -p -r1.11 compat.c
--- compat.c	2001/05/30 05:06:10	1.11
+++ compat.c	2001/05/31 22:32:07
@@ -268,7 +268,10 @@ CompatRunCommand (cmdp, gnp)
 	 */
 	static char	*shargv[4] = { "/bin/sh" };
 
-	shargv[1] = (errCheck ? "-ec" : "-c");
+	if (DEBUG(SHELL))
+		shargv[1] = (errCheck ? "-exc" : "-xc");
+	else
+		shargv[1] = (errCheck ? "-ec" : "-c");
 	shargv[2] = cmd;
 	shargv[3] = (char *)NULL;
 	av = shargv;
Index: job.c
===================================================================
RCS file: /share/cvsroot/bmake/job.c,v
retrieving revision 1.9
diff -u -p -r1.9 job.c
--- job.c	2001/05/29 10:03:09	1.9
+++ job.c	2001/06/01 00:35:24
@@ -722,6 +722,12 @@ JobPrintCommand(cmdp, jobp)
 	}
     }
 
+    if (DEBUG(SHELL) && strcmp(shellName, "sh") == 0 &&
+	(job->flags & JOB_TRACED) == 0) {
+	    DBPRINTF("set -x\n", "");
+	    job->flags |= JOB_TRACED;
+    }
+    
     if ((cp = Check_Cwd_Cmd(cmd)) != NULL) {
 	    DBPRINTF("cd %s; ", cp);
     }		    
@@ -1295,6 +1301,8 @@ JobExec(job, argv)
 {
     int	    	  cpid;	    	/* ID of new child */
 
+    job->flags &= ~JOB_TRACED;
+    
     if (DEBUG(JOB)) {
 	int 	  i;
 
@@ -2367,6 +2375,7 @@ Job_CatchChildren(block)
 	    }
 	} else {
 	    job = (Job *) Lst_Datum(jnode);
+	    Job_CatchOutput();
 	    (void) Lst_Remove(jobs, jnode);
 	    nJobs -= 1;
 #ifdef REMOTE