[ From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 26-AUG-1990 04:08:42.94  To:	MRGATE::"ARISIA::EVERHART" CC:	4 Subj:	Re(2): debugger: DBG$INPUT, DBG$OUTPUT logical  * Received:  by crdgw1.ge.com (5.57/GE 1.70)) 	 id AA06563; Sun, 26 Aug 90 03:53:51 EDT / Message-Id:  <9008260753.AA06563@crdgw1.ge.com> Z Received: From SOL1.GPS.CALTECH.EDU by CRVAX.SRI.COM with TCP; Sun, 26 AUG 90 00:44:56 PDT Date: 25 Aug 1990 23:39:53 EST( From: Carl.J.Lydick@SOL1.GPS.CALTECH.EDU4 To: uswat!jbw@boulder.colorado.edu, info-vax@sri.com7 Subject: Re(2): debugger: DBG$INPUT, DBG$OUTPUT logical 8 X-Vms-Original-To: INET%"uswat!jbw@boulder.colorado.edu"    M  > 1.  Does anyone have an example of using RMS to change the protection of a   > *device*?  O I don't think RMS will do this for you.  The only sort of device I know of that N can have its protection changed other than by using the SET PROTECTION command
 is a mailbox.   L  > 2.  Alternatively, if an image is installed with priveleges, do processesI  > it spawn have the same priveleges?  (This way, I could spawn a DCL SET E  > PROTECTION command.  Does anyone have an example of spawning a DCL   > command?)  O Yes.  The subprocess inherits the privs that belonged to the parent process (as K opposed to the image it was running) as its default privs;  it inherits any F privs that the parent had as a result of the image used to spawn beingM installed with privs as authorized privs (i.e., if you issue a SHOW PROC/PRIV N command from the spawned process, you'll see the same privs the parent processL had before the privileged image was activated;  however, if you then issue aO SET PROC/PRIV=ALL command, you'll end up with all the privs the parent had when H the subprocess was spawned.  You really don't want to try to go this wayD though.  You obviously don't know enough about VMS to write a reallyO bullet-proof program to do this, and since the image would have to be installed N with SYSPRV and OPER in order to change the terminal protection, I doubt you'd( convince a system manager to install it.  J  > 1.  The SHARE privelege is sufficient to allow the debugger to allocateK  > the target terminal device.  It is not necessary for the process already ?  > using the terminal to deallocate the terminal or disconnect.   L This is true, given that the protections on the device and the privileges ofN the user are such that he would have been able to access the device were there) nobody else with channels assigned to it.   H  > 2.  BYPASS or SYSPRV privelege is sufficient to allow the debugger toC  > access the terminal device.  (I'm not using this method myself.)   N BYPASS will let you access it as long as there are no channels assigned to it.J SYSPRV will let you access it if it's protected system-readable and has no channels assigned.  L In order to guarantee that you can do I/O to the device, you need BYPASS andM SHARE.  If you want to be able to change its protections, you need BYPASS and  OPER.   E  > 3.  Arne Vajhxj <ISIS08@ecostat.aau.dk> has used the debugger with L  > DBG$OUTPUT and DBG$INPUT connected to files.  (Didn't he post this?)  So,)  > presumably, mailboxes would also work.   N The only problem with using mailboxes is that you have no obvious and easy wayJ to force the debugger to respond to your commands (if you cancel your lastI breakpoint and issue a GO command, there's no way you can get back to the F debugger unless you've prepared the image you're debugging for such anM eventuality.  I'm enclosing two routines at the end of this message that will 
 do just that.   F  > 4.  The method of using FORCEX, DCLEXH, and UNWIND does indeed workG  > reliably for sending signals from one process to another.  Here is a    > description of the procedure:  M This may be true, but you're going through a lot of unnecessary work for what   it seems you want to accomplish.  K  >   A process that wants to receive signals sets up an exit handler, after   >   all other exit handlers.   N Alternatively, it could simply issue a call to $CREMBX, which is a lot easier.K In either case, you've got the problem of whatever other process wanting to N communicate needing to figure out where to direct their signals.  If you don'tO want to have to keep checking the mailbox, you can enable a write-attention AST  on the mailbox.   K  >   To send a signal, another process calls FORCEX and passes the value of )  >   the signal as the "completion code".   N Now, of course, if the other process happens to accidentally use the wrong PIDC in the call to FORCEX, some innocent bystander could stand to lose.   M  >   The target process receives a user mode AST.  This AST calls EXIT in the K  >   context of the target process, passing EXIT the completion code.  EXIT !  >   then runs any exit handlers.   F Using a mailbox, the target process gets an AST (normally delivered atH user-level, but the target process controls the access mode at which the! write-attention AST is delivered.   K  >   The exit handler looks at the completion code.  The processes that are M  >   using this technique to communicate must have previously agreed on a set L  >   of values that will represent signals.  This set should not include anyK  >   normally used VMS condition values.  If the completion code is not one ;  >   expected by the exit handler, it should simply return.   L Using a mailbox, the target process simply reads the mailbox (which not onlyO gets it whatever data the other process wanted to send [we're not talking about M limiting ourselves to as single longword here, either], but also the identity N of the sender.  This can all be done in the context of the AST routine, or youJ can have the AST routine set a flag somewhere in your data space, and your. process can handle the message at its leisure.  H  >   Now the exit handler should do whatever it is supposed to when this  >   signal is received.  L  >   After it is done processing the signal, the exit handler must abort theL  >   EXIT and FORCEX as if they never occurred.  To do this it calls UNWIND.M  >   Since UNWIND can not be called except from a condition handler, the exit H  >   handler must establish a condition handler (with LIB$ESTABLISH) and*  >   signal a condition (with LIB$SIGNAL).  K With a mailbox and a write-attention AST, once processing of the message is M complete, the AST procedure needs only to issue a QIO request to reenable the N write-attention AST, then execute a return instruction, in order to return the< process to the state it was in before the AST was delivered.  J  >   The condition handler then calls UNWIND, which modifies the return PCD  >   values in the stack frames below the condition handler's frame.  M  >   The condition handler then returns, starting the unwinding of the stack. L  >   The condition handler is called again (with argument SS$_UNWIND) duringM  >   the unwinding of the stack frame of the exit handler, and it must simply   >   return.  M  >   If the proper number of stack frames were unwound (!), then execution of D  >   the program resumes where it was interrupted by the FORCEX AST.  M With a mailbox and a write-attention AST enabled, you don't have to guess how M far to unwind the stack.  The operating system takes care of keeping track of J that for you, automatically.  Now, the routines you need to make debuggingK through a mailbox relatively reliable (I'm not about to spend any time on a K user interface for it; the two routines (well, three if you count a routine P that does nothing but execute a return instruction) that follow are designed to ; make sure that you can always get the debugger's attention. P /* ASTROUTINE - Clear out the mailbox and enable another write-attention AST  */P /* Takes one argument: the number of a channel assigned to the mailbox        */ #include iodef #include ssdef astroutine(short chan) {   short iosb[4];     long stat;  J     while((((stat = SYS$QIOW(0, chan, IO$_READVBLK | IO$M_NOW, iosb, 0, 0,F         0, 0, 0, 0, 0, 0)) & 7) == 1) && (((stat = iosb[0]) & 7) == 1)%          || (stat == SS$_BUFFEROVF));      if(stat != SS$_ENDOFFILE)          SYS$EXIT(stat); H     if((((stat = SYS$QIOW(0, chan, IO$_SETMODE|IO$M_WRTATTN, iosb, 0, 0,8             astroutine, chan, 0, 0, 0, 0)) & 7) != 1) ||6         (((stat = iosb[0]) & 7) != 1)) SYS$EXIT(stat); }lP /***************************** End of ASTROUTINE ******************************/  P /********************** Routine to create three mailboxes *********************/P /* In this version, logical names for the mailboxes are built in              */ #include descrip crembx()
 {	short chan;G 	long stat, i;- 	$DESCRIPTOR(input_mailbox, "INPUT_MAILBOX");i/ 	$DESCRIPTOR(output_mailbox, "OUTPUT_MAILBOX");T6 	$DESCRIPTOR(attention _mailbox, "ATTENTION_MAILBOX"); 	dsc$descriptor *lognams[3] = 9 	{	&input_mailbox, &output_mailbox, &attention_mailbox };n& /*	Create three temporary mailboxes */ 	for(i = 0; i < 3; ++i)T@ 	{	if(((stat =SYS$CREMBX(0,&chan,0,0,0,0,lognams[i])) & 7) != 1) 		SYS$EXIT(stat);  	} 	astroutine(chan);B }	/* And give the astroutine the channel number of the last one */P /*********************** End of mailbox creation routine **********************/  G To start up a debugging session through mailboxes using these routines, H 	1)  Compile and link your program with these two routines, linking with 	    the /DEBUG qualifier;? 	2)  Define DBG$INIT to point to a file containing at least thet 	    following instructions:9 		CALL crembx	! set up mailboxes and enable attention ASTe9 		SET BREAK astroutine	! BREAK when the mailbox is active(; 		GO; @INPUT_MAILBOX	! Start the image (the GO is optional)dB 	3)  To cause the program to enter the debugger, just write to the 	    ATTENTION_MAILBOX.cC 	4)  To issue commands to the debugger, write to the INPUT_MAILBOX.u@ 	5)  To see the results of your commands to the debugger, write:) 		SET LOG OUTPUT_MAILBOX:; SET OUTPUT LOG = 	    to the INPUT_MAILBOX, and startup a process to copy fromVH 	    OUTPUT_MAILBOX to wherever you want to see the output.  The command/ 		SPAWN/NOWAIT COPY OUTPUT_MAILBOX: SYS$OUTPUT:R 	    will suffice.    Hope this is of some use to you.  