#define PERLDBf_NAMEANON 0x200 /* Informative names for anon subs */
#define PERLDBf_SAVESRC 0x400 /* Save source lines into @{"_<$filename"} */
#define PERLDBf_SAVESRC_NOSUBS 0x800 /* Including evals that generate no subrouties */
+#if 0 /* Not yet working. */
#define PERLDBf_SAVESRC_INVALID 0x1000 /* Save source that did not compile */
+#endif
#define PERLDB_SUB (PL_perldb && (PL_perldb & PERLDBf_SUB))
#define PERLDB_LINE (PL_perldb && (PL_perldb & PERLDBf_LINE))
#define PERLDB_NAMEANON (PL_perldb && (PL_perldb & PERLDBf_NAMEANON))
#define PERLDB_SAVESRC (PL_perldb && (PL_perldb & PERLDBf_SAVESRC))
#define PERLDB_SAVESRC_NOSUBS (PL_perldb && (PL_perldb & PERLDBf_SAVESRC_NOSUBS))
+#if 0 /* Not yet working. */
#define PERLDB_SAVESRC_INVALID (PL_perldb && (PL_perldb & PERLDBf_SAVESRC_INVALID))
+#endif
#ifdef USE_LOCALE_NUMERIC
if (ok ? (was != PL_breakable_sub_gen /* Some subs defined here. */
? (PERLDB_LINE || PERLDB_SAVESRC)
: PERLDB_SAVESRC_NOSUBS)
- : PERLDB_SAVESRC_INVALID) {
+ : 0 /* PERLDB_SAVESRC_INVALID */
+ /* Much that I'd like to think that it was this trivial to add this
+ feature, it's not, due to
+ lex_end();
+ LEAVE;
+ in S_doeval() for the failure case. So really we want a more
+ sophisticated way of (optionally) clearing the source code.
+ Particularly as the current way is buggy, as a syntactically
+ invalid eval string can still define a subroutine that is retained,
+ and the user may wish to breakpoint. */) {
/* Just need to change the string in our writable scratch buffer that
will be used at scope exit to delete this eval's "file" name, to
something safe. The key names are of the form "_<(eval 1)" upwards,
use strict;
-plan (tests => 21);
+plan (tests => 55);
$^P = 0xA;
is (@before, 0, "No evals");
my %seen;
-my $name = 'foo';
-
-for my $sep (' ', "\0") {
- my $prog = "sub $name {
- 'Perl${sep}Rules'
-};
-1;
-";
-
- eval $prog or die;
+sub check_retained_lines {
+ my ($prog, $name) = @_;
# Is there a more efficient way to write this?
my @expect_lines = (undef, map ({"$_\n"} split "\n", $prog), "\n", ';');
my @got_lines = @{$::{$keys[0]}};
- is (@got_lines, @expect_lines, "Right number of lines for " . ord $sep);
+ is (@got_lines, @expect_lines, "Right number of lines for $name");
for (0..$#expect_lines) {
is ($got_lines[$_], $expect_lines[$_], "Line $_ is correct");
}
$seen{$keys[0]}++;
+}
+
+my $name = 'foo';
+
+for my $sep (' ', "\0") {
+
+ my $prog = "sub $name {
+ 'Perl${sep}Rules'
+};
+1;
+";
+
+ eval $prog or die;
+ check_retained_lines($prog, ord $sep);
$name++;
}
-is (eval '1 + 1', 2, 'String eval works');
+foreach my $flags (0x0, 0x800, 0x1000, 0x1800) {
+ local $^P = $^P | $flags;
+ # This is easier if we accept that the guts eval will add a trailing \n
+ # for us
+ my $prog = "1 + 1 + 1\n";
+ my $fail = "1 + \n";
+
+ is (eval $prog, 3, 'String eval works');
+ if ($flags & 0x800) {
+ check_retained_lines($prog, sprintf "%#X", $^P);
+ } else {
+ my @after = grep { /eval/ } keys %::;
+
+ is (@after, 0 + keys %seen,
+ "evals that don't define subroutines are correctly cleaned up");
+ }
-my @after = grep { /eval/ } keys %::;
+ is (eval $fail, undef, 'Failed string eval fails');
-is (@after, 0 + keys %seen,
- "evals that don't define subroutines are correctly cleaned up");
+ if ($flags & 0x1000) {
+ TODO: {
+ todo_skip "Can't yet retain lines for evals with syntax errors", 6;
+ check_retained_lines($fail, sprintf "%#X", $^P);
+ }
+ } else {
+ my @after = grep { /eval/ } keys %::;
+ is (@after, 0 + keys %seen,
+ "evals that fail are correctly cleaned up");
+ }
+}