Wednesday 25 March 2015

segmentation fault

After refining the mesh for p3, the program ends up with segmetation fault.
after debugging using idb, it is found it crashes at a line that writes result into file. apparently it is not casued by this line simply. the problem can be reproduced by using gfortran.
I was suggested by changing the stack size by

   ulimit -s 4000000

the way to get around is to compile the source code by windows. at least the program is now working.


case 2

the second time i see segmentation fault is that one of the files are not properly transfered from source to sub functions.


say: call aaa(a,b,c)

in aaa :
aaa(a,b)
c=12

this may cause segmentation fault

gdb (gefortran --debug) debug

  Intel fortran on linux is no longer free, which is annoying as a fortran user. I dicided to change to gfortran instead.
  to creat a executable file that can debug, one can use  '-g' flag
TBH, at the very beginning, it is quite annoying to use command interface to do the debugging, but

gfortran -g a.F90 -o ab

1.  use gdb (15-06-29) 
if gdb does not diplay the line properly, use -ggdb flag instead.
it is also found that the files has to be compiled by the same compiler in the same machine to ensure the readability of the code.
gfortran -ggdb a.f -o a.out

then use the following command to start debug processes.

gdb ab

other useful command:

break main

run  [r]

step [s]  (step into the subroutine)

print a [p a]

where

quit

next (n) go to the next line without step into subfunctions just over the current
n 5   go to the next for 5 times
2.  Info command
info b   see all the breaking points info breakpoints check all of the breakpoints
info line  shows where current script is stoped at



delete 1 delete break point 1 from list info b
disable 1 
enable  1

disable disable all break points

break sutra.f:333    %stop at line 333 of file sutra.f

frame   display current line

finish  stepout



https://www.google.com.au/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&ved=0CDcQFjAE&url=http%3A%2F%2Fdarkdust.net%2Ffiles%2FGDB%2520Cheat%2520Sheet.pdf&ei=HH4zVZnBO4PsmAXPz4HoCQ&usg=AFQjCNHCDpbVUfxmJyacITfnesZ0PKBKqg&sig2=ImgMp83YjaeYNoztPgTw-w&bvm=bv.91071109,d.dGY&cad=rja

http://stackoverflow.com/questions/501486/getting-gdb-to-save-a-list-of-breakpoints
save breakpoints a.txt

how to load break points --
source a.txt


Error: Dummy argument 'cherin' of procedure 'readif' at (1) has an attribute that requires an explicit interface for this procedure


set breakpoint pending on


No symbol table is loaded.  Use the "file" command.


2.  Correct the program. (15-06-29)
TIPS:
  (1) if something is wrong in the source code. one does not need to quit gdb. instead, just correct the file, make it with debug flag, and rerun simulation in gdb using r.

  1. Start the program being debugged.Example 1. The program is printch, which can take an optional command line argument. Start it running with no command line argument.
    (gdb) r
    
    Example 2. Start printch running with command line argument A.
    (gdb) r A
    
  2. Execute a single statement. If the statement is a function call, just single step into the function.
    (gdb) s
    
  3. Execute a single statement. If the statement is a function call, execute the entire function and return to the statement just after the call; that is, step over the function.
    (gdb) n
    
  4. Execute from the current point up to the next breakpoint if there is one, otherwise execute until the program terminates.
    (gdb) c
    
  5. Execute the rest of the current function; that is, step out of the function.
    (gdb) finish