Article 134673 of comp.os.vms:
Path: nntpd.lkg.dec.com!crl.dec.com!crl.dec.com!caen!kuhub.cc.ukans.edu!zippy.dct.ac.uk!btnet!newsfeed.internetmci.com!news.kei.com!simtel!news3.noc.netcom.net!news.pic.net!news.tachyon.com!wayne
Newsgroups: comp.os.vms
Subject: RE: DEBUG question ?
Message-ID: <1995Nov21.155814.31@tachyon.com>
From: wayne@tachyon.com (Wayne Sewell)
Date: 21 Nov 95 15:58:14 CST
References: <9511170542.AA14833@uu3.psi.com>
Organization: Tachyon Software Consulting
Lines: 259

In article <9511170542.AA14833@uu3.psi.com>, Jerry Leichter <leichter@lrw.com> writes:
> 	It is possible to overcome  the default behavior of VMS for the RUN
> 	command,  i.e.  after I have compiled and linked a program with /DEBUG
> 	, the program can be started --WITHOUT debugger-- by the RUN command,
> 	while retaining the  possibility of CTRL/Y+DEBUG ?
> 
> 	Of course the goal is to pass arguments to the program by foreign
> 	command definition without automatic debugger startup.
> 
[stuff deleted]

> 
> The last time this question came up, someone - I think Wolfgang Moeller,
> posted a small program to do the same thing.  I *think*, but an not sure, that
> it worked on both VAXes and Alphas.  Unfortunately, I can't seem to figure out
> where I saved a copy of this message....


Wolfgang's version was DCL, and I noticed he posted it elsewhere in the thread.
If anyone is interested in a C version...

===============================================================================
#include <descrip.h>
#include <psldef.h>
#include <stdio.h>
#include <string.h>
#include <lib$routines.h>
#include <starlet.h>
#include <rms.h>


#ifdef __DECC	/* If this is DEC C */
#pragma extern_model save
#pragma extern_model globalvalue 
#ifdef __VAX	/* If this is the VAX */
extern int ihd$m_lnkdebug;
extern int ihd$l_lnkflags;
extern int ihd$c_length;
extern int sys$imgsta;
#else		/* Must be the AXP */
extern int eihd$m_lnkdebug;
extern int eihd$l_lnkflags;
extern int eihd$c_length;
extern int eiha$q_tfradr1;
#endif
#pragma extern_model restore
#else		/* Must be VAX C */
globalvalue ihd$m_lnkdebug;
globalvalue ihd$l_lnkflags;
globalvalue ihd$c_length;
globalvalue sys$imgsta;
#endif


#include <secdef.h>

#define program_region 0
#define control_region 1
#define global              SEC$M_GBL
#define writable_section    SEC$M_WRT
#define copy_on_reference   SEC$M_CRF
#define demand_zero         SEC$M_DZRO
#define permanent_section   SEC$M_PERM
#define no_overmap_of_pages SEC$M_NO_OVERMAP
#define expand_region       SEC$M_EXPREG
#define page_file_section   SEC$M_PAGFIL     
#define permanent_section   SEC$M_PERM






void do_the_mod(void *starting_addr)

{
int *intptr;
char *charptr;
int debug_mask;
int debug_is_on;

charptr = starting_addr;
#ifdef __VAX	/* If this is the VAX */
charptr += ihd$l_lnkflags;
debug_mask= ihd$m_lnkdebug;
#else		/* Must be the AXP */
charptr += eihd$l_lnkflags;
debug_mask= eihd$m_lnkdebug;
#endif
intptr = (int *) charptr;
printf("link flags = %x\n",*intptr);
debug_is_on = (*intptr & debug_mask);
if (debug_is_on) {
   printf("debug flag is set; turning off\n");
   *intptr &= ~debug_mask;
   }
else {
   printf("debug flag is off; turning on\n");
   *intptr |= debug_mask;
   }
printf("new link flags = %x\n",*intptr);
charptr = starting_addr;
#ifdef __VAX	/* If this is the VAX */
charptr += ihd$c_length;
intptr = (int *) charptr;
printf("vectors (before) = %08x, %08x, %08x\n",intptr[0],intptr[1],intptr[2]);
if (intptr[0] != sys$imgsta) {
   intptr[2] = intptr[1];
   intptr[1] = intptr[0];
   intptr[0] = sys$imgsta;
   }
printf("vectors (after) = %08x, %08x, %08x\n",intptr[0],intptr[1],intptr[2]);
#else		/* Must be the AXP */
charptr += eihd$c_length + eiha$q_tfradr1;
intptr = (int *) charptr;
printf("vectors (before) = %08x %08x,  %08x %08x,  %08x %08x\n",intptr[1],
		intptr[0],intptr[3],intptr[2],intptr[5],intptr[4]);
if ((intptr[0] != 0x0340) && (intptr[1] != 0x0ffffffff) ) {
   intptr[5] = intptr[3];
   intptr[4] = intptr[2];
   intptr[3] = intptr[1];
   intptr[2] = intptr[0];
   intptr[1] = 0x0ffffffff;
   intptr[0] = 0x0340;
   }
printf("vectors (after) = %08x %08x,  %08x %08x,  %08x %08x\n",intptr[1],
		intptr[0],intptr[3],intptr[2],intptr[5],intptr[4]);
#endif

}


