LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Segmentation Fault

[ILUG] Segmentation Fault

Padraig Brady padraig at antefacto.com
Thu Sep 13 15:00:04 IST 2001


Aidan Kehoe wrote:

> Ar an 13u la de mi 9, scriobh Michael Treacy :
> > 
> > Ok, here's the question: in general, what causes segmentation faults?
> > 
>
>The address space of a program is divided into segments; only some of
>those segments, notably the stack (where local variables are stored) 
>and the heap (where malloc'ed ones (in C) are), are writable. Try to
>write anywhere else (e.g. to a constant string, to the address 0, to
>the address -1) and you have a segmentation fault. So, it means you're
>writing where you're not supposed to. 
>
An interesting gotcha those const strings. I.E. if you declare.
char* string="This can't be modified";
string[0]='t'; /* seg fault */
Note allowing this can be quite useful and is sometimes assumed
(especially by older code) and so some compilers allow it by default.
With gcc you have to explicitly allow it using -fwriteable-strings
Note finding this error can be hard when you cast/pass pointers
to these const string around and so gcc gives another option:
-Wwrite-strings (which isn't included by -Wall) to help you.
anyway getting back on topic...

>
>
> > I've gone through the second fortran program, even added in print commands 
> > to see how far down the program, I was getting, but the first one isn't even 
> > reached.
>
I've never used fortran but I thinkt he following will work:
Use gdb on the core file generated by the segfault. If it just says
segmentation fault and not segmentation fault (core dumped),
then you probably don't have write permissions to the working
directory or ulimit is set too low. To remove ulimits do:
ulimit -c unlimited.


Then on the generated core file do:
gdb -c core my_fortran_executable

Inside gdb type:
bt
which will generate a backtrace and you can see
where the program died.

>
>Does it reach it when you're not trying to read this input file? Have
>you tried reading from another input file? I'd advise trying GDB,
>except it doesn't seem to like fortran, unfortunately;
>
>(gdb.info)
>
>   GDB can be used to debug programs written in Fortran, although it
>does not yet support entering expressions, printing values, or similar
>features using Fortran syntax.  It may be necessary to refer to some
>variables with a trailing underscore.
>
>Chris Higgins' strace suggestion is probably the way to go. If you're
>not on Linux, investigate ktrace (some BSD) and truss (SVR4). 
>
Padraig.






More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell