[Issue 15190] New: scope(success/failure) are oddly implemented and mask stack traces

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Oct 11 13:32:53 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15190

          Issue ID: 15190
           Summary: scope(success/failure) are oddly implemented and mask
                    stack traces
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: thecybershadow at gmail.com

Created attachment 1558
  --> https://issues.dlang.org/attachment.cgi?id=1558&action=edit
Demonstration program

scope statements seem to be rethrowing exceptions, or otherwise causing them to
be (re)thrown them from within the stack frame of the function containing the
scope statement, and not the function where the exception was thrown. This
causes loss of information on the exception's origin, which makes debugging
difficult. This is especially severe when the exception does not itself contain
a stack trace (e.g. it's an OutOfMemoryError or an
InvalidMemoryOperationError).

I'm attaching a demonstration program. To reproduce the issue, compile the
program (and specify one of the defined versions), start it under gdb and run
"break _d_throwc", "run" and "where". Depending on the version specified, the
f!int function invocations will or will not be visible in the stack trace
displayed by gdb.

Here are my results (Linux, DMD64 v2.068.1, gdb 7.7.1):

Version | f!int visible? | Description
--------+----------------+--------------------
test0   | Yes            | No scope/try blocks
testSS  | No             | scope(success)
testSF  | No             | scope(failure)
testSX  | Yes            | scope(exit)
testTN  | Yes            | try/catch
testTF  | Yes            | try/finally

>From what was tested, only scope(success) and scope(failure) rethrew the
exception from main().

Things of note:

1. As far as I can see, scope(success) has no reason to interfere with
exceptions at all, all it should do is virtually insert code before every
return point in the function.

2. scope(exit) displays the full stack trace, despite that it is simply the
union of scope(success) and scope(failure).

--


More information about the Digitalmars-d-bugs mailing list