grep/pcre2: add GREP_PCRE2_DEBUG_MALLOC debug mode
Add optional printing of PCREv2 allocations to stderr for a developer who manually changes the GREP_PCRE2_DEBUG_MALLOC definition to "1". You need to manually change the definition in the source file similar to the DEBUG_MAILMAP, there's no Makefile knob for this. This will be referenced a subsequent commit, and is generally useful to manually see what's going on with PCREv2 allocations while working on that code. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Feb 18, 2021 at 01:07 UTC
a39b4003f0e4515da5d88480c24ec27196dabfb7
1 file changed
+10
grep.c
+10
@@ -42,15 +42,25 @@ static struct grep_opt grep_defaults = {
42
43
#ifdef USE_LIBPCRE2
44
static pcre2_general_context *pcre2_global_context;
45
+#define GREP_PCRE2_DEBUG_MALLOC 0
46
47
static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
48
{
49
void *pointer = malloc(size);
50
+#if GREP_PCRE2_DEBUG_MALLOC
51
+ static int count = 1;
52
+ fprintf(stderr, "PCRE2:%p -> #%02d: alloc(%lu)\n", pointer, count++, size);
53
+#endif
54
return pointer;
55
}
56
57
static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
58
{
59
+#if GREP_PCRE2_DEBUG_MALLOC
60
+ static int count = 1;
61
+ if (pointer)
62
+ fprintf(stderr, "PCRE2:%p -> #%02d: free()\n", pointer, count++);
63
+#endif
64
free(pointer);
65
}
66
#endif