Skip to content

Commit 2bfbbba

Browse files
committed
Add environment variable for -Dr: PERL_DUMP_RE_MAX_LEN
The regex engine when displaying debugging info, say under -Dr, will elide data in order to keep the output from getting too long. For example, the number of code points in all of Unicode matched by \w is quite large, and so when displaying a pattern that matches this, only the first some number of them are printed, and the rest are truncated, represented by "...". Sometimes, one wants to see more than what the compiled-into-the-engine-max shows. This commit creates code to read this environment variable to override the default max lengths. This changes the lengths for everything to the input number, even if they have different compiled maximums in the absence of this variable. I'm not currently documenting this variable, as I don't think it works properly under threads, and we may want to alter the behavior in various ways as a result of gaining experience with using it.
1 parent c23916c commit 2bfbbba

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

embedvar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
#define PL_diehook (vTHX->Idiehook)
135135
#define PL_doswitches (vTHX->Idoswitches)
136136
#define PL_dowarn (vTHX->Idowarn)
137+
#define PL_dump_re_max_len (vTHX->Idump_re_max_len)
137138
#define PL_dumper_fd (vTHX->Idumper_fd)
138139
#define PL_dumpindent (vTHX->Idumpindent)
139140
#define PL_e_script (vTHX->Ie_script)

intrpvar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ PERLVARA(I, op_exec_cnt, OP_max+2, UV) /* Counts of executed OPs of the given ty
807807

808808
PERLVAR(I, random_state, PL_RANDOM_STATE_TYPE)
809809

810+
PERLVARI(I, dump_re_max_len, STRLEN, 0)
811+
810812
/* If you are adding a U8 or U16, check to see if there are 'Space' comments
811813
* above on where there are gaps which currently will be structure padding. */
812814

regcomp.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6700,6 +6700,10 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
67006700
/* Initialize these here instead of as-needed, as is quick and avoids
67016701
* having to test them each time otherwise */
67026702
if (! PL_AboveLatin1) {
6703+
#ifdef DEBUGGING
6704+
char * dump_len_string;
6705+
#endif
6706+
67036707
PL_AboveLatin1 = _new_invlist_C_array(AboveLatin1_invlist);
67046708
PL_Latin1 = _new_invlist_C_array(Latin1_invlist);
67056709
PL_UpperLatin1 = _new_invlist_C_array(UpperLatin1_invlist);
@@ -6713,6 +6717,14 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
67136717
PL_InBitmap = _new_invlist(2);
67146718
PL_InBitmap = _add_range_to_invlist(PL_InBitmap, 0,
67156719
NUM_ANYOF_CODE_POINTS - 1);
6720+
#ifdef DEBUGGING
6721+
dump_len_string = PerlEnv_getenv("PERL_DUMP_RE_MAX_LEN");
6722+
if ( ! dump_len_string
6723+
|| ! grok_atoUV(dump_len_string, &PL_dump_re_max_len, NULL))
6724+
{
6725+
PL_dump_re_max_len = 0;
6726+
}
6727+
#endif
67166728
}
67176729

67186730
pRExC_state->code_blocks = NULL;
@@ -18463,6 +18475,9 @@ Perl_regprop(pTHX_ const regexp *prog, SV *sv, const regnode *o, const regmatch_
1846318475
char *s = savesvpv(lv);
1846418476
const char * const orig_s = s; /* Save the beginning of
1846518477
's', so can be freed */
18478+
const STRLEN dump_len = (PL_dump_re_max_len)
18479+
? PL_dump_re_max_len
18480+
: 256;
1846618481

1846718482
/* Ignore anything before the first \n */
1846818483
while (*s && *s != '\n')
@@ -18491,7 +18506,7 @@ Perl_regprop(pTHX_ const regexp *prog, SV *sv, const regnode *o, const regmatch_
1849118506
if (*s == '\n') {
1849218507

1849318508
/* Truncate very long output */
18494-
if ((UV) (s - t) > 256) {
18509+
if ((UV) (s - t) > dump_len) {
1849518510
Perl_sv_catpvf(aTHX_ sv,
1849618511
"%.*s...",
1849718512
(int) (s - t),

regcomp.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,22 +1069,25 @@ re.pm, especially to the documentation.
10691069
PERL_UNUSED_VAR(re_debug_flags); GET_RE_DEBUG_FLAGS;
10701070

10711071
#define RE_PV_COLOR_DECL(rpv,rlen,isuni,dsv,pv,l,m,c1,c2) \
1072-
const char * const rpv = \
1073-
pv_pretty((dsv), (pv), (l), (m), \
1074-
PL_colors[(c1)],PL_colors[(c2)], \
1072+
const char * const rpv = \
1073+
pv_pretty((dsv), (pv), (l), \
1074+
(PL_dump_re_max_len) ? PL_dump_re_max_len : (m), \
1075+
PL_colors[(c1)],PL_colors[(c2)], \
10751076
PERL_PV_ESCAPE_RE|PERL_PV_ESCAPE_NONASCII |((isuni) ? PERL_PV_ESCAPE_UNI : 0) ); \
10761077
const int rlen = SvCUR(dsv)
10771078

1078-
#define RE_SV_ESCAPE(rpv,isuni,dsv,sv,m) \
1079-
const char * const rpv = \
1080-
pv_pretty((dsv), (SvPV_nolen_const(sv)), (SvCUR(sv)), (m), \
1081-
PL_colors[(c1)],PL_colors[(c2)], \
1079+
#define RE_SV_ESCAPE(rpv,isuni,dsv,sv,m) \
1080+
const char * const rpv = \
1081+
pv_pretty((dsv), (SvPV_nolen_const(sv)), (SvCUR(sv)), \
1082+
(PL_dump_re_max_len) ? PL_dump_re_max_len : (m), \
1083+
PL_colors[(c1)],PL_colors[(c2)], \
10821084
PERL_PV_ESCAPE_RE|PERL_PV_ESCAPE_NONASCII |((isuni) ? PERL_PV_ESCAPE_UNI : 0) )
10831085

10841086
#define RE_PV_QUOTED_DECL(rpv,isuni,dsv,pv,l,m) \
10851087
const char * const rpv = \
1086-
pv_pretty((dsv), (pv), (l), (m), \
1087-
PL_colors[0], PL_colors[1], \
1088+
pv_pretty((dsv), (pv), (l), \
1089+
(PL_dump_re_max_len) ? PL_dump_re_max_len : (m), \
1090+
PL_colors[0], PL_colors[1], \
10881091
( PERL_PV_PRETTY_QUOTE | PERL_PV_ESCAPE_RE | PERL_PV_ESCAPE_NONASCII | PERL_PV_PRETTY_ELLIPSES | \
10891092
((isuni) ? PERL_PV_ESCAPE_UNI : 0)) \
10901093
)

0 commit comments

Comments
 (0)