WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: C++ Exceptions not working?  (Read 5954 times)

Offline indridi

  • Newbie
  • *
  • Posts: 5
C++ Exceptions not working?
« on: February 08, 2016, 02:19:19 PM »
Hi,

Wondering if anyone could help me understand this but it seems that I can't get exceptions in C++ to work properly.
I'm using: Linux box 4.1.13-piCore_v7+ #1 SMP PREEMPT Thu Dec 3 14:16:36 CET 2015 armv7l GNU/Linux

When I compile the following code, using g++ (5.3.0):
Code: [Select]
#include <exception>
#include <iostream>
               
int main(int argc, char **argv)       
{
        try {
                std::cout << "throwing" << std::endl;
                throw std::exception();
        } catch (std::exception& e) {
                std::cout << "catching" << std::endl;
        }
        return 0;
}

I'll get:
Code: [Select]
throwing
terminate called after throwing an instance of 'std::exception'
Aborted

Running in gdb will give me:
Code: [Select]
(gdb) run
Starting program: /mnt/sda1/persistent/build/throw/a.out
throwing
terminate called after throwing an instance of 'std::exception'

Program received signal SIGABRT, Aborted.
0x76cf0950 in raise () from /lib/libc.so.6
(gdb) bt
#0  0x76cf0950 in raise () from /lib/libc.so.6
#1  0x76cf1cc8 in abort () from /lib/libc.so.6
#2  0x76f18644 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#3  0x76f16870 in ?? () from /usr/lib/libstdc++.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

Running the same code on Ubuntu 14.04 will give me:
Code: [Select]
throwing
catching
as expected.

I tried adding the -fexceptions flag and also tried cross-compiling it on Ubuntu 14.04, using gcc (4.8.4) but with the same result.
What I'm I missing here?


Thanks,
Indridi


Offline indridi

  • Newbie
  • *
  • Posts: 5
Re: C++ Exceptions not working?
« Reply #1 on: February 14, 2016, 03:23:30 PM »
Hi,

I found out what the problem is /usr/lib/libstdc++.so.6.0.21 is compiled incorrectly. Downloaded, copiled gcc and replaced the library and exceptions are now working as expected.

Regards,
Indridi

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: C++ Exceptions not working?
« Reply #2 on: February 14, 2016, 10:38:44 PM »
I found out what the problem is /usr/lib/libstdc++.so.6.0.21 is compiled incorrectly. Downloaded, copiled gcc and replaced the library and exceptions are now working as expected.

Let us know what did you change in gcc config and share your build script.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline indridi

  • Newbie
  • *
  • Posts: 5
Re: C++ Exceptions not working?
« Reply #3 on: February 15, 2016, 01:04:45 AM »
Hi,

Downloaded gcc.5.3.0, extracted the files, created a special build directory (as is recommended in the README file).  Used the same arguments as the orginal gcc was using
Code: [Select]
build$ ../gcc-5.3.0/configure --libdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-clocale=gnu
--enable-languages=c,c++,fortran --disable-multilib --disable-libstdcxx-pch --enable-cloog-backend=isl --with-system-zlib --enable-frame-pointer --disable-bootstrap --enable-lto
--with-pkgversion=piCore --with-arch=armv6zk --with-tune=arm1176jzf-s --with-fpu=vfp --with-float=hard --with-gxx-include-dir=/usr/include/c++/5.3.0
Then make and make install. Not sure why this build is different from the original. Could it be because I created a clean build directory?

Regards,
Indridi

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: C++ Exceptions not working?
« Reply #4 on: February 15, 2016, 01:25:46 AM »
Thanks for feedback. At the moment I have no idea....
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

terenyi

  • Guest
Re: C++ Exceptions not working?
« Reply #5 on: May 01, 2016, 11:48:31 PM »
I have the same problem with piCore 7.1 beta3 (4.1.20-piCore+ armv6l).

Is there any progress on that topic?

terenyi

  • Guest
Re: C++ Exceptions not working?
« Reply #6 on: May 02, 2016, 08:22:01 AM »
Please help me to solve this!

I can compile my own gcc but, as I understand, my program will not function properly for others using piCore because of the faulty libstdc++.so.

Thanks in advance!

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: C++ Exceptions not working?
« Reply #7 on: May 02, 2016, 09:26:54 AM »
I have the same problem with piCore 7.1 beta3 (4.1.20-piCore+ armv6l).

Is there any progress on that topic?

Please provide a sample build script to reproduce the issue.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

terenyi

  • Guest
Re: C++ Exceptions not working?
« Reply #8 on: May 02, 2016, 10:14:24 AM »
Hello,

I wrote a shell script:

Code: (bash) [Select]
#!/bin/sh
tce-load -i compile-essentials
tce-load -i binutils
cat > test.cpp <<EOF
#include <iostream>
int main(int argc, char **argv)       
{
        try {
                throw 10;
        } catch (int& e) {
                std::cout << "It works!" << std::endl;
        }
        return 0;
}
EOF
g++ -fexceptions test.cpp && ./a.out

Success would be the output: It works!
Thanks for the support!

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: C++ Exceptions not working?
« Reply #9 on: May 02, 2016, 11:31:59 AM »
@terenyi

Thanks now I can reproduce the issue.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: C++ Exceptions not working?
« Reply #10 on: May 02, 2016, 03:26:53 PM »
Found, it will be fixed in next days.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

terenyi

  • Guest
Re: C++ Exceptions not working?
« Reply #11 on: May 02, 2016, 11:05:39 PM »
Thanks!

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: C++ Exceptions not working?
« Reply #12 on: May 03, 2016, 12:51:22 AM »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

terenyi

  • Guest
Re: C++ Exceptions not working?
« Reply #13 on: May 03, 2016, 04:47:00 AM »
It works. Thank you very much!

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: C++ Exceptions not working?
« Reply #14 on: May 03, 2016, 09:33:37 AM »
Bela, can you describe what was the issue?
The only barriers that can stop you are the ones you create yourself.