Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-16-2006, 02:07 AM   #1
LQ Newbie
Registered: Aug 2006
Location: Tehran-Iran
Posts: 1

Rep: Reputation: 0
Problem with Segmentation Fault in Linux

Dear Sir/Madam,

Iím developing a source code in C++ for RTU (Remote Terminal Unit). It will gather data of IO modules of RTU and then transmit them to SCADA center with standard communication protocol (IEC-870-5-101). In first step, I developed it in windows in visual C++ environment. For testing its functionality, I arranged test vectors instead of IO cards of RTU in windows. I trigger test vector via timers in windows. Actually, it is running well without exception. I used try catch in any thread in my program. For example I arranged it in DI thread as follows:

// Digital Input process thread
bFunctionCode = (DITHREAD_EVENTS_ENUM_) Msg.GetFunCode();
case DITH_EVENT_SHOUTDOWN_: // ShutDown message to Kill thread
Loop = FALSE_S;

case DITH_EVENT_HWMCHKMSG_: // Hardware Manager Health Check message to DI Thread
case DITH_EVENT_PCIFREEZE_: // PCI Freeze message

default :
m_pApp->GetGate()->ErrorMsg("DITH, Unknown FunCode received to DI thread!");
catch(CScadaException* e){
delete e;
m_pApp->GetGate()->ErrorMsg("Unknown exception occurred in DI_ProcessLoop!");

Now, Iím porting it to Linux to run in embedded system (RTU). It is going well so far but I am hitting a segmentation-fault and each time error occurs, my application will shut off and Aborted (Segmentation Fault) is appear on the terminal. It seems, in Windows catch(...) is a fail safe that catches everything, but in Linux catch(...) doesn't seem to catch anything.

My question is how to control this thing? Letís say after error occurs, just prompt the error message and never do that action so that the app will be ok and still running.

Best Regards
Old 08-16-2006, 08:01 PM   #2
Senior Member
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
A seg fault is typically caused by accessing an area of memory that has not been assigned to the program. So it is not a case of avoiding the problem but locating it and modifying the code.

To help you solve teh problem look at something like gdb a debugger that will be able to tell you where the error is occuring.
Old 08-16-2006, 11:42 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
C++ exceptions vs Microsoft SEH...

Hi, akzare -

I understand your frustration. The problem is that Microsoft has an OS-level feature called "Structured Exception Handling" (SEH) that their VC++ compiler (or, more precisely, their MSVC runtime) uses to implement C++ try/catch blocks.

The result is non-portable code. ANSI C++ try/catch blocks are NOT intended to catch OS-level events like segmentation faults or floating point exceptions. But, let's face it - Microsoft's Visual Studio, SEH-based implementation is really convenient (to say nothing of a lot more efficient)!

Probably the best approach in your case is to use "signal()" to trap OS-level events (SIGSEGV, SIGFPE, etc) that might occur. Perhaps you want to "#ifdef" these calls, so they're only compiled in the non-Windows versions of the code.

Although I wasn't able to find any good links that directly talk about "pure ANSI C++ vs. Microsoft SEH", these should give you the flavor of the problem:

'Hope that helps .. PSM

Last edited by paulsm4; 08-16-2006 at 11:45 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault -- permission problem? dx0r515t Slackware 13 08-24-2006 02:55 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
problem with segmentation fault lucs Slackware 2 04-28-2005 09:14 AM
Segmentation Fault Problem luvonmik Linux - Newbie 2 02-14-2004 07:44 PM
Segmentation fault on RedHat Linux 8.0 hemanth_13 Linux - General 2 07-28-2003 05:52 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:08 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration