- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to use try-catch statements, but it does not seems to work for me. I work with Quartus II 11.0sp1 and nios II (the fpga includes a vic).
When I debug what happens in my throw statement it seems as if I get another exception during the call of "_Unwind_RaiseException" in _cxxabiv1::__cxa_throw in the gnu file eh_throw.cc. My code setup is very simple: static int catched = 0; try { throw 20; } catch (...) { catched++; } Any one have a hint for me?Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some basic c++ exception tests for rtems rt os also fail using 11.0sp1 nios eds. Apprarently gcc uses either setjmp/longjmp or DWARF based mechanisms to unwind the stack, but I haven't yet determined which of these is used for nios2. We are building the nios2 cross compiler configuring for multi-threaded execution but I am starting to suspect that using the current state of the nios2 gcc 4 compiler with threads is sketchy as the Altera built compiler is configured for single-threaded use. We need C++ so we can port community software to the nios2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So it appears that the DWARF mechanism is used after seeing this type of code in gcc/config/nios2/nios2.h
/* Describe __builtin_eh_return */# define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, LAST_RETVAL_REGNO)# define EH_RETURN_DATA_REGNO(N) ((N) <= (LAST_ARG_REGNO - FIRST_ARG_REGNO) ? (N) + FIRST_ARG_REGNO : INVALID_REGNUM)# define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) (!flag_pic ? DW_EH_PE_sdata4 /* FIXME: These get expanded to dynamic relocs, which is wrong */ /* : !(GLOBAL) ? DW_EH_PE_pcrel | DW_EH_PE_sdata4 */ : DW_EH_PE_aligned)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am having a look at this link to understand gcc's exception handling mechanisms, BTW
http://gcc.gnu.org/ml/gcc/2002-07/msg00352.html- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FWIW, I can see that the exception stack unwind fails at the gcc_assert in this function.
static inline void _Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa, _Unwind_SpTmp *tmp_sp) { int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()]; if (size == sizeof(_Unwind_Ptr)) tmp_sp->ptr = (_Unwind_Ptr) cfa; else { gcc_assert (size == sizeof(_Unwind_Word)); tmp_sp->word = (_Unwind_Ptr) cfa; } _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp); }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Starting to understand what isn't working...
(gdb) print dwarf_reg_size_table[0] $6 = 0 '\000' (gdb) call init_dwarf_reg_size_table() (gdb) Quit (gdb) print dwarf_reg_size_table[0] $8 = 4 '\004'- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Success! FWIW, I resolved this issue and now the basic RTEMS C++ exceptions tests pass w/o issues. It turns out that there were no issues so far with the Altera extensions to gcc for nios2, but instead with the RTEMS specific configurations of the nios2 cross gcc. I needed only to add "builtin_define ("__USE_INIT_FINI__");" to "<gcc>/gcc/config/nios2/rtems.h" to make the C++ exception unwinding work correctly.
I should add that the combination of ddd with nios2-elf-gdb works very nicely for debugging rtems startup issues. Initially I was confused about what location in the source was failing because the optimized gcc startup code was integrating/optimizing away inline functions. With ddd I can see both the source window and the machine instruction window simultaneously and then its easy to see what is happening!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BTW, I do see in the debugger that the nios2-rtems-g++ configured gcc run-time support code does administer the proper mutual exclusion locks when a thread throws a c++ exception.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jeffrey,
Great explanations! Though I cannot find the aforementioned gcc/config/nios2/rtems.h file under my Altera Niod EDS folder. I'm currently using the Nios II EDS 11.1sp1. Can you help me find that file, so I can try your solution for the try-catch problem? I didn't want to start changing random files in my gcc folder. I only have the following rtems.h files: c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\rtems.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\arm\rtems-elf.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\avr\rtems.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\c4x\rtems.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\h8300\rtems.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\i386\rtemself.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\m68k\rtemself.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\mips\rtems.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\rs6000\rtems.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\sh\rtems.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\sh\rtemself.h c:\altera\11.1\nios2eds\bin\gnu\src\gcc-4.1\gcc\config\sparc\rtemself.h There is no nios2 under the config folder. Thanks, Tibor- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And the source code for nios2 gcc is of course available here. I have been using gcc 4.1.
http://www.altera.com/support/ip/processors/nios2/ide/ips-nios2-ide-tutorial.html- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jeffry,
Thanks for the code, though I have a question: What am I suppose to do with the new packages? I downloaded the rtems.h file and the nios2 gcc. I unpacked the nios2 gcc package, but there wasn't any manual or help document in it, and I already have a NiosII EDS installed on my computer. Is there any tutorial that I can use to make this package work? I guess I have to make my NiosII EDS use this compiler insted of the one under the original Altera installation. Can you refer my to any document that has a description how to do that? I haven't tried to hack my EDS installation before. Thanks for your help again. Tibor- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is some info on the wiki about building gcc from the Altera tarballs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
gytibor:
I obtained the source code so I could build a nios2 cross compiler which specifically targets RTEMS RT OS. The rtems.h is used by the cross compiler build to configure stack unwinding and other properties of the cross compiler specifically for RTEMS. The link below has some of the details, and you might also search for "building configuring cross gcc" on google. http://www.alterawiki.com/wiki/crossgcc- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jeffrey,
I've just realized that the RTEMS is a RTOS. Unfortunately, I'm tied to the MicroC OS-II, so I cannot just switch to a new RTOS. Thank you very much for your help. I really appreciated it. Tibor
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page