Make PL_firstgv and PL_secondgv refcounted

Otherwise freeing *a or *b in a sort block will result in a crash:

$ perl -e '@_=sort { delete $::{a}; 3 } 1..3'
Segmentation fault: 11
Make PL_envgv refcounted

Otherwise deleting $::{ENV} will make chdir crash:

$ perl -e 'delete $::{ENV}; chdir'
Segmentation fault: 11

This happens because PL_envgv points to a freed SV and GvHV(PL_envgv)
tries to access nonexistent fields.
[perl #119811] Remove %DB::lsub

Under the debugger (the -d switch), if there is a DB::sub subroutine,
then %DB::lsub gets autovivified during a call to an lvalue sub.  That
hash is never used.  The code for vivifying the *DB::lsub glob was
copied from *DB::sub when lsub was added, and *DB::sub does have a
hash (%DB::sub), but *DB::lsub doesn’t need one.
Don’t create %@ on startup

This hash has been unused since perl-5.005_02-2093-g98eae8f:

commit 98eae8f585b9800849b5e5482e2d405f21bab67e
Author: Gurusamy Sarathy <gsar@cpan.org>
Date:   Fri Oct 8 10:26:15 1999 +0000

    remove kludgey duplicate background error avoidance (caused
    "leaks"; %@ wasn't even user-visible under -Dusethreads);
    only repeats of most recent error are now avoided

    p4raw-id: //depot/perl@4316
Make PL_hintgv refcounted

Otherwise one can free it (by deleting the *^H glob) and
cause a crash:

$ perl -e 'delete $::{"\cH"}; ${^OPEN}=foo'
Segmentation fault: 11

That happens because PL_hintgv points to a freed scalar, and
GvHV(PL_hintgv) ends up trying to access nonexistent fields.
When deleting via hek, pass the computed hash value

In those cases where the hash key comes from a hek, we already have a
computed hash value, so pass that to hv_common.

The easiest way to accomplish this is to add a new macro.
gv:gv_try_downgrade: Leave PL_stderrgv alone

gv_try_downgrade exists to remove globs and subs that were (possibly
temporarily) vivified by bareword lookup.  It is called whenever a
gvop is freed and its gv looks like a candidate for downgrading.  That
means it applies, not only to potential sub calls, but also to *foo
and *bar.  gv_try_downgrade may delete a glob from the stash alto-
gether if it is empty.  So eval "*foo if 0" may delete the *foo glob.

PL_stderrgv is a shortcut variable that points to *STDERR.  When
PL_stderrgv is null, the real stderr is used as a fallback.

If gv_try_downgrade deletes *STDERR (which causes PL_stderrgv to be
cleared), it can could the behaviour, which is not supposed to happen.
It doesn’t actually delete *STDERR right now, because undef() vivifies
the scalar slot, disqualifying the glob from downgrading.

If we change undef not to vivify the scalar slot (I plan to soon, and
this commit prepares for it), then this is what would happen without
this commit:

$ perl -le 'close *{"STDERR"}; undef *{"STDERR"}; eval "*STDERR if 0"; *{"STDERR"} = *STDOUT{IO}; warn'
$ perl -le 'close *{"STDERR"}; undef *{"STDERR"}; *{"STDERR"} = *STDOUT{IO}; warn'
Warning: something's wrong at -e line 1.

Notice how the first one-liner (with the eval) produces no output.
Make PL_argvgv refcounted

Otherwise one can free it and cause assertion failures when other
things do SvREFCNT_inc on a freed scalar:

$ ./miniperl -le 'undef *x; delete $::{ARGV}; $x++; eval "BEGIN{undef *x} readline"'
Assertion failed: (SvTYPE(sv) != (svtype)SVTYPEMASK), function Perl_sv_clear, file sv.c, line 6215.
Abort trap: 6
gv:gv_try_downgrade: Leave PL_last_in_gv alone

gv_try_downgrade exists to remove globs and subs that were (possibly
temporarily) vivified by bareword lookup.  It is called whenever a
gvop is freed and its gv looks like a candidate for downgrading.  That
means it applies, not only to potential sub calls, but also to *foo
and *bar.  gv_try_downgrade may delete a glob from the stash alto-
gether if it is empty.  So eval "*foo if 0" may delete the *foo glob.

PL_last_in_gv is the internal variable underlying ${^LAST_FH}.  If
gv_try_downgrade deletes the last-read handle, then ${^LAST_FH}
will become undefined, whereas eval "*foo if 0" is not supposed to
do anything:

$ ./miniperl -le 'readline *{"foo"}; warn ${^LAST_FH}; eval "*foo if 0"; warn ${^LAST_FH}'
GLOB(0x7f8f5a0052a0) at -e line 1.
Warning: something's wrong at -e line 1.
[perl #54044] Make PL_replgv refcounted

Otherwise one can free it and make perl crash:

$ perl -e 'delete $::{"\cR"}; //'
Segmentation fault: 11

It crashes because PL_replgv now points to a freed SV which has no GV
slots, so GvSV on it fails.
Don’t assume *^R has a scalar

$ perl -e '*^R = *foo; /(?{})/'
Segmentation fault: 11
perl.h: Remove ERRHV

It has been unused by the core since 5.6.0 (98eae8f58) and is
unused on CPAN.
pat.t: suppress warning
Make PL_incgv fully refcounted

It was only reference-counted in the main thread:

$ ./perl -Ilib -e 'delete $::{INC}; eval q"my $foo : bar"'
$ ./perl -Ilib -e 'use threads; async {delete $::{INC}; eval q"my $foo : bar"}->join'
Assertion failed: (SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) == SVt_PVLV), function S_apply_attrs_my, file op.c, line 2600.
Abort trap: 6
pp.c:pp_undef: Don’t vivify the scalar slot

When PERL_DONT_CREATE_GVSV is defined, perl generally does not vivify
the scalar slot in every GV.  But it hides that implementation detail
by vivifying it when *foo{SCALAR} is accessed.

undef(*foo) was one exception to this.  It vivified the scalar in
the scalar slot regardless of whether PERL_DONT_CREATE_GVSV was
defined.

Until recently, it was not safe to remove this exception, because a
typeglob with no scalar could be a candidate for downgrading (see
gv.c:gv_try_downgrade), causing global pointers like PL_DBgv to point
to freed SVs.  Recent commits have fixed all those cases, so this
is now safe.
[perl #119799] Set breakpoints without *DB::dbline

The elements of the %{"_<..."} hashes (where ‘...’ is the filename),
whose keys are line numbers, are used to set breakpoints on the given
lines.  The corresponding @{"_<..."} array contains the actual lines
of source code.

%{"_<..."} actually acts on the array of lines that @DB::dbline is
aliased to.  The assumption is that *DB::dbline = *{"_<..."} will have
taken place first.  Hence, all %{"_<..."} hashes are the same, when it
comes to writing to keys.

It is more useful for each %{"_<..."} hash to set breakpoints on its
corresponding file’s lines regardless of whether @DB::dbline has been
aliased, so that is what this commit does.

Each hash’s mg_obj pointer in its dbfile magic now points to the
array, and magic_setdbline uses it instead of PL_DBline.