[CLN-list] Overriding read_number_bad_syntax on OS X

Richard B. Kreckel kreckel at ginac.de
Mon May 21 23:11:54 CEST 2007


Hi Bruno,

Bruno Haible wrote:
> You're right, "not reached"/"internal error"/"assertion" are a different
> type of situation: here the culprit is inside CLN.
> 
> How to signal this situation?
>   - through abort()?
>   - through throw internal_error(...)?
> I don't like abort() in the context of CLN, since it would create huge
> coredumps (1 GB is not rare), and eating that much of a user's disk is
> simply not nice.
> Therefore I'm in favour of an exception class that can be used for
> "not reached"/"internal error"/"assertion".


The Linux distributions I work with set the soft limit for maximum size 
of core files created to zero, i.e. no core files are created unless the 
user explicitly specifies another ulimit. So, if a user produces cores 
it is because he wanted so. So why bother?


> Also, there is the documented use of cl_abort in the manual, section
> "Debugging support". How can we keep this functionality, i.e. have a way to
> put a breakpoint in a single place, so that the program execution stops
> there after any CLN exception is constructed but before it is thrown?
> Does "break __cxa_throw" work? If not, it can be done by defining an
> empty function cl_exception_breakpoint(){} and calling this function at the
> end of the constructor of every concrete CLN exception class.


Right, the backtrace is very important in order to track down problems 
and putting a breakpoint in the catch clause is too late, because by 
then the stack has been rewound. I'm no gdb expert, but this appears to 
be working:

rbk at wallace:~$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v 
--enable-languages=c,c++,fortran,objc,obj-c++,ada,treelang --prefix=/usr 
--enable-shared --with-system-zlib --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --enable-nls 
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686 
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20060715 (prerelease) (Debian 4.1.1-9)
rbk at wallace:~$ gdb -v
GNU gdb 6.4.90-debian
Copyright (C) 2006 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 "i486-linux-gnu".
rbk at wallace:~$ cat foo.cc
#include <iostream>
using namespace std;

void f()
{
     throw 42;
}

int main()
{
     try {
         f();
     } catch(const int& n) {
         cerr << n << endl;
     }
     return 0;
}
rbk at wallace:~$ g++ -g foo.cc
rbk at wallace:~$ gdb ./a.out
GNU gdb 6.4.90-debian
Copyright (C) 2006 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 "i486-linux-gnu"...Using host libthread_db 
library "/lib/tls/libthread_db.so.1".

(gdb) l
3
4       void f()
5       {
6           throw 42;
7       }
8
9       int main()
10      {
11          try {
12              f();
(gdb) b 12
Breakpoint 1 at 0x804887c: file foo.cc, line 12.
(gdb) run
Starting program: /home/rbk/a.out
Failed to read a valid object file image from memory.

Breakpoint 1, main () at foo.cc:12
12              f();
(gdb) catch throw
Catchpoint 2 (throw)
(gdb) cont
Continuing.

Catchpoint 2 (exception thrown)
0xb7f7e4d5 in __cxa_throw () from /usr/lib/libstdc++.so.6
(gdb) bt
#0  0xb7f7e4d5 in __cxa_throw () from /usr/lib/libstdc++.so.6
#1  0x0804886a in f () at foo.cc:6
#2  0x08048881 in main () at foo.cc:12
(gdb)

Cheers
   -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>


More information about the CLN-list mailing list