py/gc: Add CLEAR_ON_SWEEP option to debug mis-traced objects.

Accessing them will crash immediately instead still working for some time,
until overwritten by some other data, leading to much less deterministic
crashes.
This commit is contained in:
Paul Sokolovsky 2017-12-08 00:10:44 +02:00
parent 9ebc037eee
commit 9ef4be8b41
1 changed files with 7 additions and 0 deletions

View File

@ -44,6 +44,10 @@
// make this 1 to dump the heap each time it changes // make this 1 to dump the heap each time it changes
#define EXTENSIVE_HEAP_PROFILING (0) #define EXTENSIVE_HEAP_PROFILING (0)
// make this 1 to zero out swept memory to more eagerly
// detect untraced object still in use
#define CLEAR_ON_SWEEP (0)
#define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / BYTES_PER_WORD) #define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / BYTES_PER_WORD)
#define BYTES_PER_BLOCK (MICROPY_BYTES_PER_GC_BLOCK) #define BYTES_PER_BLOCK (MICROPY_BYTES_PER_GC_BLOCK)
@ -286,6 +290,9 @@ STATIC void gc_sweep(void) {
case AT_TAIL: case AT_TAIL:
if (free_tail) { if (free_tail) {
ATB_ANY_TO_FREE(block); ATB_ANY_TO_FREE(block);
#if CLEAR_ON_SWEEP
memset((void*)PTR_FROM_BLOCK(block), 0, BYTES_PER_BLOCK);
#endif
} }
break; break;