Skip to content

Commit 1c2da39

Browse files
committed
signatures: generate only one debug breakable line for signatures
With the debugger enabled the argcheck op and each argelem op generated to process a function signature would have an associated dbstate op, allowing the debugger to step on that op. This can be confusing and/or onerous when stepping through code, since for a signature with 7 arguments you'd have 9 steps to get past the prologue of the sub. Make most of these dbstates into nextstates to make them non-steppable. Fixes #22602
1 parent 55a059e commit 1c2da39

File tree

7 files changed

+47
-10
lines changed

7 files changed

+47
-10
lines changed

lib/perl5db.t

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,6 +3662,35 @@ EOS
36623662
$wrapper->contents_like(qr/print "2\\n"/, "break immediately after defining problem");
36633663
}
36643664

3665+
{
3666+
my $wrapper = DebugWrap->new(
3667+
{
3668+
cmds =>
3669+
[
3670+
"s",
3671+
"s",
3672+
"s",
3673+
"s",
3674+
"s",
3675+
"s",
3676+
"s",
3677+
"q",
3678+
],
3679+
prog => \<<'EOS',
3680+
use v5.40.0;
3681+
sub four ($x1, $x2, $x3, $x4) { # start sub four
3682+
print $x1, $x2, $x3, $x4;
3683+
}
3684+
four(1,2,3,4);
3685+
EOS
3686+
}
3687+
);
3688+
my $content = $wrapper->_contents;
3689+
my $count = () = $content =~ /start sub four/g;
3690+
is($count, 1, "expect to step on sub four entry once")
3691+
or diag $content;
3692+
}
3693+
36653694
done_testing();
36663695

36673696
END {

op.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8896,7 +8896,8 @@ Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
88968896
flags &= ~SVf_UTF8;
88978897

88988898
NewOp(1101, cop, 1, COP);
8899-
if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) {
8899+
if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash &&
8900+
!(flags & OPf_FORCE_NEXTSTATE)) {
89008901
OpTYPE_set(cop, OP_DBSTATE);
89018902
}
89028903
else {

op.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ Deprecated. Use C<GIMME_V> instead.
171171
op_convert_list to set op_folded. */
172172
#define OPf_FOLDED (1<<16)
173173

174+
/* force newSTATEOP() to make an OP_NEXTSTATE.
175+
176+
This is useful if you need to intro_my() but not make a breakable
177+
op.
178+
*/
179+
#define OPf_FORCE_NEXTSTATE (1 << 17)
180+
174181
/* old names; don't use in new code, but don't break them, either */
175182
#define OPf_LIST OPf_WANT_LIST
176183
#define OPf_KNOW OPf_WANT

perly.act

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

perly.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

perly.tab

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

perly.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
837837
yyerror("A slurpy parameter may not have "
838838
"a default value");
839839

840-
$$ = var ? newSTATEOP(0, NULL, var) : NULL;
840+
$$ = var ? newSTATEOP(OPf_FORCE_NEXTSTATE, NULL, var) : NULL;
841841
}
842842
;
843843

@@ -913,7 +913,7 @@ sigscalarelem:
913913
"follows optional parameter");
914914
}
915915

916-
$$ = var ? newSTATEOP(0, NULL, var) : NULL;
916+
$$ = var ? newSTATEOP(OPf_FORCE_NEXTSTATE, NULL, var) : NULL;
917917
}
918918
;
919919

@@ -985,7 +985,7 @@ subsigguts:
985985
(UNOP_AUX_item *)aux);
986986
sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
987987
sigops = op_prepend_elem(OP_LINESEQ,
988-
newSTATEOP(0, NULL, NULL),
988+
newSTATEOP(OPf_FORCE_NEXTSTATE, NULL, NULL),
989989
sigops);
990990
/* a nextstate at the end handles context
991991
* correctly for an empty sub body */

0 commit comments

Comments
 (0)