home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 7927 < prev    next >
Encoding:
Text File  |  1993-01-21  |  5.4 KB  |  176 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!srvr1.engin.umich.edu!uvaarpa!mmdf
  3. From: " (Paul Marquess)" <pmarquess@rosebud.bfsec.bt.co.uk>
  4. Subject: Re: Perl debugger under X ?
  5. Message-ID: <1993Jan21.143028.19327@uvaarpa.Virginia.EDU>
  6. Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
  7. Reply-To: pmarquess@bfsec.bt.co.uk
  8. Organization: The Internet
  9. Date: Thu, 21 Jan 1993 14:30:28 GMT
  10. Lines: 164
  11.  
  12. In message <1992Dec3.132739.21282@news.eng.convex.com> 
  13.     tchrist@convex.COM (Tom Christiansen) writes:
  14. | Maybe... not sure what that means.  Here's a system I have
  15. | for starting several xterms, one for the debugger, one for
  16. | program i/o, and one for a slave-vi that autorepositions
  17. | at each break point or line number.  You need named pipes
  18. | and the TIOCSTI ioctl.  There's a two-line or so mod to 
  19. | perldb to support this.
  20. | I first invented this to debug plum, cause it does screen
  21. | handling stuff, which is highly inconvenient when you're
  22. | using the same window to debug.
  23.  
  24. I have used this for quite a while and found it VERY useful. One small
  25. problem, though, is that it is difficult to use it to debug programs
  26. which require special copies of the perl interpreter, e.g. oraperl,
  27. curseperl etc.
  28.  
  29. These sort of scripts usually have a #! line to specify the interpreter
  30. name, so below is a patch for Tom's pwdb program which will search the
  31. script to be debugged for the initial #! line and extract the name of
  32. the interpreter. This will then be the used to debug the script.
  33.  
  34. For those scripts which do not have the appropriate #! line I have
  35. added a -i option which allow the interpreter to be specified. If the
  36. interpreter specified is not a relative or absolute path, it will be
  37. searched for on the path. 
  38.  
  39. So, for example, to debug an oraperl script which does not contain
  40. the appropriate #! line, use
  41.  
  42.     pwdb -i oraperl script
  43.  
  44. Whilst on the subject of debuggers and X, I am in the middle of writing
  45. a perl interface to XView (freely available OPEN LOOK user interface
  46. toolkit). One of my reasons is to attempt to implement an enhanced
  47. X-wondows perl debugger. If I ever get around to finishing the XView
  48. interface I will post it - it sort of works at the moment, but there
  49. are still quite a few loose end which need tying.
  50.  
  51.  
  52. *** old/pwdb    Thu Jan 21 12:48:17 1993
  53. --- pwdb    Thu Jan 21 12:51:32 1993
  54. ***************
  55. *** 2,7 ****
  56. --- 2,22 ----
  57.   
  58.   die "no program to dbg" unless @ARGV;
  59.   
  60. + # Parse the command line
  61. + if ($ARGV[0] eq '-i')
  62. + {
  63. +     shift ;
  64. +     ($interp = shift) || die "usage: $0 [-i interpreter] script [parameters]\n";
  65. +     $interp = &SearchPath($interp) ;
  66. + }
  67. + else
  68. + {
  69. +     $interp = &GetInterpreterName ($ARGV[0]) ;
  70. + }
  71. +  
  72. +  
  73. + print "Perl Interpreter is $interp\n" ;
  74.   open (TTY, "</dev/tty") || die "can't open /dev/tty: $!";
  75.   
  76.   system("stty -echo");
  77. ***************
  78. *** 60,66 ****
  79.       close (STDOUT);
  80.       open(STDOUT, "> $bugtty") || die "can't reopen STDOUT: $!";
  81.       open(STDERR, ">&STDOUT") || die "can't reopen STDERR: $!";
  82. !     exec "perl -d @ARGV 2>&1 >$bugtty";
  83.       die "can't exec perl debugger: $!";
  84.   } 
  85.   
  86. --- 75,81 ----
  87.       close (STDOUT);
  88.       open(STDOUT, "> $bugtty") || die "can't reopen STDOUT: $!";
  89.       open(STDERR, ">&STDOUT") || die "can't reopen STDERR: $!";
  90. !     exec "$interp -d @ARGV 2>&1 >$bugtty";
  91.       die "can't exec perl debugger: $!";
  92.   } 
  93.   
  94. ***************
  95. *** 92,94 ****
  96. --- 107,175 ----
  97.   sub newpgrp { 
  98.       setpgrp($$,$$); 
  99.   } 
  100. + sub GetInterpreterName
  101. + {
  102. +     local ($file) = @_ ;
  103. +     local ($line) ;
  104. +     local ($interpreter) = "perl" ;  # Initialise to default interpterer name
  105. +     # check that the script file actually is a text file
  106. +     die "$file is not a text file\n" if ! -T $file ;
  107. +     # get the first line from the script
  108. +     open (FIL, "<$file") || die "Cannot open $file: $!\n" ;
  109. +     $line = <FIL> ;
  110. +     close FIL ;
  111. +     # now figure out the name of the interpreter
  112. +     chop $line ;
  113. +     # Check for a #! -- if not then assume bog standard perl
  114. +     if ( $line =~ s/^#! *//o )
  115. +     {
  116. +         # The first word must be the interpreter
  117. +         $interpreter = (split (/ /, $line)) [0] ; 
  118. +     }
  119. +     &SearchPath ($interpreter) ;
  120. + }
  121. + sub SearchPath
  122. + {
  123. +     local ($interpreter) = @_ ;
  124. +     local ($found, $dir, @absdirs) ;
  125. +     # only search for the interpreter on the path if it is
  126. +     # neither an absolute or relative path
  127. +     if ( $interpreter !~ m#^[/.]#o )
  128. +     {
  129. +         # Now check for the existance of the interpreter
  130. +         @absdirs = reverse grep(m!^/!, split(/:/, $ENV{'PATH'}, 999)) ;
  131. +  
  132. +         $found = '' ;
  133. +         foreach $dir (@absdirs)
  134. +         {
  135. +             stat ("$dir/$interpreter") ;
  136. +  
  137. +             # file must be executable but
  138. +             # not be a directory, block special or character special file
  139. +             $found = "$dir/$interpreter"
  140. +                 if -x _ && ! ( -d _ || -b _ || -c _) ;
  141. +          }
  142. +  
  143. +         die "cannot find $interpreter in path\n" if ! $found ;
  144. +  
  145. +         $interpreter = $found  ;
  146. +     }
  147. +     else
  148. +     {
  149. +         # Check that specified interpterer can be executed
  150. +         die "Cannot execute $interpreter\n"
  151. +             unless -x $interpreter ;
  152. +     }
  153. +     $interpreter ;
  154. + }
  155. *** end of patch
  156.  
  157. Paul Marquess                 Tel:    +44 232 894-265
  158. BT                          Fax:    +44 232 333-600
  159. Royston House               e-mail: pmarquess@bfsec.bt.co.uk
  160. 34 Upper Queen Street
  161. BELFAST BT8 4QY
  162. UK
  163.