From: system@SendSpamHere.ORG
Sent: Monday, February 11, 2002 5:32 PM
To: Info-VAX@Mvb.Saic.Com
Subject: Re: Am I being debugged?

In article <dundas-1102021256370001@dundas-mac.caltech.edu>, dundas@caltech.edu (John A. Dundas III) writes:
>Is this what you are looking for:
>
>   .title  isdebug - is image linked with debug information?
>        .ident  /28-Jan-1985/
>        .enabl  debug
>        .dsabl  global
>        .extrn  jd_image_act, malloc, free, sys$open, sys$close, __fabr
>;
>; *** Edit History   ***
>;
>; 12-Oct-1984  Original creation and testing.
>;
>; 28-Jan-1985   Use callg instead of calls for jd_image_act().
>;
>   .library "sys$library:lib"
>   $fabdef
>   $ihddef
>   $secdef
>   .psect   jd_ro_code, nowrt, pic, shr
>;
>; function bool isdebug ([str]) varargs
>; char *str; /* optional */
>;
>; If str is specified, it is the name of the file to
>; check  for  debug enabled (no check is made to see
>; if it is really  an  executable  or  not).  If  no
>; argument   is  specified,  the  current  image  is
>; checked. 
>;
>   .entry  isdebug, ^m<r2, r3, r4, r5, r6>
>   tstb  (ap)        ; any args specified?
>   bneq  20$         ; yes, different code
>        callg   (ap), g^jd_image_act    ; get the local image activator stuff
>   movl    20(r0), r0              ; get link flag information
>   bbs     #ihd$v_lnkdebug, r0, 10$ ; exit if set
>   clrl    r0                      ; indicate none
>10$:
>   ret                             ; ...
>20$:
>   pushl   #fab$k_bln              ; stack the size of a fab
>   calls   #1, g^malloc            ; allocate one on the fly
>   movl    r0, r6                  ; save the address in a good reg
>   bneq    30$                     ; skip around if ok
>   brw     error                   ; exit on error
>30$:
>   movc3   #fab$k_bln, g^__fabr, (r6) ; copy a template readonly fab
>   locc    #0, #-1, @4(ap)         ; find the null
>   subl    4(ap), r1               ; compute the length
>   cvtlb   r1, fab$b_fns(r6)       ; set the length
>   movl    4(ap), fab$l_fna(r6)    ; set the filename address
>   bisl    #fab$m_ufo, fab$l_fop(r6) ; set user file open
>   pushl   r6                      ; stack the fab
>   calls   #1, g^sys$open          ; open the file with RMS
>   blbc    r0, error1              ; exit on errors
>   movab   -16(sp), sp             ; get local stack space
>   movzwl  #^x200, -4(fp)          ; safe starting address in P0 space
>   movzwl  #^x200, -8(fp)          ; same
>   $crmpsc_s -                     ; map a section
>      inadr = -8(fp), -
>      retadr = -16(fp), -
>      acmode = #0, -
>      flags = #sec$m_expreg, -
>      chan = fab$l_stv(r6), -
>      pagcnt = #1, -          ; only map 1 page
>      pfc = #1                ; page fault cluster size of 1
>   blbc  r0, error1     ; exit on errors
>   movl  -16(fp), r2    ; get the starting virtual address of section
>   movl    ihd$l_lnkflags(r2), r3  ; get link flags
>   $deltva_s -       ; delete what we created earlier
>      inadr = -16(fp)
>   pushl r6       ; stack the fab
>   calls #1, g^sys$close      ; close the fab
>   pushl r6       ; stack the fab to return to pool mem
>   calls #1, g^free     ; free the memory
>   bbs     #ihd$v_lnkdebug, r3, error ; indicate debug
>   clrl    r0                      ; indicate none
>   ret            ; ...
>error1:
>   pushl r6       ; stack the fab to return to pool mem
>   calls #1, g^free     ; free the memory
>error:
>   movzbl  #1, r0                  ; indicate debug enabled
>   ret            ; ...
>
>   .end
>
>In article <3C67A834.989AD54@herald.ox.ac.uk>, Peter Harding
><harding@herald.ox.ac.uk> wrote:
>
>> I could be a bit clearer: I know about toggling the bit/byte in the
>> image header to control whether the thing runs in debug mode by default
>> or not, but what I want is to know what to replace ***** with in the
>> following:
>> 
>>   if ( ***** ) {
>> 
>>     /* I'm being debugged. Act accordingly */
>> 
>>   } else {
>> 
>>     /* I'm not being debugged. Run as normal. */
>> 
>>   };
>> 
>> I know it goes against the 'spirit' of debugging in that the
>> not-debugged clause will be rather hard to debug, but it's what I need.
>> 
>> Thanks!
>> 
>> Joe wrote:
>> > 
>> > I've never had need to fiddle with it however - assuming I understand
>> > your question I seem to have some dim memory of a bit (byte?) in the
>> > image header that controls this. The linker manual would be the place
>> > to start.
>> > 
>> > Joe
>> > 
>> > Peter Harding <harding@herald.ox.ac.uk> wrote in message
>news:<3C666291.CC53D4F1@herald.ox.ac.uk>...
>> > > Howdy y'all
>> > >
>> > > Small question: how can my (C today, but tomorrow will be different)
>> > > program tell if it is being run in debug mode?
>> > >
>> > > I'm not shy of system service calls.
>> > >
>> > >
>> > > Thanks very much!
>
>-- 
>John A. Dundas III
>Director, Information Technology Services, Caltech
>Mail Code: 014-81, Pasadena, CA  91125-8100
>Phone: 626.395.3392 FAX: 626.449.6973 <mailto:dundas@caltech.edu>


Surely an awfull lot of work.

#include <stdio.h>

start_here(void *transfer_vector_address,
           void *cli_parse_informaiton,
           void *image_header_information,
           void *image_file_information,
           int link_status_bits,
           int cli_status_bits)
  {

    if (((link_status_bits&1) == 1) && ((cli_status_bits&1) == 0))
       printf("I'm being debugged. Act accordingly.\n");
    else
       printf("I'm not being debugged. Run as normal.\n");
  }

--
VAXman- OpenVMS APE certification number: AAA-0001     VAXman(at)TMESIS(dot)COM
           
  "And of course, I'm a genius, so people are naturally drawn to my fiery 
  intellect.  Their admiration overwhelms their envy!" -- Calvin & Hobbes