9 # This test depends on t/lib/Devel/switchd*.pm.
15 my $filename = tempfile();
17 open my $f, ">$filename"
18 or skip( "Can't write temp file $filename: $!" );
19 print $f <<'__SWDTEST__';
21 sub bar { $_[0] * $_[0] }
25 $s += Bar::bar($_) for 1..$_[0];
31 $| = 1; # Unbufferize.
33 switches => [ '-Ilib', '-f', '-d:switchd' ],
34 progfile => $filename,
38 qr/^sub<Devel::switchd::import>;import<Devel::switchd>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/,
39 'Got debugging output: 1');
41 switches => [ '-Ilib', '-f', '-d:switchd=a,42' ],
42 progfile => $filename,
46 qr/^sub<Devel::switchd::import>;import<Devel::switchd a 42>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/,
47 'Got debugging output: 2');
49 switches => [ '-Ilib', '-f', '-d:-switchd=a,42' ],
50 progfile => $filename,
54 qr/^sub<Devel::switchd::unimport>;unimport<Devel::switchd a 42>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/,
55 'Got debugging output: 3');
60 runperl( # less is useful for something :-)
61 switches => [ '"-Mless ++INC->{q-Devel/_.pm-}"' ],
64 'sub DB::DB{} print scalar @{q/_</.__FILE__}',
69 'The debugger can see the lines of the main program under #!perl -d',
74 switches => [ '"-Mless ++INC->{q-Devel/_.pm-}"' ],
77 'sub DB::DB{} print line=>__LINE__',
81 '#!perl -d:whatever does not throw line numbers off';
86 switches => [ '-Ilib', '-d:switchd_empty' ],
88 'sub foo { print qq _1\n_ }',
90 '*foo = sub { print qq _2\n_ };',
95 'Subroutine redefinition works in the debugger [perl #48332]',
98 # [rt.cpan.org #69862]
101 switches => [ '-Ilib', '-d:switchd_empty' ],
103 'sub DB::sub { goto &$DB::sub }',
104 'sub foo { print qq _1\n_ }',
105 'sub bar { print qq _2\n_ }',
106 'delete $::{foo}; eval { foo() };',
107 'my $bar = *bar; undef *bar; eval { &$bar };',
111 'Subroutines no longer found under their names can be called',
114 # [rt.cpan.org #69862]
117 switches => [ '-Ilib', '-d:switchd_empty' ],
119 'sub DB::sub { goto &$DB::sub }',
120 'sub foo { goto &bar::baz; }',
121 'sub bar::baz { print qq _ok\n_ }',
122 'delete $::{bar::::};',
127 'No crash when calling orphaned subroutine via goto &',
130 # test when DB::DB is seen but not defined [perl #114990]
133 switches => [ '-Ilib', '-d:nodb' ],
137 qr/^No DB::DB routine defined/,
138 "No crash when *DB::DB exists but not &DB::DB",
142 switches => [ '-Ilib' ],
143 prog => 'sub DB::DB; BEGIN { $^P = 0x22; } for(0..9){ warn }',
146 qr/^No DB::DB routine defined/,
147 "No crash when &DB::DB exists but isn't actually defined",
149 # or seen and defined later
152 switches => [ '-Ilib', '-d:nodb' ], # nodb.pm contains *DB::DB...if 0
153 prog => 'warn; sub DB::DB { print qq-ok\n-; exit }',
157 "DB::DB works after '*DB::DB if 0'",
160 # [perl #115742] Recursive DB::DB clobbering its own pad
163 switches => [ '-Ilib' ],
164 progs => [ split "\n", <<'='
172 $^D |= 1 << 30; # allow recursive calls
174 print $x//q-u-, qq-\n-;
184 "Recursive DB::DB does not clobber its own pad",
190 switches => [ '-Ilib', '-d:switchd_empty' ],
191 prog => 'print @{q|_<-e|}',
193 qr "use Devel::switchd_empty;(?:BEGIN|\r?\nprint)",
194 # miniperl tacks a BEGIN block on to the same line
195 'Copy on write does not mangle ${"_<-e"}[0] [perl #118627]',
198 # PERL5DB with embedded newlines
200 local $ENV{PERL5DB} = "sub DB::DB{}\nwarn";
203 switches => [ '-Ilib', '-ld' ],
207 "Warning: something's wrong.\n"
208 ."Warning: something's wrong at -e line 1.\n",
209 'PERL5DB with embedded newlines',
213 # test that DB::goto works
216 switches => [ '-Ilib', '-d:switchd_goto' ],
217 prog => 'sub baz { print qq|hello;\n| } sub foo { goto &baz } foo()',
220 "goto<main::baz>;hello;\n",
224 # Test that %DB::lsub is not vivified
227 switches => [ '-Ilib', '-d:switchd_empty' ],
228 progs => ['sub DB::sub {} sub foo : lvalue {} foo();',
229 'print qq-ok\n- unless defined *DB::lsub{HASH}'],
232 "%DB::lsub is not vivified"
235 # Test setting of breakpoints without *DB::dbline aliased
238 switches => [ '-Ilib', '-d:nodb' ],
239 progs => [ split "\n",
241 $DB::single = 0, return if $DB::single; print qq[ok\n]; exit
243 ${q(_<).__FILE__}{6} = 1; # set a breakpoint
253 "setting breakpoints without *DB::dbline aliased"
257 # Check that utf8 caches are flushed when $DB::sub is set
260 switches => [ '-Ilib', '-d:switchd_empty' ],
261 progs => [ split "\n",
262 'sub DB::sub{length($DB::sub); goto &$DB::sub}
265 eval qq|sub oo\x{25f} { 42 }
266 sub ooooo\x{25f} { oo\x{25f}() }
275 'UTF8 length caches on $DB::sub are flushed'
278 # [perl #122771] -d conflicting with sort optimisations
281 switches => [ '-Ilib', '-d:switchd_empty' ],
282 prog => 'BEGIN { $^P &= ~0x4 } sort { $$b <=> $$a } (); print qq-42\n-',
285 '-d does not conflict with sort optimisations'
289 skip_if_miniperl("under miniperl", 1);
292 switches => [ '-Ilib', '-d:switchd_empty' ],
293 progs => [ split "\n",
296 print qq/debugged\n/;
302 "\$DB::single set to overload"
308 # On some platforms, it's possible that calls to getenv() will
309 # return a pointer to statically allocated data that may be
310 # overwritten by subsequent calls to getenv/putenv/setenv/unsetenv.
312 # In perl.c, s = PerlEnv_GetEnv("PERL5OPT") is called, and
313 # then moreswitches(s), which, if -d:switchd_empty is given,
314 # will call my_setenv("PERL5DB", "use Devel::switchd_empty"),
315 # and then return to continue parsing s.
317 # This may need -Accflags="-DPERL_USE_SAFE_PUTENV" to fail on
320 local $ENV{PERL5OPT} = '-d:switchd_empty';
324 switches => [ '-Ilib' ], prog => 'print q(hi)',
327 'putenv does not interfere with PERL5OPT parsing',