Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 9th September 2012, 05:52 PM
Anuradha Offline
Registered User
 
Join Date: Sep 2012
Location: India
Posts: 4
linuxfedorafirefox
segmentation, fault

Its giving the results now.

Last edited by Anuradha; 24th September 2012 at 04:25 PM. Reason: problem solved.
Reply With Quote
  #2  
Old 9th September 2012, 07:16 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,110
linuxfirefox
Re: segmentaion,fault, core dumped, in fedora16

There are lots of possible reasons -
memory failure
library differences
corrupted binary
insufficient memory
bad programming
bad install
...

Knowing what program would help. Knowing what the program does may help. Knowing which version of Fedora (I assume for the moment you are talking about Fedora 16 as there no such Fedora 16000...)
Reply With Quote
  #3  
Old 10th September 2012, 03:02 AM
Dan's Avatar
Dan Offline
Administrator
 
Join Date: Jun 2006
Location: Paris, TX
Posts: 22,309
linuxfirefox
Re: segmentation, fault

One thread per subject per customer at a time.

Threads merged.
__________________
Signature Links | New Posts | Who's on the forums (right now) |

© ® ™ № ¿
Reply With Quote
  #4  
Old 10th September 2012, 10:51 AM
george_toolan Offline
Registered User
 
Join Date: Dec 2006
Posts: 1,718
linuxfirefox
Re: segmentation, fault

Your program doesn't do anything, because you forgot to post item2.dat.
Reply With Quote
  #5  
Old 10th September 2012, 04:31 PM
cmanL Offline
Registered User
 
Join Date: Jul 2012
Location: America
Posts: 76
macossafari
Re: segmentation, fault

Compile the program with gcc using the -g option ( for creating an executable with debugging information ) and run the resulting program using gdb ( the GNU command line debugger ). When the program crashes type "where" at the gdb prompt and the debugger will tell you where the program crashed and allow you to inspect variables in your program to help you find the segmentation fault. So do this:

Code:
gcc -g yourProgram.c

gdb a.out

GNU gdb (GDB) Fedora (7.2-52.fc14)
........
(gdb) run

segmentation fault ........

(gdb) where

myArray [ i ] = myVariable;   <- just for example here

(gdb) print i         <-print the value of the array index here , etc .......
I haven't really looked at your code but I saw arrays ( I didn't see any pointers or dynamic memory ) so I would test to see if you have an array index that is out of bounds ( too big or small compared to your declarations ) first.......
Reply With Quote
  #6  
Old 11th September 2012, 02:43 PM
cmanL Offline
Registered User
 
Join Date: Jul 2012
Location: America
Posts: 76
macossafari
Re: segmentation, fault

On the next (gdb) prompt you should type "where" to see the location of the crash ( from the output you have you can see that the program crashes in the function "strcmp" - from the line "0x009ce118 in strcmp () from /lib/libc.so.6" ). The where command should show you the exact line of code that caused the crash , it looks like you might have passed a bad address to one of the "strcmp" function ( maybe a non-null terminated string , or you passed an address beyond the ending 0 ? ). So I would try this first. Once you find out where the crash occurred you can use other gdb commands like "print" to try to find out what the problem is. For instance:

Code:
Program received signal SIGSEGV, Segmentation fault.
0x009ce118 in strcmp () from /lib/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc.i686
(gdb) where
 
if(strcmp(it.item_ids[i],item_id[j])==0) <- just for example

(gdb) print i
$1 = 839    <- array index is too big , for example

Heres an example of how to do this with a program designed to crash. Take some bad code like this:

Code:
#include <iostream>

using namespace std;
int main()
{
	int j [ 10 ];
	int i = 0;

	while ( i < 2000 )
	{
		j [ i ] = 20;
		cout << i << endl;		
		i ++;
	}
}
compile it with "g++ -g test.cpp" and run the program with gdb:


Code:
gdb a.out

gdb a.out
GNU gdb (GDB) Fedora (7.2-52.fc14)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/couchman/Desktop/programs/a.out...done.
(gdb) run

...... ( I cut some stuff out here )
828
829
830
831
832
833
834
835
836
837
838

Program received signal SIGSEGV, Segmentation fault.
0x080485fb in main () at test.cpp:11
11			j [ i ] = 20;
Missing separate debuginfos, use: debuginfo-install glibc-2.13-2.i686 libgcc-4.5.1-4.fc14.i686 libstdc++-4.5.1-4.fc14.i686
(gdb) where
#0  0x080485fb in main () at test.cpp:11
(gdb) print i
$1 = 839
(gdb)
Here gdb shows me that the program crashes on line 11 in the function main() ( this is the line "j [ i ] = 20;" ). I now can type the print command and this shows me that the value of "i" is much greater than the value 10 that was used to declare the array "j". So now I can rework my code so that the program does not crash. There are also several GUI debuggers that use gdb , like DDD and Eclipse IDE , so you might want to look at these too...........
Reply With Quote
  #7  
Old 11th September 2012, 02:52 PM
george_toolan Offline
Registered User
 
Join Date: Dec 2006
Posts: 1,718
linuxfirefox
Re: segmentation, fault

If you want to use gdb you'll have to install debugging libraries for glibc et al, because the standard Fedora libraries weren't compiled with debugging symbols.

Your program crashes while parsing the input file, probably trying to read past the "end" of the file.

For testing you can just add some debugging output like this:

Code:
cout << i << ": " << it->item_ids[i] << endl;

