From:	SMTP%"neill@macro.demon.co.uk"  5-JAN-1994 19:45:19.08
To:	EVERHART
CC:	
Subj:	DDB.1-OF-5  Detached debugger

Date: Wed, 05 Jan 1994 23:27:04 +0000
From: Neill Clift <neill@macro.demon.co.uk>
To: EVERHART@arisia.gce.com
Message-ID: <009781AA.D7DE42C0.5388@macro.demon.co.uk>
Subject: DDB.1-OF-5  Detached debugger

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_UNPACK_VERIFY"))'
$!
$! This archive created:
$!  Name : DDB
$!  By   : neill@macro.demon.co.uk
$!  Date :  5-JAN-1994 23:23:28.74
$!  Using: VMS_SHARE 8.4, (C) 1993 Andy Harper, Kings College London UK
$!
$! Credit is due to these people for their original ideas:
$!    James Gray, Michael Bednarek 
$!
$!+ THIS PACKAGE DISTRIBUTED IN 5 PARTS, TO KEEP EACH PART
$!  BELOW 30 BLOCKS
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. AAAREADME.TXT;2
$!       2. BUILD.COM;22
$!       3. DDB_CLD.CLD;11
$!       4. DDB_MAIN.MAR;120
$!       5. DDB_MSG.MSG;6
$!       6. DDB_PRIV.MAR;112
$!       7. DESCRIP.MMS;3
$!       8. SETUP.COM;3
$!       9. TEST.COM;6
$!      10. TEST.FOR;1
$!
$ set="set"
$ set symbol/scope=(nolocal,noglobal)
$ f=f$parse("SHARE_UNPACK_TEMP","SYS$SCRATCH:."+f$getjpi("","PID"))
$ e="write sys$error  ""%UNPACK"", "
$ w="write sys$output ""%UNPACK"", "
$ if .not. f$trnlnm("SHARE_UNPACK_LOG") then $ w = "!"
$ if f$getsyi("CPU") .gt. 127 then $ goto start
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto start
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$unpack: subroutine ! P1=filename, P2=checksum, P3=attributes,P4=size
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'"
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn' File skipped"
$ delete 'f'*
$ exit
$dirok:
$ x=f$search(P1)
$ if x .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped"
$ delete 'f'*
$ exit
$file_absent:
$ w "-I-UNPACK, Unpacking ", P5, " of ", P6, " - ", P1, " - ", P4, " Blocks"
$ n=P1
$ if P3 .nes. "" then $ n=f
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT/NOJOURNAL 'f'/OUT='n'
PROCEDURE GetHex(s,p)LOCAL x1,x2;x1:=INDEX(t,SUBSTR(s,p,1))-1;x2:=INDEX(t,
SUBSTR(s,p+1,1))-1;RETURN 16*x1+x2;ENDPROCEDURE;PROCEDURE SkipPartsep LOCAL m;
LOOP m:=MARK(NONE);EXITIF m=END_OF(b);DELETE(m);EXITIF INDEX(ERASE_LINE,
"-+-+-+-+-+-+-+-+")=1;ENDLOOP;ENDPROCEDURE;PROCEDURE ProcessLine LOCAL c,s,l,b,
n,p;c := ERASE_CHARACTER(1);s := ERASE_LINE;IF c = "X" THEN SPLIT_LINE; ENDIF;
MOVE_HORIZONTAL(-1);l := LENGTH(s);p := 1;LOOP EXITIF p > l;c := SUBSTR(s,p,1);
p := p+1;CASE c FROM ' ' TO '`' ['`']: COPY_TEXT(ASCII(GetHex(s,p))); p:=p+2;[
' ']: p:=p+1;[INRANGE,OUTRANGE]: COPY_TEXT(c);ENDCASE;ENDLOOP;ENDPROCEDURE;
PROCEDURE Decode LOCAL m;POSITION(BEGINNING_OF(b));LOOP m:=MARK(NONE);EXITIF m=
END_OF(b);DELETE(m);IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+-")=
1 THEN SkipPartSep;ELSE ProcessLine;MOVE_HORIZONTAL(1);ENDIF;ENDLOOP;
ENDPROCEDURE;SET(FACILITY_NAME,"UNPACK");SET(SUCCESS,OFF);SET(INFORMATIONAL,
OFF);t:="0123456789ABCDEF";f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);Decode;WRITE_FILE(b,GET_INFO(COMMAND_LINE,"output_file"));
QUIT;
$ if p3 .eqs. "" then $ goto dl
$ open/write fdl &f
$ write fdl "RECORD"
$ write fdl P3
$ close fdl
$ w "-I-CONVRFM, Converting record format to ", P3
$ convert/fdl=&f &f-1 &P1
$dl: delete 'f'*
$ checksum 'P1'
$ if checksum$checksum .nes. P2 then $ -
  e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ exit
$ endsubroutine
$start:
$!
$ create 'f'
XDDB`20(detached`20debugger)`20is`20a`20utilility`20to`20fire`20up`20the`20debu
Vgger`20for`20a`20detached
Xprocess.`20DDB`20is`20set`20up`20as`20a`20foreign`20command:
X
X$`20ddb`20:==`20$file_path:ddb
X
XIt`20has`20the`20following`20syntax:
X
X$`20ddb`5B/identification=pid`5D`5B/log=logfile`5D`20`5Bprocess_name`5D
X
XThe`20process`20to`20be`20debugged`20is`20selected`20via`20the`20PID`20or`20pr
Vocess`20name.
X
XDDB`20works`20by`20creating`20an`20pseudo`20(FTAnnn:)`20and`20virtual`20(VTAnn
Vn:)`20terminal`20and
Xlinking`20the`20two`20together`20in`20the`20usual`20way.`20DDB`20then`20sends
V`20a`20kernel`20mode`20AST`20to
Xthe`20process`20to`20be`20debugged`20to`20assign`20DBG$INPUT`20and`20DBG$OUTPU
VT`20to`20be`20the`20created
Xvirtual`20terminal.`20DDB`20then`20transparently`20copies`20all`20the`20users
V`20terminal`20strokes
Xto`20the`20pseudo`20terminal.`20This`20make`20it`20appear`20to`20the`20user`20
Vthat`20s/he`20is`20talking`20to
Xthe`20detached`20process`20directly.
X
XThe`20configuaration`20looks`20like`20this:
X
Xuser`20----`20typing`20--->`20FTAnnn:`20---->`20VTAnnn:`20---->`20detached`20p
Vrocess`20+`20debug
X`20`20`20`20`20<---`20output`20----`20`20`20`20`20`20`20`20`20<----`20`20`20
V`20`20`20`20`20`20<----
X
X
XWhen`20the`20user`20has`20finished`20debugging`20the`20detached`20process`20s/
Vhe`20may`20hit`20`5E`5C`20which
Xwill`20cause`20the`20FTAnnn`20device`20to`20be`20eventualy`20hung`20up.`20At
V`20this`20point`20the`20virtual
Xterminal`20disconnects`20from`20the`20physical`20(nothing`20physical`20about
V`20it`20really`20maybe
Xlogical`20is`20a`20better`20word`20for`20it)`20terminal.`20If`20the`20user`20a
Vt`20a`20later`20time`20decides
Xto`20reenter`20debug`20for`20this`20detached`20process`20DDB`20detects`20that
V`20debug`20has`20already
Xbeen`20activated`20and`20connects`20a`20new`20FTAnnn`20device`20to`20the`20dis
Vconnected`20virtual
Xterminal.
X
XThere`20is`20a`20small`20FORTRAN`20program`20for`20you`20to`20debug`20to`20tes
Vt`20it`20out.`20Just
X@test.com`20and`20a`20process`20TEST`20is`20created`20at`20priority`200.`20Use
V:
X$`20@setup.com
X$`20ddb`20test
XThen`20wait`20for`20the`20debug`20prompt`20to`20appear.
X
XPlease`20feel`20free`20to`20get`20in`20there`20and`20hack`20that`20code`20arou
Vnd.`20Just`20remember`20that
Xeven`20the`20slightest`20change`20to`20a`20program`20of`20this`20sort`20might
V`20crash`20your`20machine`20so
Xdon't`20test`20it`20on`20your`20production`20machines.`20If`20you`20make`20any
V`20mods,`20have`20any`20good
Xideas,`20find`20any`20bugs`20or`20just`20want`20my`20address`20to`20send`20me
V`20some`20dosh`20*MAIL`20ME*.
X
XSome`20problems`20so`20far`20noted:
X
XSome`20older`20versions`20of`20VMS`20(older`20than`20V5.5`20maybe?)`20had`20pr
Voblems`20were`20the
XFTDRIVER`20did`20not`20like`20being`20used`20with`20virtual`20terminals.
X
XYou`20need`20virtual`20terminals`20loaded`20on`20the`20system`20but`20you`20ca
Vn`20get`20away`20with`20only
Xloading`20the`20driver`20at`20debug`20time.`20Setup.com`20does`20this.
X
XHitting`20return`20before`20the`20process`20has`20got`20its`20hands`20on`20the
V`20FTAnnnn:`20device
Xcauses`20loginout`20to`20be`20activated.`20I`20could`20set`20the`20terminal`20
Vnotype_ahead`20but`20then
Xyou`20don't`20get`20to`20type`20ahead`20in`20debug.`20I`20suppose`20I`20should
V`20not`20transfer
Xkeystrokes`20to`20the`20FTAnnnn:`20until`20I`20know`20the`20debug`20process`20
Vhas`20assigned.
X
XThe`20program`20leaves`20logical`20names`20hanging`20about`20in`20the`20system
V`20table.`20These`20maybe
Xshould`20be`20gotten`20rid`20of`20by`20the`20target`20process`20but`20I`20am
V`20not`20sure`20what`20the`20best
Xway`20of`20doing`20this`20is.
X
XVirtual`20terminals`20eventualy`20try`20to`20delete`20themselves`20after`20a
V`20certain`20period`20of
Xtime`20has`20elapsed.`20This`20is`20determined`20by`20the`20sysgen`20parameter
V`20TTY_TIMEOUT
X(default`20is`20900s`20=`2015`20mins).`20After`20this`20timeout`20period`20you
V`20can`20not`20return`20to
Xdebug`20the`20process.
X
XYou`20can`20only`20debug`20a`20process`20that`20has`20the`20same`20UIC`20as`20
Vyourself.`20The`20terminal
Xdriver`20will`20not`20allow`20reattachment`20unless`20UICs`20match`20regardles
Vs`20of`20privilege.
X
XSometimes`20it`20takes`20a`20long`20time`20for`20the`20debugger`20to`20activat
Ve.`20If`20the`20process`20you`20
Xare`20debugging`20dies`20before`20it`20gets`20into`20debug`20(notraceback`20or
V`20quota`20problems)
Xyou`20sit`20in`20DDB`20forever.`20You`20can`20get`20out`20with`20`5E`5C.
X
XIn`20order`20to`20debug`20at`20a`20level`20other`20than`20assembler`20instruct
Vions`20the`20image`20must
Xhave`20been`20compiled`20and`20linked`20/debug.`20The`20easiest`20way`20of`20d
Voing`20this`20is`20to
Xactivate`20the`20detached`20process`20with`20a`20CLI`20and`20issue`20a`20run/n
Vodebug`20command`20in`20the
Xprocesses`20sys$input`20command`20file:
X
X$`20run/deta/input=cmd_proc.com/out=output_file`20sys$system:loginout.exe
X
XWhere`20cmd_proc.com`20contains:
X
X$`20run/nodebug`20image
X
XAfter`20posting`20this`20file`20to`20comp.os.vms`20I`20received`20the`20follow
Ving`20brilliant`20idea
Xfrom`20Don`20Stokes`20(don@zl2tnm.gen.nz):
X
X>A`20better`20way`20is`20to`20link`20the`20image`20/DEBUG`20and`20flip`20the
V`20debug`20bit`20in`20the
X>image`20header`20(leaving`20the`20symbol`20table`20intact).`20`20I`20kinda`20
Vwish`20there`20were
X>separate`20qualifiers`20to`20build`20a`20symbol`20table`20and`20set`20the`20D
VEBUG`20bit.`20`20Then
X>run`20the`20program`20in`20its`20native`20environment.`20`20Things`20change
V`20a`20bit`20when
X>running`20under`20DCL.`20`20All`20the`20debug`20bit`20does`20is`20indicate`20
Vthat`20the`20debugger
X>kicks`20into`20life`20on`20image`20startup`20before`20passing`20control`20to
V`20the`20second
X>transfer`20vector.
X>
X>Anyway,`20the`20following`20command`20file`20will`20do`20this`20for`20you:
X>
X>$`20`20`20`20`20`20`20on`20warning`20then`20goto`20abort
X>$`20`20`20`20`20`20`20open/read/write`20in`20'f$parse(p1,`20".EXE")'
X>$`20`20`20`20`20`20`20read`20in`20header
X>$`20`20`20`20`20`20`20header`5B%x20*8,1`5D`20=`200
X>$`20`20`20`20`20`20`20write/update/symbol`20in`20header
X>$`20abort:close/nolog`20in
X>$`20`20`20`20`20`20`20exit
X>
X>And`20yes,`20I`20would`20like`20you`20to`20make`20your`20program`20available.
V...`20`208-)
X>
X
XI`20only`20wish`20I`20had`20thought`20this`20up`20myself`20:-(
X
X*WARNING*
X
XThis`20code`20is`20very`20hacky`20and`20as`20such`20requires`20the`20following
V`20warning:
X
XUse`20at`20your`20own`20risk.`20If`20it`20crashes`20your`20machine`20then`20th
Vats`20tough!`20I`20accept
X*NO*`20responsibility`20for`20it`20what`20so`20ever.
X
XIts`20kernel,`20its`20privileged,`20its`20version`20dependent,`20its`20unsuppo
Vrted`20(by`20anyone)
Xand`20its`20likely`20to`20break`20if`20you`20upgrade`20the`20OS/debug`20someth
Ving`20funny`20(ACP)/stand
Xin`20a`20funny`20way.
X
XDon't`20install`20this`20image`20with`20privileges.
X
XI`20wrote`20this`20code`20for`20fun`20not`20money`20but`20of`20course`20I`20wo
Vuld`20like`20to`20know`20of`20any
Xbugs`20etc.
X
X`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
V`20`20`20`20Neill
X
Xneill@macro.demon.co.uk
$ call unpack AAAREADME.TXT;2 561307806 "" 11 1 10 
$!
$ create 'f'
X$`20MACRO`20/NOLIST/OBJECT=DDB_MAIN.OBJ`20DDB_MAIN.MAR
X$`20MESSAGE`20/NOLIST/OBJECT=DDB_MSG.OBJ`20DDB_MSG.MSG
X$`20SET`20COMMAND`20/OBJECT=DDB_CLD.OBJ`20`20DDB_CLD.CLD
X$`20MACRO`20/NOLIST/OBJECT=DDB_PRIV.OBJ`20DDB_PRIV.MAR
X$`20link/notrace/exe=ddb.exe`20ddb_main.obj,`20ddb_msg.obj,`20ddb_cld.obj,`20
V`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
V`20`20ddb_priv.obj
X$`20fortran/debug/nooptim/check=all`20test.for
X$`20link/debug`20test.obj
X$`20!
$ call unpack BUILD.COM;22 -
 1031287745 "FORMAT STREAM_LF;CARRIAGE_CONTROL CARRIAGE_RETURN" 1 2 10 
