summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Guggenmos <tguggenm@redhat.com>2019-09-07 15:32:06 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-03 12:17:33 -0400
commit47386fe85a412c8aa35f6bcbce0d41f0eed03b65 (patch)
treeeb269c7dd0f13ee5803d22a6bd5009596bcda17b
parentee6324adfed737fbf9ca3c36538145542b425617 (diff)
downloadhaskell-47386fe85a412c8aa35f6bcbce0d41f0eed03b65.tar.gz
Add new debug flag -DZ
Zeros heap memory after gc freed it.
-rw-r--r--docs/users_guide/runtime_control.rst1
-rw-r--r--includes/rts/Flags.h1
-rw-r--r--rts/Linker.c4
-rw-r--r--rts/RtsFlags.c11
-rw-r--r--rts/RtsUtils.c2
-rw-r--r--rts/Trace.h1
-rw-r--r--rts/sm/BlockAlloc.c6
-rw-r--r--rts/sm/Storage.c2
-rw-r--r--testsuite/tests/rts/all.T1
-rw-r--r--testsuite/tests/rts/test-zeroongc.hs1
-rw-r--r--testsuite/tests/rts/test-zeroongc.stdout1
11 files changed, 24 insertions, 7 deletions
diff --git a/docs/users_guide/runtime_control.rst b/docs/users_guide/runtime_control.rst
index 77b86e3c2a..32d665da66 100644
--- a/docs/users_guide/runtime_control.rst
+++ b/docs/users_guide/runtime_control.rst
@@ -1161,6 +1161,7 @@ recommended for everyday use!
.. rts-flag:: -Dg DEBUG: gc
.. rts-flag:: -Db DEBUG: block
.. rts-flag:: -DS DEBUG: sanity
+.. rts-flag:: -DZ DEBUG: zero freed memory on GC
.. rts-flag:: -Dt DEBUG: stable
.. rts-flag:: -Dp DEBUG: prof
.. rts-flag:: -Da DEBUG: apply
diff --git a/includes/rts/Flags.h b/includes/rts/Flags.h
index 41fcf088d1..b3caf13c1f 100644
--- a/includes/rts/Flags.h
+++ b/includes/rts/Flags.h
@@ -97,6 +97,7 @@ typedef struct _DEBUG_FLAGS {
bool gc; /* 'g' */
bool block_alloc; /* 'b' */
bool sanity; /* 'S' warning: might be expensive! */
+ bool zero_on_gc; /* 'Z' */
bool stable; /* 't' */
bool prof; /* 'p' */
bool linker; /* 'l' the object linker */
diff --git a/rts/Linker.c b/rts/Linker.c
index 54e5049a58..1f3d8162be 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1185,7 +1185,7 @@ void freeObjectCode (ObjectCode *oc)
oc->sections[i].mapped_size);
break;
case SECTION_M32:
- IF_DEBUG(sanity,
+ IF_DEBUG(zero_on_gc,
memset(oc->sections[i].start,
0x00, oc->sections[i].size));
m32_free(oc->sections[i].start,
@@ -1193,7 +1193,7 @@ void freeObjectCode (ObjectCode *oc)
break;
#endif
case SECTION_MALLOC:
- IF_DEBUG(sanity,
+ IF_DEBUG(zero_on_gc,
memset(oc->sections[i].start,
0x00, oc->sections[i].size));
stgFree(oc->sections[i].start);
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index cbc9a333ec..d4301c414f 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -181,6 +181,7 @@ void initRtsFlagsDefaults(void)
RtsFlags.DebugFlags.gc = false;
RtsFlags.DebugFlags.block_alloc = false;
RtsFlags.DebugFlags.sanity = false;
+ RtsFlags.DebugFlags.zero_on_gc = false;
RtsFlags.DebugFlags.stable = false;
RtsFlags.DebugFlags.stm = false;
RtsFlags.DebugFlags.prof = false;
@@ -405,6 +406,7 @@ usage_text[] = {
" -Dg DEBUG: gc",
" -Db DEBUG: block",
" -DS DEBUG: sanity",
+" -DZ DEBUG: zero freed memory during GC",
" -Dt DEBUG: stable",
" -Dp DEBUG: prof",
" -Da DEBUG: apply",
@@ -1861,6 +1863,9 @@ static void read_debug_flags(const char* arg)
case 'S':
RtsFlags.DebugFlags.sanity = true;
break;
+ case 'Z':
+ RtsFlags.DebugFlags.zero_on_gc = true;
+ break;
case 't':
RtsFlags.DebugFlags.stable = true;
break;
@@ -1895,6 +1900,12 @@ static void read_debug_flags(const char* arg)
// -Dx also turns on -v. Use -l to direct trace
// events to the .eventlog file instead.
RtsFlags.TraceFlags.tracing = TRACE_STDERR;
+
+ // sanity implies zero_on_gc
+ if(RtsFlags.DebugFlags.sanity){
+ RtsFlags.DebugFlags.zero_on_gc = true;
+ }
+
}
#endif
diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c
index 2a53d18572..b9ddb2a345 100644
--- a/rts/RtsUtils.c
+++ b/rts/RtsUtils.c
@@ -79,7 +79,7 @@ stgMallocBytes (size_t n, char *msg)
rtsConfig.mallocFailHook((W_) n, msg);
stg_exit(EXIT_INTERNAL_ERROR);
}
- IF_DEBUG(sanity, memset(space, 0xbb, n));
+ IF_DEBUG(zero_on_gc, memset(space, 0xbb, n));
return space;
}
diff --git a/rts/Trace.h b/rts/Trace.h
index 9985adc52f..d3bb226000 100644
--- a/rts/Trace.h
+++ b/rts/Trace.h
@@ -52,6 +52,7 @@ enum CapsetType { CapsetTypeCustom = CAPSET_TYPE_CUSTOM,
#define DEBUG_gc RtsFlags.DebugFlags.gc
#define DEBUG_block_alloc RtsFlags.DebugFlags.alloc
#define DEBUG_sanity RtsFlags.DebugFlags.sanity
+#define DEBUG_zero_on_gc RtsFlags.DebugFlags.zero_on_gc
#define DEBUG_stable RtsFlags.DebugFlags.stable
#define DEBUG_stm RtsFlags.DebugFlags.stm
#define DEBUG_prof RtsFlags.DebugFlags.prof
diff --git a/rts/sm/BlockAlloc.c b/rts/sm/BlockAlloc.c
index bbb4f8a6c1..f9e3d11407 100644
--- a/rts/sm/BlockAlloc.c
+++ b/rts/sm/BlockAlloc.c
@@ -456,7 +456,7 @@ allocGroupOnNode (uint32_t node, W_ n)
}
finish:
- IF_DEBUG(sanity, memset(bd->start, 0xaa, bd->blocks * BLOCK_SIZE));
+ IF_DEBUG(zero_on_gc, memset(bd->start, 0xaa, bd->blocks * BLOCK_SIZE));
IF_DEBUG(sanity, checkFreeListSanity());
return bd;
}
@@ -531,7 +531,7 @@ bdescr* allocLargeChunkOnNode (uint32_t node, W_ min, W_ max)
recordAllocatedBlocks(node, bd->blocks);
- IF_DEBUG(sanity, memset(bd->start, 0xaa, bd->blocks * BLOCK_SIZE));
+ IF_DEBUG(zero_on_gc, memset(bd->start, 0xaa, bd->blocks * BLOCK_SIZE));
IF_DEBUG(sanity, checkFreeListSanity());
return bd;
}
@@ -656,7 +656,7 @@ freeGroup(bdescr *p)
p->gen = NULL;
p->gen_no = 0;
/* fill the block group with garbage if sanity checking is on */
- IF_DEBUG(sanity,memset(p->start, 0xaa, (W_)p->blocks * BLOCK_SIZE));
+ IF_DEBUG(zero_on_gc, memset(p->start, 0xaa, (W_)p->blocks * BLOCK_SIZE));
if (p->blocks == 0) barf("freeGroup: block size is zero");
diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c
index 3f91905f3c..d4be531c73 100644
--- a/rts/sm/Storage.c
+++ b/rts/sm/Storage.c
@@ -650,7 +650,7 @@ resetNurseries (void)
ASSERT(bd->gen_no == 0);
ASSERT(bd->gen == g0);
ASSERT(bd->node == capNoToNumaNode(n));
- IF_DEBUG(sanity, memset(bd->start, 0xaa, BLOCK_SIZE));
+ IF_DEBUG(zero_on_gc, memset(bd->start, 0xaa, BLOCK_SIZE));
}
}
#endif
diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T
index 9f2c064f9b..ba5b139efe 100644
--- a/testsuite/tests/rts/all.T
+++ b/testsuite/tests/rts/all.T
@@ -392,3 +392,4 @@ test('keep-cafs',
makefile_test, ['KeepCafs'])
test('T16514', unless(opsys('mingw32'), skip), compile_and_run, ['T16514_c.cpp -lstdc++'])
+test('test-zeroongc', extra_run_opts('-DZ'), compile_and_run, ['-debug'])
diff --git a/testsuite/tests/rts/test-zeroongc.hs b/testsuite/tests/rts/test-zeroongc.hs
new file mode 100644
index 0000000000..73566f6f20
--- /dev/null
+++ b/testsuite/tests/rts/test-zeroongc.hs
@@ -0,0 +1 @@
+main = putStrLn "Hello World"
diff --git a/testsuite/tests/rts/test-zeroongc.stdout b/testsuite/tests/rts/test-zeroongc.stdout
new file mode 100644
index 0000000000..557db03de9
--- /dev/null
+++ b/testsuite/tests/rts/test-zeroongc.stdout
@@ -0,0 +1 @@
+Hello World