while(strcmp(it->item_ids[i],"end")!=0)
We still don't know what your input file looks like. In your "example" it is trying to read the whole thing as one item and btw there's a difference between i5 and I5.

Last edited by george_toolan; 11th September 2012 at 02:55 PM.
Reply With Quote
  #8  
Old 11th September 2012, 04:31 PM
Anuradha Offline
Registered User
 
Join Date: Sep 2012
Location: India
Posts: 4
linuxfedorafirefox
Re: segmentation, fault

Thank you very much for your response. when I follow your suggestions, Iam getting the following output.

[anu@localhost ~]$ gcc -g anu.c
[anu@localhost ~]$ gdb a.out
GNU gdb Fedora (6.8-1.fc9)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) where
No stack.
(gdb) run
Starting program: /home/anu/a.out

Program received signal SIGSEGV, Segmentation fault.
0x009ce118 in strcmp () from /lib/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc.i686
(gdb) where
#0 0x009ce118 in strcmp () from /lib/libc.so.6
#1 0x0804880d in func1 () at anu.c:63
#2 0x08048926 in main () at anu.c:119
(gdb) print
The history is empty.

What is this no stack problem. I am having 2GB memory and 9.8GB available disk space.













[
Reply With Quote
  #9  
Old 11th September 2012, 04:47 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,110
linuxfirefox
Re: segmentation, fault

There is no stack because the process hasn't been started. The stack in question hasn't been initialized.

Your error is on line 20 - I suspect it is the line "while(strcmp(it->item_ids[i],"end")!=0)"

You have no detection for the end of file, and if the string "end" is not in the data, then you have created an index out of bounds.
Reply With Quote
  #10  
Old 11th September 2012, 09:40 PM
cmanL Offline
Registered User
 
Join Date: Jul 2012
Location: America
Posts: 76
macossafari
Re: segmentation, fault

Quote:
(gdb) print
You need to name a variable to use the "print" command. Try something like "print i".
Reply With Quote
  #11  
Old 17th September 2012, 11:05 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,110
linuxfirefox
Re: segmentation, fault

Does each item end in the string "end\0"?

If not, then you have a buffer overflow in line "while(strcmp(it->item_ids[i],"end")!=0)"

You don't check that the item has limits, just checking for "end". Not a safe way to do it.

Also note, if item is variable length (and it appears to be "maybe" then fread will read a fixed number of bytes each time - and possibly cause a synchronization problem with the data.

Can't tell without the data source or a sample...

It would also help a lot if you indented your code - makes it much more readable. Put the code in code blocks for posting...
Reply With Quote
  #12  
Old 19th September 2012, 01:25 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,110
linuxfirefox
Re: segmentation, fault

Is this by any chance a homework assignment?

There are several idiosyncrasies that make me think this - one is the recreation of a "do {}while()" construct in the generator. Another it the odd indentation...
Reply With Quote
  #13  
Old 19th September 2012, 07:35 PM
stevea's Avatar
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,304
linuxfirefox
Re: segmentation, fault

Why do you use PROT_EXEC ?

I believe JPollard is correct, For reasons unclear, you are running off The end of the mmap'ed file in memory.
To debug you already have the stack trace, so change context back to func1 and print i, j, and the item data structures.
You can also print the addresses to see where in the file you are.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #14  
Old 23rd September 2012, 12:22 PM
george_toolan Offline
Registered User
 
Join Date: Dec 2006
Posts: 1,718
linuxfirefox
Re: segmentation, fault

It is rather difficult to debug a program since you refuse to give us any information ;-)

I still don't see no item2.dat file and the program you posted is written in something like Turbo C. It doesn't compile with Linux.

So the input file was generated with dos?

If the file doesn't exist you're just getting a simple message and no segmentation fault:
Code:
open: No such file or directory
fread does have some error checking and should never try to read beyond the end of the file.

Code:
RETURN VALUE
       fread()  and  fwrite()  return the number of items successfully read or
       written (i.e., not the number of characters).  If an error  occurs,  or
       the  end-of-file is reached, the return value is a short item count (or
       zero).
While mmap just gives you a pointer. If you try to read beyond the end of the file you should get a segmentation fault, because you're poking around memory locations where you don't belong!
Reply With Quote
  #15  
Old 23rd September 2012, 03:46 PM
hmmsjan Online
Registered User
 
Join Date: Jun 2009
Location: Alkmaar The Netherlands
Posts: 195
linuxubuntufirefox
Re: segmentation, fault

if (k++ <(sb.st_size/sizeof(item))

The < operator is evaluated before incrementing k by postfix operator, thus the loop is executed one time too much.


If you change this to "if(++k<(sb.st_size/sizeof(item))", the code runs as it should run.

Because you are looking into memory out of the valid region, the results are inpredictable and Ubuntu might behave differently.

Good luck
__________________
H.Janssen
Alkmaar
The Netherlands

Last edited by hmmsjan; 23rd September 2012 at 04:42 PM. Reason: First conclusion wrong
Reply With Quote
Reply

Tags
core, dumped, fault, fedora16, segmentaion, segmentation

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault. GodL1ke Using Fedora 7 23rd October 2007 05:04 AM
Segmentation Fault yellowplum Using Fedora 2 12th September 2007 05:35 AM
Segmentation fault! mediator Programming & Packaging 6 29th July 2007 12:55 PM
segmentation fault in rpm shreedhan Installation and Live Media 3 26th March 2007 03:36 PM
Segmentation Fault complete-noobie Using Fedora 1 10th June 2006 09:03 PM


Current GMT-time: 08:33 (Sunday, 26-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat