Fix segmentation fault when .prof file not writeable
authorThomas Miedema <thomasmiedema@gmail.com>
Tue, 26 Jan 2016 00:11:49 +0000 (01:11 +0100)
committerBen Gamari <ben@smart-cactus.org>
Wed, 27 Jan 2016 11:07:15 +0000 (12:07 +0100)
commit8efe964a0f31af30c5b860b7491f4f278884493b
treed54d80841377c5cd44f5ee08c21ced741052752d
parentfb6e8768fe818a3d45bc857f9dccc7d783b2f9e5
Fix segmentation fault when .prof file not writeable

There are two ways to do retainer profiling. Quoting from the user's guide:
  1. `+RTS -hr` "Breaks down the graph by retainer set"
  2. `+RTS -hr<cc> -h<x>`, where `-h<x>` is one of normal heap profiling
     break-down options (e.g. `-hc`), and `-hr<cc> means "Restrict the
     profile to closures with retainer sets containing cost-centre
     stacks with one of the specified cost centres at the top."

Retainer profiling writes to a .hp file, like the other heap profiling
options, but also to a .prof file. Therefore, when the .prof file is not
writeable for whatever reason, retainer profiling should be turned off
completely.

This worked ok when running the program with `+RTS -hr` (option 1), but a
segfault would occur when using `+RTS -hr<cc> -h<x>`, with `x!=r` (option 2).

This commit fixes that.

Reviewed by: bgamari

Differential Revision: https://phabricator.haskell.org/D1849

GHC Trac Issues: #11489

(cherry picked from commit 6d2bdfd8d40b926d7a11d003213220022a63d9f5)
rts/ProfHeap.c
rts/ProfHeap.h
rts/Profiling.c
testsuite/tests/profiling/should_run/Makefile
testsuite/tests/profiling/should_run/T11489.hs [new file with mode: 0644]
testsuite/tests/profiling/should_run/T11489.stderr [new file with mode: 0644]
testsuite/tests/profiling/should_run/all.T
testsuite/tests/rts/all.T