develooper Front page | perl.perl5.porters | Postings from September 2003

Re: [PATCH 5.8.1 @21379] debugger fixes

Thread Previous
From:
Joe McMahon
Date:
September 26, 2003 08:40
Subject:
Re: [PATCH 5.8.1 @21379] debugger fixes
Message ID:
CCFA4B06-F037-11D7-9623-000393BCA0FC@ibiblio.org

On Thursday, Sep 25, 2003, at 22:49 US/Eastern, Ilya Zakharevich wrote:

> This patch fixes several problems with the debugger:
>
>   a) POD docs and new-comments are very wrong quite often.  I fixed
>      only one or two of the errors which were at hand when I was doing
>      other stuff;
>
>      [I wonder: what is the point of having more docs if these
>      additions are wrong?]
The point was to have *something*. I never professed to knowing all and 
seeing all. I very much appreciate the OS/2 corrections, because I 
frankly had to guess based on the code.
>
>  XXX It behooves an OS/2 expert to write the necessary documentation 
> for this!
>
> +Starts a separate session (so a new console) with a kid Perl program; 
> this
> +program mirrors user's input of this session to one filehandle 
> ($out), and
> +displays data coming through $in filehandle.
> +
> +Since this kid program should not be debugged, we massage C<PERL5OPT>
> +and C<PERL5LIB> environment variables to make the kid as reliable as 
> possible.
> +
> +B<LIMITATIONS>: with the current logic the kid should inherit the 
> filehandles
> +created by pipe() calls; this we can't start it with C<P_INDEPENDENT> 
> flag.
> +However, in any session only one process can start a new session 
> without
> +this flag; thus only one window per session can be created.  (To fix 
> this,
> +one should communicate via named pipes or sockets...)
> +
> +Since the depended-sessions are killed when a parent terminates, the 
> kids
> +print C<Process terminated by SIGKILL> (?) messages; they are visible 
> for a
> +moment before the session closes.
> +
Exactly what I needed. Just wish it had gotten here before the 5.8.1 
release.


Would you be willing to add a few more comments here?
> +    # What follows until <<<<< is mostly almost exactly
> +    #  require OS2::Process; my ($in, $out, $pid) = 
> OS2::Process::io_term @args
> +    local $^F = 40;     # XXXX Fixme!
> +    local $\  = '';
> +    my ($in1, $out1, $in2, $out2);
> +
> +    pipe $in1, $out1 or return;
> +    pipe $in2, $out2 or do { close($in1), close($out1), return };
> +
> +    # system P_SESSION=4 will fail if there is another process
> +    # in the same session with a "dependent" asynchronous child 
> session.
> +    my @args = (($rl ? (read_by_key => 1) : ()),
> +		# scrsize => '40,50',
> +		title => "Daughter Perl debugger $pids $name");
> +    my $kpid = system 4, $^X, '-we', <<'EOS', fileno $in1, fileno 
> $out2, @args;
> +       END {sleep($sleep || 5)}
> +       use OS2::Process; $sleep = 1;
> +       OS2::Process::__term_mirror(@ARGV);
>  EOS
> +    close $in1 or warn;
> +    close $out2 or warn;
> +    warn "system P_SESSION, $^X: $!, $^E" and do { close($in2), 
> close($out1), return }
> +      unless $kpid > 0;
> +    # <<<<<<<<<<<<<
>

And here? This is more OS/2 stuff which I don't have the background to 
comment in detail.
>
> +# Large buffer works at least for read from pipes
> +sub __term_mirror_screen {   # Read from fd=$in and write to the 
> console
> +  my $in = shift;
> +  open IN, "<&=$in" or die "open <&=$in: $!";
> +  # Attempt to redirect to STDERR/OUT is not very useful, but try 
> this anyway...
> +  open OUT, '>', '/dev/con' or open OUT, '>&STDERR' or open OUT, 
> '>&STDOUT'
> +        or warn "Cannot reopen STDOUT to /dev/con or STDERR/STDOUT";
> +  select OUT; $| = 1; local $SIG{TERM} = sub { die "screenwriter 
> exits...\n"};
> +  eval { print while sysread IN, $_, 1<<16; }
> +}
> +
> +sub __term_mirror {   # Read from fd=$in and pass through; same for 
> $out
> +  my $pid;
> +  local $SIG{TERM} = sub { die "keyreader exits...\n" };
> +  my ($in, $out) = (shift, shift);
> +  my %in = @_;
> +  Title_set $in{title}			if exists $in{title};
> +  &scrsize_set(split /,/, $in{scrsize})	if exists $in{scrsize};
> +
> +  $pid = system 1, $^X, '-MOS2::Process',
> +	 '-we', 'OS2::Process::__term_mirror_screen shift', $in;
> +  $pid > 0 or die "Cannot start a grandkid";
> +
> +  open STDIN, '</dev/con' or warn "reopen stdin: $!";
> +  open OUT, ">&=$out" or die "Cannot open &=$out for writing: $!";
> +  select OUT;    $| = 1;  binmode OUT;	# need binmode since sysread() 
> is bin
> +  $SIG{PIPE} = sub { die "writing to a closed pipe" };
> +  # Turn Nodelay on kbd.  Pipe is automatically nodelay...
> +  if ($in{read_by_key}) {
> +    if (eval {require Term::ReadKey; 1}) {
> +      Term::ReadKey::ReadMode(4);
> +    } else { warn }
> +  }
> +  print while sysread STDIN, $_, 1<<($flag ? 16 : 0);
> +}
> +
> +sub io_term {	# arguments: hash with keys read_by_key/title/scrsize
> +  local $^F = 40;     # XXXX Fixme!
> +  local $\  = '';
> +  my ($in1, $out1, $in2, $out2);
> +
> +  pipe $in1, $out1 or return;
> +  pipe $in2, $out2 or do { close($in1), close($out1), return };
> +
> +  # system P_SESSION will fail if there is another process
> +  # in the same session with a "dependent" asynchronous child session.
> +  my @i = map +('-I', $_), @INC;	# Propagate @INC
> +  my $kpid = system 4, $^X, @i, '-we', <<'EOS', fileno $in1, fileno 
> $out2, @_;
> +     END {sleep($sleep || 5)}
> +     use OS2::Process; $sleep = 1;
> +     OS2::Process::__term_mirror(@ARGV);
> +EOS
> +  close $in1 or warn;
> +  close $out2 or warn;
> +  warn "system P_SESSION, $^X: $!, $^E" and do { close($in2), 
> close($out1), return }
> +    unless $kpid > 0;
> +  return ($in2, $out1, $kpid);
> +}
>

  --- Joe M.


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About