Go to Post Dean looks rather debonaire in a tux. Like some sort of engineer super hero. The tuxedo is like his Clark Kent costume under which lies his amazing denim suit, to be whipped out at a moments notice in the face of uninspired youth and problems unconquered. - phrontist [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 23-10-2013, 20:44
William Kunkel William Kunkel is offline
Programming Lead
AKA: Kunkel
FRC #0422 (Mech Tech Dragons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Richmond, VA
Posts: 94
William Kunkel is an unknown quantity at this point
VxWorks exception handling and division by zero

I've been wondering how VxWorks on the cRIO reacts to uncaught exceptions in the user program. As I understand it, the user program is loaded as a kernel module, so it seems like an uncaught exception should result in a kernel panic. I wanted to test this out, so I wrote code that I expected to throw a runtime error on a button press. I tried a piece of code that would simply output the result of "1/0" to stderr. The result, however, was that "0" was printed to stderr, and no error or unexpected behavior occurred. The same code snippet,
Code:
std::cerr << 1/0 << std::endl;
in a native program caused a crash. So now I am left with two questions:

How does VxWorks respond to an uncaught exception in a kernel module?

Why is the result of "1/0" "0" in WindRiver C++?
Reply With Quote
  #2   Spotlight this post!  
Unread 27-10-2013, 10:10
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: VxWorks exception handling and division by zero

The reaction to an internal exception in VxWorks is customizable (so NI might have changed it). One can register signal handlers to trap exceptions and implement behaviours other than the default.

Even though the NI tasks and our robot application code are running in kernel space or context, the kernel context supports multiple tasks. The default reaction to an internal exception is to suspend the offending task, store some data in a special area of memory (so it can be examined after a warm reboot) and log a message. It is the exception handler task that implements this behaviour and the log message task that prints the message.

I am not sure about the 1/0 statement. My first guess is that would create an exception. Perhaps C++ traps that somehow or perhaps NI is trapping it somehow. Maybe the C pre-processor resolves 1/0 as a constant and the PowerPC never sees the statement. Try using 1.0/0.0 or using a variable (set to zero) in the denominator - that will probably create the exception more reliably.

HTH
__________________
Fast, cheap or working - pick any two!

Last edited by wireties : 27-10-2013 at 10:13.
Reply With Quote
  #3   Spotlight this post!  
Unread 27-10-2013, 12:54
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: VxWorks exception handling and division by zero

You can also experiment with dereferencing a bad address, double freeing an allocation, etc. It feels odd to write programs that you know will crash, but learning how they present their crash is very helpful later when it is not you, or it is an accident.

Greg McKaskle
Reply With Quote
  #4   Spotlight this post!  
Unread 29-10-2013, 00:51
William Kunkel William Kunkel is offline
Programming Lead
AKA: Kunkel
FRC #0422 (Mech Tech Dragons)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Richmond, VA
Posts: 94
William Kunkel is an unknown quantity at this point
Re: VxWorks exception handling and division by zero

Sorry for not replying for a while, it's been very hectic. 1/0 and 1/any variable set to 0 will both produce the same output. 1.0/0.0 will produce inf. I also tried dereferencing a null pointer, and it had much the same effect (that is, none). I'll try to test raising other exceptions when I get the chance.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:38.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi