bin/62559: FreeBSD's exception (try/catch) handling is somewhat odd

Nakata Maho maho at FreeBSD.org
Sun Feb 8 19:30:22 PST 2004


The following reply was made to PR bin/62559; it has been noted by GNATS.

From: Nakata Maho <maho at FreeBSD.org>
To: freebsd-gnats-submit at FreeBSD.org, maho at FreeBSD.org
Cc:  
Subject: Re: bin/62559: FreeBSD's exception (try/catch) handling is somewhat
 odd
Date: Mon, 09 Feb 2004 12:28:35 +0900

 Sorry, description inappropreate. so I send follow-up
 
 We are porting OpenOffice.org to FreeBSD, and encounter the problem.
 FreeBSD's g++'s handling of exception throwing
 seems to be somewhat odd, so coredump can happen everywhere
 when throwing the exception, and OpenOffice.org for FreeBSD will be
 unbuildable/unstable.
 
 Michael Rauch <mrauch at netbsd.org> wote very simple test program.
 http://porting.openoffice.org/servlets/ReadMsg?list=dev&msgNo=11408
 
 a) untar gcc_eh_test.tar.gz
 b) make clean ; make
 
 For FreeBSD 5.2-RELEASE i386,
 % make clean ; make
 rm -f main libtest1.so libtest2.so core *.core *.o main.out
 g++ -Wall -shared -o libtest1.so libtest1.cpp
 g++ -Wall -shared -o libtest2.so libtest2.cpp
 g++ -Wall -export-dynamic -o main main.cpp
 ./main > main.out
 Abort trap (core dumped)
 *** Error code 134
 
 % cat main.out
 Testing exception handling ...
 calling lib2func successful!
 % gdb main main.core
 GNU gdb 5.2.1 (FreeBSD)
 Copyright 2002 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and you are
 welcome to change it and/or distribute copies of it under certain 
 conditions.
 Type "show copying" to see the conditions.
 There is absolutely no warranty for GDB.  Type "show warranty" for details.
 This GDB was configured as "i386-unknown-freebsd"...(no debugging 
 symbols found)...
 Core was generated by `main'.
 Program terminated with signal 6, Aborted.
 Reading symbols from /usr/lib/libstdc++.so.4...(no debugging symbols 
 found)...done.
 Loaded symbols for /usr/lib/libstdc++.so.4
 Reading symbols from /lib/libm.so.2...(no debugging symbols found)...done.
 Loaded symbols for /lib/libm.so.2
 Reading symbols from /lib/libc.so.5...(no debugging symbols found)...done.
 Loaded symbols for /lib/libc.so.5
 Reading symbols from ./libtest1.so...(no debugging symbols found)...done.
 Loaded symbols for ./libtest1.so
 Reading symbols from ./libtest2.so...(no debugging symbols found)...done.
 Loaded symbols for ./libtest2.so
 Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols 
 found)...done.
 Loaded symbols for /libexec/ld-elf.so.1
 #0  0x28193d4f in kill () from /lib/libc.so.5
 (gdb) bt
 #0  0x28193d4f in kill () from /lib/libc.so.5
 #1  0x281887f8 in raise () from /lib/libc.so.5
 #2  0x28200f02 in abort () from /lib/libc.so.5
 #3  0x28102007 in __cxxabiv1::__terminate(void (*)()) () from 
 /usr/lib/libstdc++.so.4
 #4  0x28102044 in std::terminate() () from /usr/lib/libstdc++.so.4
 #5  0x28101f86 in __cxa_throw () from /usr/lib/libstdc++.so.4
 #6  0x28226ab9 in lib2func() () from ./libtest2.so
 #7  0x28224a4e in lib1func(void*) () from ./libtest1.so
 #8  0x08048aa7 in main ()
 #9  0x08048862 in _start ()
 (gdb)
 
 apparently exception are thrown correctly (at #6)
 but not catched correctly (at #5).
 
 % cat libtest2.cpp
 #include <iostream>
 #include "libtest.h"
 
 using namespace std;
 
 void lib2func() throw(EHclass) {
   cout << "calling lib2func successful!" << endl;
   throw(EHclass(42));                         <---here
 
 }
 
 you see that exception is thrown perfectly, and catcher
 
 % cat libtest1.cpp
 #include <iostream>
 #include "libtest.h"
 
 using namespace std;
 
 typedef void libfunc();
 
 void lib1func(void * lib2func) {
 
   libfunc *libfunc2;
 
   try{
 
     libfunc2 = (libfunc*) lib2func;
     libfunc2();
 
   } catch(EHclass e) {
     cout << "Exception caught: " << e.i << endl;   <---here
   }
 
 }
 doesn't work.
 expected result is:
 % cat main.exp
 Testing exception handling ...
 calling lib2func successful!
 Exception caught: 42
 ---------------------------------------------------------------
 
 you can fetch test program at:
 http://www.fs.tum.de/~mrauch/OpenOffice/gcc_eh_test.tar.gz
 in BSD style license, but for infomative reason, I pasted
 in this PR.
 
  >Fix:
 
         Sorry. N/A.
         I desperately need Guru's help.
 
 


More information about the freebsd-bugs mailing list