[commit: ghc] master: Improve access violation reporting on Windows (c13151e)

git at git.haskell.org git at git.haskell.org
Sun Jan 15 16:56:13 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/c13151e5ac774d38d7c5a807692851022c18fe6b/ghc

>---------------------------------------------------------------

commit c13151e5ac774d38d7c5a807692851022c18fe6b
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Sun Jan 15 11:54:41 2017 -0500

    Improve access violation reporting on Windows
    
    Summary:
    This patch is courtesy of @awson.
    
    Currently, whenever GHC catches a segfault on Windows, it simply reports the
    somewhat uninformative message
    `Segmentation fault/access violation in generated code`. This patch adds to
    the message the type of violation (read/write/dep) and location information,
    which should help debugging segfaults in the future.
    
    Fixes #13108.
    
    Test Plan: Build on Windows
    
    Reviewers: austin, erikd, bgamari, simonmar, Phyx
    
    Reviewed By: bgamari, Phyx
    
    Subscribers: awson, thomie, #ghc_windows_task_force
    
    Differential Revision: https://phabricator.haskell.org/D2969
    
    GHC Trac Issues: #13108


>---------------------------------------------------------------

c13151e5ac774d38d7c5a807692851022c18fe6b
 rts/win32/veh_excn.c                                        | 8 +++++++-
 testsuite/tests/rts/all.T                                   | 8 +++++++-
 testsuite/tests/rts/derefnull.stdout-i386-unknown-mingw32   | 2 +-
 testsuite/tests/rts/derefnull.stdout-x86_64-unknown-mingw32 | 2 +-
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/rts/win32/veh_excn.c b/rts/win32/veh_excn.c
index bf2151a..c94dc5a 100644
--- a/rts/win32/veh_excn.c
+++ b/rts/win32/veh_excn.c
@@ -32,6 +32,7 @@ PVOID __hs_handle = NULL;
 long WINAPI __hs_exception_handler(struct _EXCEPTION_POINTERS *exception_data)
 {
     long action = EXCEPTION_CONTINUE_SEARCH;
+    ULONG_PTR what;
 
     // When the system unwinds the VEH stack after having handled an excn,
     // return immediately.
@@ -49,7 +50,12 @@ long WINAPI __hs_exception_handler(struct _EXCEPTION_POINTERS *exception_data)
                 action = EXCEPTION_CONTINUE_EXECUTION;
                 break;
             case EXCEPTION_ACCESS_VIOLATION:
-                fprintf(stdout, "Segmentation fault/access violation in generated code\n");
+                what = exception_data->ExceptionRecord->ExceptionInformation[0];
+                fprintf(stdout, "Access violation in generated code"
+                                " when %s %p\n"
+                                , what == 0 ? "reading" : what == 1 ? "writing" : what == 8 ? "executing data at" : "?"
+                                , (void*) exception_data->ExceptionRecord->ExceptionInformation[1]
+                                );
                 action = EXCEPTION_CONTINUE_EXECUTION;
                 break;
             default:;
diff --git a/testsuite/tests/rts/all.T b/testsuite/tests/rts/all.T
index cf8e904..14f0cec 100644
--- a/testsuite/tests/rts/all.T
+++ b/testsuite/tests/rts/all.T
@@ -13,6 +13,12 @@ test('testmblockalloc',
 # See bug #101, test requires +RTS -c (or equivalently +RTS -M<something>)
 # only GHCi triggers the bug, but we run the test all ways for completeness.
 test('bug1010', normal, compile_and_run, ['+RTS -c -RTS'])
+
+def normalise_address(str):
+    return re.sub('Access violation in generated code when reading [0]+',
+                  'Access violation in generated code when reading ADDRESS',
+                  str)
+
 test('derefnull',
      [# LLVM Optimiser considers dereference of a null pointer
       # undefined and marks the code as unreachable which means
@@ -29,7 +35,7 @@ test('derefnull',
       when(platform('i386-apple-darwin'), [ignore_stderr, exit_code(139)]),
       when(platform('x86_64-apple-darwin'), [ignore_stderr, exit_code(139)]),
       when(platform('powerpc-apple-darwin'), [ignore_stderr, exit_code(139)]),
-      when(opsys('mingw32'), exit_code(1)),
+      when(opsys('mingw32'), [exit_code(1), normalise_fun(normalise_address)]),
       # since these test are supposed to crash the
       # profile report will be empty always.
       # so disable the check for profiling
diff --git a/testsuite/tests/rts/derefnull.stdout-i386-unknown-mingw32 b/testsuite/tests/rts/derefnull.stdout-i386-unknown-mingw32
index 5f2034d..4541b7f 100644
--- a/testsuite/tests/rts/derefnull.stdout-i386-unknown-mingw32
+++ b/testsuite/tests/rts/derefnull.stdout-i386-unknown-mingw32
@@ -1 +1 @@
-Segmentation fault/access violation in generated code
+Access violation in generated code when reading ADDRESS
diff --git a/testsuite/tests/rts/derefnull.stdout-x86_64-unknown-mingw32 b/testsuite/tests/rts/derefnull.stdout-x86_64-unknown-mingw32
index 5f2034d..4541b7f 100644
--- a/testsuite/tests/rts/derefnull.stdout-x86_64-unknown-mingw32
+++ b/testsuite/tests/rts/derefnull.stdout-x86_64-unknown-mingw32
@@ -1 +1 @@
-Segmentation fault/access violation in generated code
+Access violation in generated code when reading ADDRESS



More information about the ghc-commits mailing list