int get_channel_from_file_name(char file_name[], int *chan)

{
/* Allocate the RMS user structures */
struct	FAB	the_fab; /* File Access Block */
struct	NAM	the_nam; /* name block */
int status;    	/* Check completion status of RMS operations */

/* Initialize RMS user structures for the file. */
the_fab  	   = cc$rms_fab;
the_fab.fab$l_fna = file_name;
the_fab.fab$b_fns = strlen (file_name);
the_fab.fab$b_fac = FAB$M_GET | FAB$M_PUT ;
the_fab.fab$l_nam = &the_nam;
the_fab.fab$l_fop = FAB$M_UFO ;

the_nam  = cc$rms_nam;

/* Open the file */
status =  sys$open (&the_fab,0,0);


if (!(status & 1)) return status;

*chan = the_fab.fab$l_stv;		/* channel number */
return status;
}



int create_and_map_global_section(char sect_file[],int access_mode,
			int relative_page_number,int page_count,
			int virtual_block_number,int protection,
			int page_fault_cluster,
			int flags, void *starting_addr, int length,
			void **actual_starting_addr, 
			int *actual_length)

{
int sts;
int inadr[2];
int retadr[2];
int file_channel_number;


lib$establish(lib$sig_to_ret);
sts = get_channel_from_file_name(sect_file,&file_channel_number);
if (!(sts & 1)) return sts;
inadr[0] = 0;

sts = sys$crmpsc(inadr,retadr,access_mode,flags,0,
		0,relative_page_number, file_channel_number,page_count, 
		virtual_block_number,protection,page_fault_cluster);

if (!(sts & 1)) return sts;

*actual_starting_addr = (void *) retadr[0];
*actual_length = retadr[1] - retadr[0] + 1;

return sts;
}  
  






int map_file_to_local_section(char file_name[],int start_block,
			int relative_page_number,int page_count,
			int virtual_block_number,int protection,
			int num_blocks, void *starting_addr,
			void **actual_starting_addr,
			int access_mode, int flags,
                        int *actual_number_of_blocks,int which_region)

{
int sts;
int actual_len;

flags = flags & (~(page_file_section));
sts = create_and_map_global_section(file_name,access_mode,
			relative_page_number,page_count,
			virtual_block_number,protection,0,
			flags, starting_addr, num_blocks * 512,
			actual_starting_addr,&actual_len);
*actual_number_of_blocks = actual_len / 512;
return sts;
}



int main (int argc, char **argv) 


{
char filename_string[2048];
int sts;
void *starting_addr;
int actual_number_of_blocks;
void *context;

strcpy(filename_string,argv[1]);
/* open the file for write access and get the channel */

sts = map_file_to_local_section(filename_string,0,0,1,0,0x0ffff,
			1, 0,&starting_addr,PSL$C_USER, 
			expand_region+writable_section,
                        &actual_number_of_blocks,program_region);

if (!(sts & 1)) return sts;
do_the_mod(starting_addr);
return sts;
}


===============================================================================

This program will toggle the flag every time you run it.

-- 
===============================================================================
Wayne Sewell, Tachyon Software Consulting  (214)553-9760   wayne@tachyon.com
http://www.tachyon.com/www/tachyon.html and wayne.html    pgp key via web/finger
Key fingerprint =  77 A5 C1 56 9C ED F1 8E  89 F9 27 3C 86 79 F7 1B 
===============================================================================
To Sharon: "If I said you had a beautiful body, would you hold it against me?"


