wiki:cypress/Programming/CodeDebugging

Version 2 (modified by fuji, 9 years ago) ( diff )

Code Debugging

Ideally, code should be debuged on your desktop computer before being moved to a cluster environment. There are a number of debugging techniques, which you can learn from the internet.

print

Insert 'print' into the source code.

in C/C++

 /* check */
#ifdef DEBUG
  if (info == 0) printf("successfully done\n"); 
#endif

in Fortran

#ifdef debug
    if (info == 0) then
       print *,"successfully done"
    endif
#endif

Compile with -DDEBUG option

icc -g -pg -DDEBUG -c stokeslet2d.c

Makefile

#
# CCS WORKSHOP
# Stokes Flow in a Cavity
#
# Makefile
#
#
TARGET = ex32s ex32m
#
ALL: $(TARGET)
#
CC = icc
 
#CFLAGS = -O3
CFLAGS = -g -pg -DDEBUG
#
#
#
SRC_EX32c = ex32.c stokeslet2d.c gmres.c
#
#
MKL_SQ_LIBS = -L$(MKLROOT)/lib/intel64/ \
        -I$(MKLROOT)/mkl/include \
        -Wl,--start-group \
        $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a \
        $(MKLROOT)/lib/intel64/libmkl_sequential.a \
        $(MKLROOT)/lib/intel64/libmkl_core.a \
        -Wl,--end-group \
        -lpthread
#
MKL_MT_LIBS = -L$(MKLROOT)/lib/intel64/ \
        -I$(MKLROOT)/mkl/include \
        -Wl,--start-group \
        $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a \
        $(MKLROOT)/lib/intel64/libmkl_intel_thread.a \
        $(MKLROOT)/lib/intel64/libmkl_core.a \
        -Wl,--end-group \
        -liomp5 \
        -lpthread
#
#
#
OBJ_EX32c = $(SRC_EX32c:.c=.o)
#
#
ex32s : $(OBJ_EX32c)
        $(CC) $(CFLAGS) -o $@ $(OBJ_EX32c) $(MKL_SQ_LIBS)
 
ex32m : $(OBJ_EX32c)
        $(CC) $(CFLAGS) -o $@ $(OBJ_EX32c) $(MKL_MT_LIBS)
 
#
#
%.o : %.c
        $(CC) $(CFLAGS) -c $<
 
#
clean:  
        rm -f *.o $(TARGET)

GDB

You can use GDB on CCS cluster. GDB

To debug with GDB, submit an interactive job. See here

Compiling with -g option

 icc -g -pg -DDEBUG -c stokeslet2d.c

run gdb

user@host>gdb ./ex32s 
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-56.el6)
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 "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /ccs-autofs/u01/fuji/LabWork/FlowInCavity/ex32s...done.
(gdb) 

show source by command, list line#

(gdb) list 44
39	    printf("Usage:%s [Depth of Cavity]\n",argv[0]);
40	    exit(-1);
41	  }
42	
43	  /* get inputed depth */
44	  dp = atof(argv[1]);
45	
46	  /* # of particles in depth */
47	  numpdepth = (int)(dp / EPSILON + 0.5);
48	  
(gdb)

set breakpoint by command, b line#

(gdb) b 47
Breakpoint 1 at 0x4044c2: file ex32.c, line 47.
(gdb) 

run [command line option]

(gdb) run 5
Starting program: /ccs-autofs/u01/fuji/LabWork/FlowInCavity/ex32s 1
[Thread debugging using libthread_db enabled]

Breakpoint 1, main (argc=2, argv=0x7fffffffd5c8) at ex32.c:47
47	  numpdepth = (int)(dp / EPSILON + 0.5);
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.el6_3.3.x86_64
(gdb) 

print values

(gdb) p dp
$1 = 5
(gdb) p numpdepth
$2 = 0
(gdb) 

continue one step

(gdb) next
50	  numpwidth = (int)(1.0 / EPSILON + 0.5);
(gdb) p numpdepth
$3 = 1000
(gdb) 

exit

(gdb) quit
A debugging session is active.

	Inferior 1 [process 6222] will be killed.

Quit anyway? (y or n) y
Note: See TracWiki for help on using the wiki.