From:	AITGW::"MACRO32@WKUVX1.BITNET" 10-MAR-1992 11:22:17.65
To:	"macro32" <macro32%wkuvx1.bitnet@cunyvm.cuny.edu>
CC:	
Subj:	debug flags

Received: by AITGW.DECnet (utk-mail11 v1.5) ; Tue, 10 Mar 92 11:21:58 EST
Received: from ukcc.uky.edu by aitgw.ge.com (5.65/GE Gateway 1.5)
	id AA27787; Tue, 10 Mar 92 11:21:52 -0500
Message-Id: <9203101621.AA27787@aitgw.ge.com>
Received: from ukcc.uky.edu by UKCC.uky.edu (IBM VM SMTP V2R2)
   with BSMTP id 2162; Tue, 10 Mar 92 11:15:18 EST
Received: from UKCC by ukcc.uky.edu (Mailer R2.08) with BSMTP id 6790; Tue, 10
 Mar 92 11:15:16 EST
Received: from WKUVX1.BITNET by ukcc.uky.edu (Mailer R2.08) with BSMTP id 6686;
 Tue, 10 Mar 92 11:12:44 EST
Errors-To: MacroMan@WKUVX1.BITNET
X-Listname: "VMS Internals, MACRO, and BLISS Discussions"
    <MACRO32@WKUVX1.BITNET>
Received: from CUNYVM.BITNET (MAILER) by WKUVX1 (MX V3.0A) with BSMTP; Tue, 10
          Mar 1992 09:45:29 CST
Received: from CUNYVM by CUNYVM.BITNET (Mailer R2.08) with BSMTP id 2429; Tue,
          10 Mar 92 10:40:28 EST
Received: from argos.jdssc.dca.mil by CUNYVM.CUNY.EDU (IBM VM SMTP V2R2) with
          TCP; Tue, 10 Mar 92 10:40:22 EST
Received: from aeneas.jdssc.dca.mil by argos.jdssc.dca.mil with SMTP ; Tue, 10
          Mar 92 10:37:50 EST
Date: 10 Mar 92 10:37:00 EST
From: "Bob George" <BOB@aeneas.jdssc.dca.mil>
Reply-To: MACRO32@WKUVX1.BITNET
Subject: debug flags
To: "macro32" <macro32%wkuvx1.bitnet@cunyvm.cuny.edu>
 
Subj:   a patch for debug
 
>hi to all of you out there (in here?)
>i heard of a possibility to patch an exe file (linked with /nodeb)
>to invoke debugger when executed.Can anyone give me some hint or
>a reference (an example of a patch is even more prefered).
 
Here's a small C program to toggle the debug flag on an executable.
                                    bob
 
+---------------------------------------------------------------------+
|      Bob George       Internet:  BOB@AENEAS.JDSSC.DCA.MIL           |
|      Disclaimer:      Opinions expressed are mine and mine only.    |
+---------------------------------------------------------------------+
--------------------------------------------------------------------------------
 
/*
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);
  }
}
 
 
 
