From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 31-MAY-1991 04:10:57.73
To:	ARISIA::EVERHART
CC:	
Subj:	Re: How do you run an executable with /nodebug and arguments?

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.99)
	 id AA02838; Fri, 31 May 91 03:42:43 EDT
Received: From ucbvax.Berkeley.EDU ([128.32.133.1]) by CRVAX.SRI.COM with TCP; Thu, 30 MAY 91 16:59:34 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA06905; Thu, 30 May 91 16:44:27 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 30 May 91 18:35:25 GMT
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ra!uvaarpa!software.org!stluka@ucbvax.Berkeley.EDU  (Fred Stluka)
Organization: Software Productivity Consortium, Herndon VA
Subject: Re: How do you run an executable with /nodebug and arguments?
Message-Id: <1991May30.183525.28868@software.org>
References: <1991May28.142214.17958@athena.mit.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <1991May28.142214.17958@athena.mit.edu> mlevin@jade.tufts.edu writes:

> My question is, is there any way I can also specify /debug or /nodebug?
> That is, run a program linked with the debugger, without invoking it, 
> and still eing able to give the program command-line arguments?

A good trick was posted here a while back.  It is a program 
which changes the switch inside the executable which controls
whether the Debugger gets control or not at startup.

I use it all the time.

The code is appended below.  Enjoy!

--Fred

Fred Stluka                              Internet: stluka@software.org
Software Productivity Consortium         UUNET:    ...!uunet!software!stluka
2214 Rock Hill Rd, Herndon VA 22070 USA 

--------------------------------------------------------------------------------

/*
Path: mucs!mupsy!ukc!mcvax!uunet!convex!killer!mit-eddie!bu-cs!gjc
From: gjc@bu-cs.BU.EDU (George J. Carrette)
Newsgroups: comp.os.vms
Subject: little single-message source postings.
Message-ID: <26744@bu-cs.BU.EDU>
Date: 16 Dec 88 21:05:30 GMT
Organization: Boston U. Comp. Sci.
Lines: 85

*/
/* SETDEBUG.C 2-JUN-88 George Carrette (gjc@bu-it.bu.edu)
   [NOTE: Public domain, unsupported, use at own risk]

   Development work was supported by
   Paradigm Associates Inc. 29 Putnam Ave, Suit 6. 
   Cambridge MA 02139. 617-492-6079
       and
   Mitech Corporation, 74 Junction Square.
   Concord MA 01742. 508-371-2002.
 */
/*
 * Altered by R.Marshall (rmarshall@cs.man.ac.uk)
 * so that a default extension of .exe is provided
 * Should use sys$parse (eventually!)
 */

/* It is useful to be able to build an executable with LINK/DEBUG
   so that the image has debugging information and lib$signal(SS$_DEBUG) 
   will enter the VMS debugger. However, we may not want to actually
   start up in the debugger, and cannot always use run/nodebug.
   This program can set the IHD$V_LNKDEBUG flag back to 0, so that
   running the program will not start up in the debugger.

   Process dumps created by SET PROCESS/DUMP are 100 times more useful
   when the executables were created with LINK/DEBUG.

   This can also be used to debug programs you have the executables
   for but not the sources, when RUN/DEBUG is not suitable. Because it
   can set the debug flag back to 1. Toggling back and forth is also useful.

   I picked up this trick from the VAX/NIL (MIT's VAX LISP) project
   which was original was coded in BLISS.

   Usage:
	$ debug_tog :== $device:[directory]debug_tog.exe
	$ debug_tog file.exe	    ! Toggle debug switch
	$ debug_tog file.exe 1	    ! Set debug switch on
	$ debug_tog file.exe 0	    ! Set debug switch off
 */

#include <stdio.h>
#include <errno.h>

/* these were gotten with lib/extract=$IHDDEF sys$library:lib.mlb */

#define IHD$L_LNKFLAGS	32
#define	IHD$V_LNKDEBUG	0
#define	IHD$V_LNKNOTFR	1
#define	IHD$V_NOP0BUFS	2
#define	IHD$V_PICIMG	3
#define	IHD$V_P0IMAGE	4
#define	IHD$V_DBGDMT	5
#define	IHD$M_LNKDEBUG	1
#define	IHD$M_LNKNOTFR	2
#define	IHD$M_NOP0BUFS	4
#define	IHD$M_PICIMG	8
#define	IHD$M_P0IMAGE	16
#define	IHD$M_DBGDMT	32
#define IHD$S_IHDDEF	512

main(argc,argv)
 int argc; char **argv;
{
 FILE *f;
 unsigned char ihd[IHD$S_IHDDEF];
 char namebuff[512];
 char *fname;
 long *lnkflags;
 int j,k;
 if (argc < 2) {printf("setdebug <filename> [flag]\n");exit(1);};
 fname = (char *) malloc(strlen(argv[1]) + 5);
 if (!(f = fopen(argv[1],"rb"))) {
  (void) strcpy(fname,argv[1]);
  (void) strcat(fname,".exe");
  if (!(f = fopen(fname,"rb"))) {
  perror(argv[1]);exit(vaxc$errno);}};
 if (fgetname(f,namebuff) == 0) {perror(argv[1]);exit(vaxc$errno);}
 printf("Existing IHD of %s\n",namebuff);
 for(j=0;j<IHD$S_IHDDEF;++j) ihd[j] = getc(f);
 lnkflags = &(ihd[IHD$L_LNKFLAGS]);
 printf("LNKFLAGS = %8X\n",*lnkflags);
 printf("LNKDEBUG = %d\n",1 & (*lnkflags >> IHD$V_LNKDEBUG));
 printf("LNKNOTFR = %d\n",1 & (*lnkflags >> IHD$V_LNKNOTFR));
 printf("NOP0BUFS = %d\n",1 & (*lnkflags >> IHD$V_NOP0BUFS));
 printf("PICIMG   = %d\n",1 & (*lnkflags >> IHD$V_PICIMG));
 printf("P0IMAGE  = %d\n",1 & (*lnkflags >> IHD$V_P0IMAGE));
 printf("DBGDMT   = %d\n",1 & (*lnkflags >> IHD$V_DBGDMT));
 fclose(f);
 if (argc == 3)
  {sscanf(argv[2],"%d",&k);
   printf("modifying file to have LNKDEBUG = %d\n",k);
   if (k == 0) *lnkflags &= ~IHD$M_LNKDEBUG; else *lnkflags |= IHD$M_LNKDEBUG;
   /*|*/
   printf("LNKFLAGS = %8X\n",*lnkflags);
   if (!(f = fopen(namebuff,"rb+"))) {perror(namebuff);exit(vaxc$errno);}
   for(j=0;j<IHD$S_IHDDEF;++j) putc(ihd[j],f);
   fclose(f);
  }
}

