summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-03-04 20:58:28 -0700
committerKarl Williamson <khw@cpan.org>2020-03-18 17:38:19 -0600
commite0be78213ff4362a011b8be77ba8af2d5a307178 (patch)
tree6dd25442946cef9e4b512e59fcf3916cc244822a /pp_hot.c
parent1fe1d354d323db2d8a59f107855fc1f71ddc6ab5 (diff)
downloadperl-e0be78213ff4362a011b8be77ba8af2d5a307178.tar.gz
pp_match(): output regex debugging info
This fixes #17612 This adds an inline function to pp_hot to be called to determine if debugging info should be output or not, regardless of whether it comes from -Dr, or from a 'use re Debug' statement
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 1c4ff48e23..9698fb3727 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -34,6 +34,7 @@
#include "EXTERN.h"
#define PERL_IN_PP_HOT_C
#include "perl.h"
+#include "regcomp.h"
/* Hot code. */
@@ -2889,6 +2890,47 @@ PP(pp_qr)
RETURN;
}
+STATIC bool
+S_are_we_in_Debug_EXECUTE_r(pTHX)
+{
+ /* Given a 'use re' is in effect, does it ask for outputting execution
+ * debug info?
+ *
+ * This is separated from the sole place it's called, an inline function,
+ * because it is the large-ish slow portion of the function */
+
+ DECLARE_AND_GET_RE_DEBUG_FLAGS_NON_REGEX;
+
+ return cBOOL(RE_DEBUG_FLAG(RE_DEBUG_EXECUTE_MASK));
+}
+
+PERL_STATIC_INLINE bool
+S_should_we_output_Debug_r(pTHX_ regexp *prog)
+{
+ PERL_ARGS_ASSERT_SHOULD_WE_OUTPUT_DEBUG_R;
+
+ /* pp_match can output regex debugging info. This function returns a
+ * boolean as to whether or not it should.
+ *
+ * Under -Dr, it should. Any reasonable compiler will optimize this bit of
+ * code away on non-debugging builds. */
+ if (UNLIKELY(DEBUG_r_TEST)) {
+ return TRUE;
+ }
+
+ /* If the regex engine is using the non-debugging execution routine, then
+ * no debugging should be output. Same if the field is NULL that pluggable
+ * engines are not supposed to fill. */
+ if ( LIKELY(prog->engine->exec == &Perl_regexec_flags)
+ || UNLIKELY(prog->engine->op_comp == NULL))
+ {
+ return FALSE;
+ }
+
+ /* Otherwise have to check */
+ return S_are_we_in_Debug_EXECUTE_r(aTHX);
+}
+
PP(pp_match)
{
dSP; dTARG;
@@ -2944,7 +2986,9 @@ PP(pp_match)
pm->op_pmflags & PMf_USED
#endif
) {
- DEBUG_r(PerlIO_printf(Perl_debug_log, "?? already matched once"));
+ if (UNLIKELY(should_we_output_Debug_r(prog))) {
+ PerlIO_printf(Perl_debug_log, "?? already matched once");
+ }
goto nope;
}
@@ -2966,9 +3010,11 @@ PP(pp_match)
}
if (RXp_MINLEN(prog) >= 0 && (STRLEN)RXp_MINLEN(prog) > len) {
- DEBUG_r(PerlIO_printf(Perl_debug_log,
+ if (UNLIKELY(should_we_output_Debug_r(prog))) {
+ PerlIO_printf(Perl_debug_log,
"String shorter than min possible regex match (%zd < %zd)\n",
- len, RXp_MINLEN(prog)));
+ len, RXp_MINLEN(prog));
+ }
goto nope;
}