forked from rocky/Perl-Devel-Trepan
/
Condition.pm
75 lines (63 loc) · 2.12 KB
/
Condition.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
# Copyright (C) 2011 Rocky Bernstein <rocky@cpan.org>
use warnings; no warnings 'redefine';
use lib '../../../..';
package Devel::Trepan::CmdProcessor::Command::Condition;
use English qw( -no_match_vars );
use if !defined @ISA, Devel::Trepan::Condition ;
use if !defined @ISA, Devel::Trepan::CmdProcessor::Command ;
unless (defined @ISA) {
eval "use constant ALIASES => qw(cond);";
eval "use constant CATEGORY => 'breakpoints';";
eval "use constant NEED_STACK => 0;";
eval "use constant SHORT_HELP =>
'Specify breakpoint number N to break only if COND is true';"
}
use strict; use vars qw(@ISA); @ISA = @CMD_ISA;
use vars @CMD_VARS; # Value inherited from parent
our $MIN_ARGS = 2; # Need at least this many
our $MAX_ARGS = undef; # Need at most this many - undef -> unlimited.
our $NAME = set_name();
our $HELP = <<"HELP";
${NAME} BP_NUMBER CONDITION
BP_NUMBER is a breakpoint number. CONDITION is an expression which
must evaluate to True before the breakpoint is honored. If CONDITION
is absent, any existing condition is removed; i.e., the breakpoint is
made unconditional.
Examples:
${NAME} 5 x > 10 # Breakpoint 5 now has condition x > 10
${NAME} 5 # Remove above condition
See also "break", "enable" and "disable".
HELP
# This method runs the command
sub run($$) {
my ($self, $args) = @_;
my $proc = $self->{proc};
my $bpnum = $proc->get_an_int($args->[1]);
my $bp = $proc->{brkpts}->find($bpnum);
unless ($bp) {
$proc->errmsg("No breakpoint number $bpnum");
return;
}
my $condition;
if (scalar @{$args} > 2) {
my @args = @{$args};
shift @args; shift @args;
$condition = join(' ', @args);
unless (is_valid_condition($condition)) {
$proc->errmsg("Invalid condition: $condition");
return
}
} else {
$condition = '1';
$proc->msg('Breakpoint $bp->id is now unconditional.');
}
$bp->condition($condition);
}
unless (caller) {
require Devel::Trepan::CmdProcessor::Mock;
my $proc = Devel::Trepan::CmdProcessor::Mock::setup();
# my $cmd = __PACKAGE__->new($proc);
# $cmd->run([$NAME]);
}
1;