Wrestling with exceptions on win32 gcj 4.1

Ranjit Mathew rmathew@gmail.com
Thu Apr 6 14:45:00 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

tHE DPR wrote:
> my modified hellow world crashes because of segfault:
> 
> public class Test
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Hello, GCJ!");
>         try
>         {
>             new StringBuffer().append("123".toCharArray(), 1, 5);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         System.loadLibrary("any-lib");
>     }
> }
[...]
> i traced the problem down to the method
> _Jv_StackTrace::UnwindTraceFn (btw, why it is not shown in backtrace?)

The problem is that _Unwind_Backtrace() should not be called
for non-DWARF-2 EH (i.e. SJLJ) targets:

  http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00472.html

You need something like the attached patch to prevent this
situation. See if it resolves your segfault.

Note that you *still* won't get proper method names in
stack traces - see the _Jv_StackTrace::GetStackTraceElements()
method in "libjava/stacktrace.cc", which just prints the
instruction pointers (IPs) in hex for SJLJ targets.

The best option is to use DWARF-2 EH for Windows.
(Though this does not work if you're trying to throw an
exception across code that is not using DWARF-2 EH.
For example, in a Windows GUI callback function, you
cannot throw an exception and then hope to catch it
in your event loop.)

HTH,
Ranjit.

- --
Ranjit Mathew      Email: rmathew AT gmail DOT com

Bangalore, INDIA.    Web: http://rmathew.com/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFENSlNYb1hx2wRS48RAuchAJ9r9PPQxWjjep9H/5O9pA4lfMkTJQCcDF2C
aBY0t1iawcjddEepHRvE3Io=
=0Srw
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sjlj.txt
URL: <http://gcc.gnu.org/pipermail/java/attachments/20060406/166b5ba6/attachment.txt>


More information about the Java mailing list