Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#44 Structured Exception Handling missing

Known_bugs
closed-fixed
nobody
gcc (462)
2014-08-12
2001-05-18
David Gravereaux
No

Although Win32 SEH is an OS `feature`, it requires new
language semantics:

http://msdn.microsoft.com/library/devprods/vs6/visualc/
vccore/_core_exception_handling_topics_.28.seh.29.htm

The attached file should compile with mingw.

The M$VC++ understands it:
D:\itcl_exp>cl -c SEHtest.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights
reserved.

sehtest.c

D:\itcl_exp>

MinGW does not:
daveg@HALEAKALA d:/itcl_exp
$ gcc -c -mno-cygwin SEHtest.c
SEHtest.c: In function `SomeCloseProc':
SEHtest.c:7: `__try' undeclared (first use in this
function)
SEHtest.c:7: (Each undeclared identifier is reported
only once
SEHtest.c:7: for each function it appears in.)
SEHtest.c:7: parse error before `{'
SEHtest.c: At top level:
SEHtest.c:11: syntax error before `{'
SEHtest.c:15: parse error before `1'
SEHtest.c:18: parse error before `return'

daveg@HALEAKALA d:/itcl_exp
$

Discussion

  • test case

     
    Attachments
  • Logged In: YES
    user_id=7549

    SEHtest.c:7: `__try' undeclared (first use in this function)

    __try is not a function. __try is a built-in language
    statement, and has semantics, to implement SEH. __leave is
    only valid within a __try block. GetExceptionCode() is not
    a function either. It's a keyword only valid within the
    except filter. I could keep going on defining the rules,
    but I'll save my typing energy for other things :)

    Please don't consider this an M$ hack job. SEH is very
    important to some users, like myself. Tcl cannot be
    compiled by MinGW due to this missing feature.

     
  • Danny Smith
    Danny Smith
    2001-05-18

    Logged In: YES
    user_id=11494

    Can you show me in the ANSI standard or any standard for
    that matter where SEH is defined as "built-in language
    statement"?

    I agree that SEH is useful and very important to some
    users, and I wish I knew enough about assembly programming
    to do something about it. But...

    BTW TCL 8.3.3 can be compiled with mingw, with a few simple
    patches to the __try blocks, which essentially convert them
    to no-ops. Crashes aren't handled very gracefully, but it
    will compile and run. I have been intending to submit
    patches to TCL but have been delayed by the change in host
    of their site.

    Danny

     
  • Logged In: YES
    user_id=7549

    >Can you show me in the ANSI standard or any standard for
    >that matter where SEH is defined as "built-in language
    >statement"?

    Agreed! It won't be there.

    >I agree that SEH is useful and very important to some
    >users, and I wish I knew enough about assembly programming
    >to do something about it. But...

    Same. The author of LCC-Win32 added it and you might
    consider grabbing his source. His compiler doesn't support
    termination handlers, though. It coughs at __finally.
    http://www.q-software-solutions.com/lccwin32/

    >BTW TCL 8.3.3 can be compiled with mingw, with a few
    simple
    >patches to the __try blocks, which essentially convert
    them
    >to no-ops. Crashes aren't handled very gracefully, but it
    >will compile and run. I have been intending to submit
    >patches to TCL but have been delayed by the change in host
    >of their site.

    Send bugs/patches to me or https://sourceforge.net/tracker/?
    group_id=10894

    There's a new sticky-point in part of 8.4a2 that _requires_
    the use of SEH to determine if a handle is valid. See
    http://cvs.sourceforge.net/cgi-
    bin/viewcvs.cgi/tcl/tcl/win/tclWinChan.c?rev=1.13&content-
    type=text/vnd.viewcvs-markup
    in Tcl_MakeFileChannel() about 3/4 the way down.

    I'm sure there's a better way to do that test, and I'll
    have to work on a solution to it, if SEH is a no-op. FYI,
    a Win2K OS bug caused that test to be added. Thanks for
    the input :)

     
  • Logged In: YES
    user_id=7549

    If it helps, and you have the free borland compiler, have a
    look in the include directory at excpt.h

    Oh! MSVC++6 has excpt.h as well. Three functions are
    defined:
    unsigned long __cdecl _exception_code(void);
    void * __cdecl _exception_info(void);
    int __cdecl _abnormal_termination(void);

    But the damn M$ guys didn't seem to put them in the c-
    runtime sources. I see exsup.inc and that's the closest I
    can find to what the intrinsics are.

    It appears that three asm files were used: exsup.asm,
    exsup2.asm, and exsup3.asm. The object files are there,
    but the source appears missing.

     
  • closest to the intrinsics I can find

     
    Attachments
  • assembly of the test case

     
    Attachments
  • Logged In: YES
    user_id=7549

    If it is at all helpful, here is the listings output of
    SEHtest.c from:

    cl -c -FAs -MD sehtest.c

    Notice the use of _except_handler3 and _except_list
    functions. Ok, so the helper code is already in the
    runtime... Just use it.

     
  • Logged In: YES
    user_id=7549

    My mistake, _except_list is a variable with an unknown
    location. I can't find it.

    I found these export, though:

    144 8F 0000DACD _abnormal_termination
    206 CD 0000DB11 _except_handler3
    270 10D 0000DA23 _global_unwind2
    326 145 0000DA65 _local_unwind2
    432 1AF 0000DBCE _seh_longjmp_unwind

    Some yummy MASM assembly stuff about the direct method
    which may explain some of this :)
    http://spiff.tripnet.se/~iczelion/Exceptionhandling.html

    Sorry for pouring this on thick.. I'm trying to be helpful.

     
  • Logged In: NO

    MinGW has minimal support for SEH:
    following example Programm demonstrates how to use it:

    #include <windows.h>
    int bad(int &b) ;
    EXCEPTION_DISPOSITION _catch1(struct _EXCEPTION_RECORD*,
    void*, struct _CONTEXT*, void*);
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE
    hPrevInstance,
    PSTR szCmdLine, int iCmdShow)
    {
    try {
    __try1(_catch1)
    int a, b;
    a = bad(b);
    __except1
    } catch(...) {
    MessageBox (0,"Exception arised", "Bye
    Bye", MB_OK);
    return 0;
    };
    return 0;
    }

    int bad(int &b)
    {
    int (*foo)() = NULL;
    foo();
    return b;
    }

    EXCEPTION_DISPOSITION _catch1(struct _EXCEPTION_RECORD*,
    void* err, struct _CONTEXT* , void* par)
    {
    throw 1;
    }

     
  • Logged In: YES
    user_id=7549

    I've found this to be repaired, thank you!

     
    • status: open --> closed-fixed