I have been working on Fortran95 on a Linux operating system. I have made a compiled a code which was done without any error. When I tried to use the compiled file, the result error is reported as,
segmentation fault (core dumped)
As a recovery measure, I have changed the memory allocation to 65535, even then the code reported the same error. What can be done to run the file smoothly?
Any help will be appreciated.
The most frequent reason behind a 'segmentation fault' is an illegal array subscript (like when you want to get A(11) when A is a 1D array of size 10). You may want to add the compiler option
-fcheck=bounds
to have a more detailed description of your error.
Related
I'm using GTest for unittesting my project.
One of the functions I want to test terminates with a Segmentation Fault, which is is not the correct behavior of this function.
I want gtest to report this error, like every other error, but it doesnt. It doesnt run other test cases and it doenst print a report at the end.
It there a way to get a correct report from gtest for this kind of behavior?
You didn't link any code example, so the best answer I can give you is very general.
Your problem is either:
Your function is incorrect and is segmentation faulting (edge cases or main body)
You wrote your test badly, and it (the test itself) is segmentation faulting
Seg Faulting happens when your program/test tries to do something it isn't allowed to do (i.e.. you try to dereference a null ptr, access memory that isn't yours, etc..). Google Test is not able to handle the signal SIGSEGV (nobody is), so your program will crash. Seg Faults are the operating systems way of telling you that you did something illegal and they instantly terminate your program. You need to fix the segmentation fault in order to get results. I would recommend doing the following things:
Learn how to use GDB, and run your program in GDB to figure out where it is segmentation faulting
Use print statements to figure out where your program is segmentation faulting.
I thought segmentation fault only causes crashes. But when I run my c++ program (on windows with mingw compiler) it hangs. But when I run it in gdb it says segmentation fault.
That should be much easier to solve than the reverse: If it seg faulted without the debugger but hangs with the debugger, that can be tricky to debug. Anything that seg faults with a debugger gives you a very easy way (get a backtrace after it seg faults) to get the direct cause of the seg fault, which usually (but not always) directly indicates the bug.
For your title question, you will likely discover the specific situation after you discover the cause of your seg fault. But in theory, it is possible but unlikely: In some environments some segfaults can be caught by try/catch and your code could be structured so catching such a fault puts the program in an infinite loop. More likely the same bug that causes a seg fault in the debugger causes a hang outside the debugger. Likely the debugger loads the program, its stack and/or its command line arguments at slightly different virtual addresses. Some random memory clobber might trigger a hang for one load location and seg fault for another. Alternately, some debuggers intentionally modify uninitialized memory, so that use of an uninitialized pointer is much more likely to seg fault, when it might cause other behavior (including hanging) without that interference by the debugger.
I ran a depth first search program in C++ for a very large graph. The dfs is written in a recursive way. I got segmentation fault 11 on my laptop, but can't find any bugs. I then ran it on a linux server, it runs fine.
I am curious what the difference is. I suspected the stack size because the program is recursive, but as I checked with: ulimit -a, both computers have stack size of 8192 kB. I can't find other limits that might cause this problem. Do you know why I got the difference? Thank you!
A "segmentation fault" is just one of possible outcomes of what's formally defined as "undefined behavior".
The existence of a segmentation fault can be generally concluded to be conclusive evidence that, in some manner, the application engages in "undefined behavior".
And the reason that it is called "undefined behavior" is exactly that: the behavior of the application is not defined. The actual behavior may depend on the processor, architecture, the time of day, the phase of the moon, or who won the World Series. Sometimes the application will crash with a segmentation fault. Other times it might run to the end, apparently producing the expected results, or perhaps results that are subtly wrong, in an undetectable behavior. You can't expect any particular behavior from the program, because it is undefined.
And this is what "undefined behavior" means. A better known synonym for "undefined behavior" is a "bug".
I have some code, that I'm currently porting from OS X to Linux (console tool).
Somewhere in this code, I get a segmentation fault. The problem is, that if I run the program without GDB, I clearly see the segmentation fault, and the program is killed. But when I'm running GDB it just halts, and GDB never returns to the prompt. So I'm not really able to examine what's going on.
C++ is the code. Compiled with the -g option in g++.
Btw. Pretty new to GDB, so excuse me if this is obvious.
Any ideas?
Thanks in advance.
Trenskow
gdb will suspend your program when the seg fault signal is received
type where to see the stack trace and start inspecting what's going on from there.
Also consider enabling core dumps, that way you can load the core dump in GDB and investigate what is going on
you can then load the core dump like this
> gdb your_program the_core_dump
The behaviour you describe is not typical - I suspect the stack may have been trashed.
Try sending various signals directly via the 'kill' command.
Might be worth you running a test program in gdb with an abort() in it so that you can learn what the expected behaviour is for gdb.
I've seen this before when my stack was too large. Try moving stack variables onto the heap (make them globals), recompile, and see if you still get the error.
I got this error message from the C++ compiler:
CC: Fatal error in ccfe: Segmentation Fault (core dumped)
What could cause it?
My user stack limit was very low (1MB). Since the compiler is heavily recursive, this limit as not enough. In solaris, the command for diplaying and changing this limit is ulimt. Other memory limits (virtual, heap) could cause this too.
http://forums.sun.com/thread.jspa?threadID=5389815&tstart=0
I think this answer is not likely to be a long-term useful resource. Now that the original user has had their issue addressed, perhaps this question should retired. (deleted?)
Otherwise someone should extract information from the forum posting and summarize it here in a way that's generally useful to people.