Operating System - Linux
1752364 Members
5858 Online
108787 Solutions
New Discussion юеВ

Segmentation fault (core dumped)

 
Henry Chua
Super Advisor

Segmentation fault (core dumped)

Hi guys,

wat does this error does? I gave been getting this error when every my program ran for awhile. wat is the usual way to rectify it?

Thanks!
9 REPLIES 9
Juan M Leon
Trusted Contributor

Re: Segmentation fault (core dumped)

I will say analyze the core file, also you can use tusc to run your programs. Tusc will help you to see what is happening during the program.
What type of program are you running, java or C
Henry Chua
Super Advisor

Re: Segmentation fault (core dumped)

Hi Juan, thanks for the tips.. i am using C.. but could have caused this sort of error and how do I analyze the core file.. what is core file actually?

Regards
Henry

Vibhor Kumar Agarwal
Esteemed Contributor

Re: Segmentation fault (core dumped)

Core file is the contents of the memory when the program teminated.

You can use any debugger like gdb, adb for that.

It will give you the why the program terminated.
Vibhor Kumar Agarwal
Henry Chua
Super Advisor

Re: Segmentation fault (core dumped)

oh ok.. but I am really new to core file.. what should I do to examine them? Can you give an example? thanks!

regards
Henry
Muthukumar_5
Honored Contributor

Re: Segmentation fault (core dumped)

To examine core files,

1) file core
2) what core
3) gdb core application-bianry
gdb) bt
gdb)q
4) adb core application-binary
adb> c
abd>q

hth.
Easy to suggest when don't know about the problem!
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Segmentation fault (core dumped)

The basic syntax is:

debugger_application core_file exe_which produced_core

For detail have a look at
man gdb
Vibhor Kumar Agarwal
susan gregory_1
Valued Contributor

Re: Segmentation fault (core dumped)

The usual root cause of a segmentation fault is that the program tried to access an unreachable virtual address. It is possible or likely that you had some type of move statement that resulted in corruption of the data stack and when the program later tried to use a virtual address that had been stored in the corrupted area, the value in that location was corrupted and pointed to an invalid "address" thus caused your program to abort.

Re: Segmentation fault (core dumped)

You can use gdb to see why this segmantation fault is happening.

$ gdb core
(gdb) bt

When you load the core file into gdb, it will show exact source line or instruction that got the segfault.

It can be something like
*ptr = 10;

Where ptr is a pointer say like "int *ptr;"
Check what the value of ptr is by printing it.

(gdb) p ptr

and check if it is a valid address. Normally segfault happens when you derefernce an invalid address (like a NULL pointer). In that case, you need to make sure that you are accessing a valid address in your program before dereference it. Checking if a pointer if null before you derefernce it is always a good idea.

if (ptr != NULL)
*ptr = 10;
Michael D. Zorn
Regular Advisor

Re: Segmentation fault (core dumped)

My experience here is that that kind of error almost always happens when there's a mismatched calling and receiving argument list.

If you can, get in the debugger and put a trap at the beginning of every routine. You may have to take out some of the traps if a routine gets called a lot. But try to pin it down to a specific routine.