| 1 | # -*- coding: utf-8 -*- | ||||||||||||||
| 2 | # Copyright (C) 2011-2013 Rocky Bernstein <rocky@cpan.org> | ||||||||||||||
| 3 | 12 | ▶ | use strict; use warnings; no warnings 'redefine'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 12 | ▶ | use English qw( -no_match_vars ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 12 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 12 | my @OLD_INC = @INC; | |||||||||||||
| 8 | 12 | ▶ | use rlib '../..'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 12 | ▶ | use Devel::Trepan::DB::Breakpoint; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 12 | @INC = @OLD_INC; | |||||||||||||
| 11 | } | ||||||||||||||
| 12 | |||||||||||||||
| 13 | package Devel::Trepan::BrkptMgr; | ||||||||||||||
| 14 | |||||||||||||||
| 15 | |||||||||||||||
| 16 | sub new($$) | ||||||||||||||
| 17 | 27 | ▶ | { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||
| 18 | 0 | ▶ | my ($class,$dbgr) = @_; | ||||||||||||
|
Subroutine
new: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||
| 19 | 0 | my $self = {}; | |||||||||||||
| 20 | 0 | $self->{dbgr} = $dbgr; | |||||||||||||
| 21 | 0 | bless $self, $class; | |||||||||||||
| 22 | 0 | $self->clear(); | |||||||||||||
| 23 | 0 | $self; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | sub clear($) | ||||||||||||||
| 27 | 27 | ▶ | { | ||||||||||||
|
Subroutine
clear: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||
| 28 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||
| 29 | 0 | $self->{list} = []; | |||||||||||||
| 30 | 0 | $self->{next_id} = 1; | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | |||||||||||||||
| 33 | sub inspect($) | ||||||||||||||
| 34 | 0 | ▶ | { | ||||||||||||
|
Subroutine
inspect: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 35 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
inspect: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 36 | 0 | my $str = ''; | |||||||||||||
| 37 | 0 | for my $brkpt ($self->list) { | |||||||||||||
| 38 | 0 | ▶ | next unless defined $brkpt; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 39 | 0 | $str .= $brkpt->inspect . "\n"; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | 0 | $str; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | sub ids($) | ||||||||||||||
| 45 | 0 | ▶ | { | ||||||||||||
|
Subroutine
ids: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 46 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
ids: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 47 | 0 | map $_->id, @{$self->compact()}; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | sub list($) | ||||||||||||||
| 51 | 1 | ▶ | { | ||||||||||||
|
Subroutine
list: called CC=2 SCAR=10.5
Pod
undocumented
| |||||||||||||||
| 52 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
list: not called CC=2 SCAR=10.5
Pod
undocumented
| |||||||||||||||
| 53 | 0 | ▶ | map defined($_) ? $_ : (), @{$self->{list}} | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | # Remove all breakpoints that we have recorded | ||||||||||||||
| 57 | 1 | ▶ | sub DESTROY() { | ||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=9.2
| |||||||||||||||
| 58 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=9.2
| |||||||||||||||
| 59 | 0 | for my $bp ($self->list) { | |||||||||||||
| 60 | 0 | $self->delete_by_brkpt($bp); | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | 0 | $self->{clear}; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | sub find($$) | ||||||||||||||
| 66 | 3 | ▶ | { | ||||||||||||
|
Subroutine
find: called CC=5 SCAR=21.9
Pod
undocumented
| |||||||||||||||
| 67 | 0 | ▶ | my ($self, $index) = @_; | ||||||||||||
|
Subroutine
find: not called CC=5 SCAR=21.9
Pod
undocumented
| |||||||||||||||
| 68 | 0 | ▶ | return undef unless $index =~ /^\d+$/; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 69 | 0 | for my $bp (@{$self->{list}}) { | |||||||||||||
| 70 | 0 | ▶ | next unless $bp; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 71 | 0 | ▶ | return $bp if $bp->id eq $index; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 72 | } | ||||||||||||||
| 73 | 0 | return undef; | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | sub delete($$) | ||||||||||||||
| 77 | 0 | ▶ | { | ||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 78 | 0 | ▶ | my ($self, $index) = @_; | ||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 79 | 0 | my $bp = $self->find($index); | |||||||||||||
| 80 | 0 | ▶ | if (defined ($bp)) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 81 | 0 | $self->delete_by_brkpt($bp); | |||||||||||||
| 82 | 0 | return $bp; | |||||||||||||
| 83 | } else { | ||||||||||||||
| 84 | 0 | return undef; | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | sub delete_by_brkpt($$) | ||||||||||||||
| 89 | 1 | ▶ | { | ||||||||||||
|
Subroutine
delete_by_brkpt: called CC=5 SCAR=24.3
Pod
undocumented
| |||||||||||||||
| 90 | 0 | ▶ | my ($self, $delete_bp) = @_; | ||||||||||||
|
Subroutine
delete_by_brkpt: not called CC=5 SCAR=24.3
Pod
undocumented
| |||||||||||||||
| 91 | 0 | for my $candidate (@{$self->{list}}) { | |||||||||||||
| 92 | 0 | ▶ | next unless defined $candidate; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 93 | 0 | ▶ | if ($candidate eq $delete_bp) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 94 | 0 | $candidate = undef; | |||||||||||||
| 95 | 0 | ▶ | $self->{dbgr} && $self->{dbgr}->delete_bp($delete_bp); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 96 | 0 | return $delete_bp; | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | } | ||||||||||||||
| 99 | 0 | return undef; | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | sub add($$) | ||||||||||||||
| 103 | 1 | ▶ | { | ||||||||||||
|
Subroutine
add: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||
| 104 | 0 | ▶ | my ($self, $brkpt) = @_; | ||||||||||||
|
Subroutine
add: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||
| 105 | 0 | push @{$self->{list}}, $brkpt; | |||||||||||||
| 106 | 0 | return $brkpt; | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | |||||||||||||||
| 109 | sub compact($) | ||||||||||||||
| 110 | 0 | ▶ | { | ||||||||||||
|
Subroutine
compact: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 111 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
compact: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 112 | 0 | my @new_list = (); | |||||||||||||
| 113 | 0 | for my $brkpt (@{$self->{list}}) { | |||||||||||||
| 114 | 0 | ▶ | next unless defined $brkpt; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 115 | 0 | push @new_list, $brkpt; | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | 0 | $self->{list} = \@new_list; | |||||||||||||
| 118 | 0 | return $self->{list}; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | |||||||||||||||
| 121 | sub is_empty($) | ||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||
|
Subroutine
is_empty: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 123 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
is_empty: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 124 | 0 | $self->compact(); | |||||||||||||
| 125 | 0 | return scalar(0 == @{$self->{list}}); | |||||||||||||
| 126 | } | ||||||||||||||
| 127 | |||||||||||||||
| 128 | sub max($) | ||||||||||||||
| 129 | 0 | ▶ | { | ||||||||||||
|
Subroutine
max: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 130 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
max: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 131 | 0 | my $max = 0; | |||||||||||||
| 132 | 0 | for my $brkpt (@{$self->{list}}) { | |||||||||||||
| 133 | 0 | ▶ | $max = $brkpt->id if $brkpt->id > $max; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 134 | } | ||||||||||||||
| 135 | 0 | return $max; | |||||||||||||
| 136 | } | ||||||||||||||
| 137 | |||||||||||||||
| 138 | sub size($) | ||||||||||||||
| 139 | 0 | ▶ | { | ||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 140 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 141 | 0 | $self->compact(); | |||||||||||||
| 142 | 0 | return scalar @{$self->{list}}; | |||||||||||||
| 143 | } | ||||||||||||||
| 144 | |||||||||||||||
| 145 | sub reset($) | ||||||||||||||
| 146 | 0 | ▶ | { | ||||||||||||
|
Subroutine
reset: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 147 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
reset: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 148 | 0 | for my $bp (@{$self->{list}}) { | |||||||||||||
| 149 | 0 | $self->{dbgr}->delete_bp($bp); | |||||||||||||
| 150 | } | ||||||||||||||
| 151 | 0 | $self->{list} = []; | |||||||||||||
| 152 | } | ||||||||||||||
| 153 | |||||||||||||||
| 154 | |||||||||||||||
| 155 | 12 | ▶ | unless (caller) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 156 | |||||||||||||||
| 157 | 0 | eval <<'EOE'; | |||||||||||||
| 158 | sub bp_status($$) | ||||||||||||||
| 159 | { | ||||||||||||||
| 160 | my ($brkpts, $i) = @_; | ||||||||||||||
| 161 | printf "list size: %s\n", $brkpts->size(); | ||||||||||||||
| 162 | printf "max: %d\n", $brkpts->max() // -1; | ||||||||||||||
| 163 | print $brkpts->inspect(); | ||||||||||||||
| 164 | print "--- ${i} ---\n"; | ||||||||||||||
| 165 | } | ||||||||||||||
| 166 | EOE | ||||||||||||||
| 167 | |||||||||||||||
| 168 | 0 | require Devel::Trepan::Core; | |||||||||||||
| 169 | 0 | my $dbgr = Devel::Trepan::Core->new; | |||||||||||||
| 170 | 0 | my $brkpts = Devel::Trepan::BrkptMgr->new($dbgr); | |||||||||||||
| 171 | 0 | bp_status($brkpts, 0); | |||||||||||||
| 172 | 0 | my $brkpt1 = DBBreak->new( | |||||||||||||
| 173 | type=>'brkpt', condition=>'1', id=>1, hits => 0, enabled => 1, | ||||||||||||||
| 174 | negate => 0, filename => __FILE__, line_num => __LINE__ | ||||||||||||||
| 175 | ); | ||||||||||||||
| 176 | |||||||||||||||
| 177 | 0 | $brkpts->add($brkpt1); | |||||||||||||
| 178 | 0 | bp_status($brkpts, 1); | |||||||||||||
| 179 | |||||||||||||||
| 180 | 0 | my $brkpt2 = DBBreak->new( | |||||||||||||
| 181 | type=>'brkpt', condition=>'x>5', id=>2, hits => 0, enabled => 0, | ||||||||||||||
| 182 | Negate => 0, filename => __FILE__, line_num => __LINE__ | ||||||||||||||
| 183 | ); | ||||||||||||||
| 184 | 0 | $brkpts->add($brkpt2); | |||||||||||||
| 185 | 0 | bp_status($brkpts, 2); | |||||||||||||
| 186 | |||||||||||||||
| 187 | 0 | $brkpts->delete_by_brkpt($brkpt1); | |||||||||||||
| 188 | 0 | bp_status($brkpts, 3); | |||||||||||||
| 189 | |||||||||||||||
| 190 | 0 | my $brkpt3 = DBBreak->new( | |||||||||||||
| 191 | type=>'brkpt', condition=>'y eq x', id=>3, hits => 0, enabled => 1, | ||||||||||||||
| 192 | negate => 1, filename => __FILE__, line_num => __LINE__ | ||||||||||||||
| 193 | ); | ||||||||||||||
| 194 | 0 | $brkpts->add($brkpt3); | |||||||||||||
| 195 | 0 | bp_status($brkpts, 4); | |||||||||||||
| 196 | 0 | print "id 3 found is", $brkpts->find(3), "\n"; | |||||||||||||
| 197 | 0 | ▶ | print "id 4 is undef\n" unless defined $brkpts->find(4); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 198 | 0 | ▶ | print "id 'a' is undef\n" unless defined $brkpts->find('a'); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 199 | |||||||||||||||
| 200 | # p brkpts.delete(2) | ||||||||||||||
| 201 | # p brkpts[2] | ||||||||||||||
| 202 | # bp_status(brkpts, 3) | ||||||||||||||
| 203 | |||||||||||||||
| 204 | # # Two of the same breakpoints but delete 1 and see that the | ||||||||||||||
| 205 | # # other still stays | ||||||||||||||
| 206 | # offset = frame.pc_offset | ||||||||||||||
| 207 | # b2 = Trepan::Breakpoint.new(iseq, offset) | ||||||||||||||
| 208 | # brkpts << b2 | ||||||||||||||
| 209 | # bp_status(brkpts, 4) | ||||||||||||||
| 210 | # b3 = Trepan::Breakpoint.new(iseq, offset) | ||||||||||||||
| 211 | # brkpts << b3 | ||||||||||||||
| 212 | # bp_status(brkpts, 5) | ||||||||||||||
| 213 | # brkpts.delete_by_brkpt(b2) | ||||||||||||||
| 214 | # bp_status(brkpts, 6) | ||||||||||||||
| 215 | # brkpts.delete_by_brkpt(b3) | ||||||||||||||
| 216 | # bp_status(brkpts, 7) | ||||||||||||||
| 217 | } | ||||||||||||||
| 218 | |||||||||||||||
| 219 | 12 | 1; | |||||||||||||