Compiling with debugger flag -g fixes SEGfault (fortran90) | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Compiling with debugger flag -g fixes SEGfault (fortran90)

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-17-2010
drbones drbones is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 17 December 2010, 8:07 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Compiling with debugger flag -g fixes SEGfault (fortran90)

So the title kinda says it all. I was getting a SEGfault, so I decided to compile with the -g option to find where, and low and behold the SEGfault doesn't occur.

I suppose the answer is "Problem solved! You fixed yet another SEGfault." But I am very curious how this could have happened.

Some info that may help:
1 At first the executable instantly killed itself. After removing some unnecessary variables from the header file, this was fixed. (stack overflow i assume)
2 This is the full compilation command:
ifort -r8 -i4 -mcmodel=large -i-dynamic -align all -g -o code code.f90
3 When compiling without debugger flag messages informing me that loops have been vectorized are printed to screen. Nothing is printed to screen when I compile WITH '-g'.

Thanks!
Sponsored Links
    #2  
Old 12-17-2010
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 31 July 2014, 1:33 PM EDT
Location: Saskatchewan
Posts: 19,023
Thanks: 755
Thanked 3,158 Times in 2,962 Posts
Quote:
Originally Posted by drbones View Post
So the title kinda says it all. I was getting a SEGfault, so I decided to compile with the -g option to find where, and low and behold the SEGfault doesn't occur.

I suppose the answer is "Problem solved! You fixed yet another SEGfault." But I am very curious how this could have happened.
Enabling debugging likely disabled some optimizations, altering the way the code was generated and perhaps the pattern of memory use.

Imagine you're using an uninitialized variable. It may just happen to always be zero when the code isn't optimized since it wasn't used before. But optimize it and it decides it doesn't need a variable at all and puts it in a register! Suddenly you're using an uninitialized register, which could be anything, and it crashes...

Or you're overflowing the end of an array, and the arrangement of memory is different when the executable's optimized. When it's not optimized, you might be corrupting empty space and not care. When it's optimized, you could be munging something important, like pointers to somewhere else, or even your stack frame...

Can you debug it when it's not compiled for debugging? The information you get might be limited, but limited's better than nothing.
Sponsored Links
    #3  
Old 12-17-2010
drbones drbones is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 17 December 2010, 8:07 PM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for quick and useful reply!!

I actually just figured out the issue by rigorously debugging with print* commands.

I was searching for x within a list x1, x2, x3...xn, but did not account for x<x1. D'oh! So despite executing without an issue, the result would have been garbage. I think you hit the nail on the head, I had no idea this could happen!
    #4  
Old 12-17-2010
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 31 July 2014, 1:33 PM EDT
Location: Saskatchewan
Posts: 19,023
Thanks: 755
Thanked 3,158 Times in 2,962 Posts
Yep, that's why it's best to remain wary of segfaults that just "go away". Something'd probably still be wrong somewhere.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
id3lib SEGFAULT errb Programming 2 01-25-2010 03:33 PM
Working around netscape 4.9 segfault on Solaris 8 aussieos Solaris 1 04-18-2009 04:36 PM
how to avoid the segfault from Address 0x1cd00000103 out of bounds cdbug Programming 11 01-19-2009 01:46 AM
[Linux] How Do I Run Until Segfault aslambilal UNIX for Dummies Questions & Answers 1 10-17-2008 08:01 PM
gnu history library signal segfault a1g0rithm Programming 2 03-18-2006 05:23 AM



All times are GMT -4. The time now is 01:34 PM.