$!
$ create 'f'
X!
X!`20Define`20verb`20for`20the`20Detached`20process`20DeBugger
X!
X!`20Command`20has`20the`20form:
X!`20`20`20`20$`20ddb`5B/identification=pid`5D`5B/log=logfile`5D`20`5Bprocess_n
Vame`5D
X!
Xmodule`20ddb_clitable
X`20`20`20define`20verb`20ddb
X`20`20`20`20`20`20parameter`20p1`20label=process_name`20value`20(required)`20!
V`20Process`20name
X`20`20`20`20`20`20qualifier`20identification`20syntax=id_syntax`20value`20(req
Vuired)`20!`20Process`20id
X`20`20`20`20`20`20qualifier`20log`20value`20(default='SYS$DISK:`5B`5DDDB.LOG',
V`20type=$outfile)
X
X`20`20`20define`20syntax`20id_syntax
X`20`20`20`20`20`20noparameters
$ call unpack DDB_CLD.CLD;11 1413244699 "" 1 3 10 
$!
$ create 'f'
X`09.title`09ddb_main`20main`20module
X;
X;`20Copyright`20(C)`201994`20Neill`20Clift`20(neill@macro.demon.co.uk).
X;
X;`20This`20program`20comes`20without`20any`20warranty.`20The`20author`20does
V`20not`20accept`20any
X;`20responsibility`20for`20any`20damage`20caused`20by`20the`20use`20of`20this
V`20program.`20This
X;`20program`20is`20not`20in`20the`20public`20domain`20but`20may`20be`20copied
V`20freely`20so`20long`20as`20this
X;`20copyright`20notice`20remains.
X;
X;`20Please`20send`20any`20modifications`20to`20the`20author.
X;
X;`20The`20aim`20of`20this`20code`20is`20to`20run`20up`20the`20debugger`20in`20
Va`20detached`20process`20with
X;`20dbg$input`20etc`20pointing`20to`20a`20pseudo-terminal`20created`20especial
Vy`20for`20the`20debug
X;`20purpose.
X;
X`09.disable`20global
X;
X;`20Includes:
X;
X`09$dvidef`09`09`09`09`09;`20Device`20volume`20information
X`09$iodef`09`09`09`09`09;`20$QIO`20request`20values
X`09$lckdef`09`09`09`09`09;`20Lock`20services`20defs.
X`09$lnmdef`09`09`09`09`09;`20Logical`20name`20service`20defs.
X`09$namdef`09`09`09`09`09;`20Name`20block`20definitions
X`09$psldef`09`09`09`09`09;`20Process`20status`20longword`20defs.
X`09$ssdef`09`09`09`09`09;`20System`20service`20comp.`20codes
X`09$stsdef`09`09`09`09`09;`20Status`20code`20defs
X`09$ttdef`09`09`09`09`09;`20Terminal`20characteristics
X`09$tt2def`09`09`09`09`09;`20Extended`20terminal`20chars
X;
X;`20External`20symbols:
X;
X`09.external`20ddb_clitable`09`09`09;`20CLI`20command`20table
X`09.external`20ddb__logopenerr,`20-`09`09;`20Error`20opening`20log`20file
X`09`09ddb__logconnerr,`20-`09`09;`20Error`20connecting`20log`20file
X`09`09ddb__logputerr,`20-`09`09;`20Error`20during`20$PUT
X`09`09ddb__prcnam,`20-`09`09`09;`20Error`20obtaining`20PID
X`09`09ddb__vtcon,`20-`09`09`09;`20Error`20connectinf`20to`20VTAnnnn:
X`09`09ddb__prcpid`09`09`09;`20Error`20converting`20PID
X;
X;`20External`20routines:
X;
X`09.external`20cli$dcl_parse,`20-`09`09;`20Parse`20a`20DCL`20command
X`09`09cli$get_value,`20-`09`09;`20Get`20a`20value`20from`20the`20CLI
X`09`09cli$present`09`09`09;`20Is`20an`20entity`20present
X`09.external`20ots$cvt_tz_l`09`09`09;`20Convert`20hex`20to`20binary
X`09.external`20lib$get_foreign,`20-`09`09;`20get`20foreign`20command`20line
X`09`09lib$signal,`20-`09`09`09;`20Signal`20error
X`09`09lib$wait`09`09`09;`20wait`20for`20a`20bit
X`09.external`20ddb_privw`09`09`09;`20Start`20up`20debugger
X;
X`09.psect`09ddb_wdata`20wrt`20rd`20noexe`20page
X;
Xlogfab:`09$fab`09dnm`20=`20<sys$disk:`5B`5Dddb.log>,`20-
X`09`09fac`20=`20put,`20-
X`09`09fop`20=`20<dfw,sqo>,`20-
X`09`09nam`20=`20lognam,`20-
X`09`09org`20=`20seq,`20-
X`09`09rat`20=`20cr,`20-
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-
--
Neill Clift  neill@macro.demon.co.uk
