perl5db: fixes for issues related to overloads #23506
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When perl calls DB::sub in the debugger, it sets $DB::sub to the sub
being called. If we trigger any other subs to get called somewhere
inside DB::sub, this could cause DB::sub to be called again, overwriting
the global. Perl won't call DB::sub for any sub calls within the DB
namespace, but we could inadvertently trigger this via a sub override or
magic, like overloads.
Create a copy of the global value in a lexical to use inside the sub, to
avoid it ever getting overwritten.
DB::sub can be called by perl giving it either a name (if it can be
determined) or a code ref. There is special handling for AUTOLOAD subs
and threads::new. This could only be happen when given the name of the
sub, so there is no need to do these checks if given a reference.
Additionally, a reference could be an object, which could have
overloads. Those overloads could fail or otherwise complicate the normal
operation of DB::sub.
Add a ref check to the sub given to DB::sub to avoid these issues.
Fixes #23486