debugging.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. GRASS Debugging:
  2. At user level:
  3. Print debugging message if variable DEBUG
  4. is set to level equal or greater
  5. g.gisenv set="DEBUG=3"
  6. Levels: (recommended levels)
  7. * 0 - silence
  8. * 1 - message is printed once or few times per module
  9. * 3 - each row (raster) or line (vector)
  10. * 5 - each cell (raster) or point (vector)
  11. Further hints:
  12. > How can I force gcc, to complain about missing header file?
  13. '-Wimplicit-function-declaration'
  14. '-Werror-implicit-function-declaration'
  15. Give a warning (or error) whenever a function is used before being
  16. declared.
  17. ----------------------------------------------------
  18. To make gcc less tolerant in accepting errors and code flaws, compile
  19. with (see also ../INSTALL):
  20. export CFLAGS='-g -ansi -Wall -D_BSD_SOURCE=1 -D_SVID_SOURCE=1 -D_POSIX_SOURCE=1 -D_POSIX_C_SOURCE=199506L'
  21. Also nice to emulate gcc/MacOSX compiler:
  22. CFLAGS='-fno-common'
  23. It is a good idea to use '-Wall -Werror' as gcc options. This means
  24. it treats the warnings as errors, i.e. it stops on them. So you have time
  25. to read them then.
  26. The gcc switch -Wimplicit-function-declaration (implied by -Wall) should
  27. report missing prototypes (use -Werror-implicit-function-declaration to
  28. make it an error rather than a warning).
  29. The linker switch --warn-common (e.g. LDFLAGS='-Wl,--warn-common') might
  30. be useful for catching multiply-defined symbols.
  31. Be sure to compile using debug flags (gcc -g) and don't "strip" the
  32. binaries after compiling.
  33. ----------------------------------------------------
  34. C Code debugging Software:
  35. 1) Debugger (command-line)
  36. gdb `which r.plane`
  37. r <flags> <parameters>
  38. bt full
  39. To debug in a running process, find out the process ID (PID)
  40. ps -aef
  41. and then use
  42. gdb --pid=PID
  43. to attach to running process PID. It will stop, enter 'c'
  44. to continue and so forth (bt full for backtrace).
  45. 2a) Graphical front-end for command-line debugger: ddd
  46. ddd `which r.plane`
  47. RUN -> here enter Parameters/Flags
  48. http://www.gnu.org/software/ddd/
  49. (GNU DDD is a graphical front-end for command-line debuggers such as
  50. GDB, DBX, WDB, Ladebug, JDB, XDB, the Perl debugger, the bash debugger, or the
  51. Python debugger. )
  52. See mini tutorial here:
  53. http://grass.osgeo.org/wiki/GRASS_Debugging
  54. 2b) Graphical front-end for command-line debugger: kdbg
  55. Use the menus
  56. ----------------------------------------------------
  57. Debugging on Mac OS X
  58. The 'ldd' command doesn't exist, but
  59. otool -L
  60. does almost the same job.
  61. ----------------------------------------------------
  62. Using valgrind to find memory leaks (http://valgrind.org/):
  63. * Memory note for vector modules:
  64. Support structures are not released by default because it take long time
  65. and it is much faster if it is done by system.
  66. You have to call Vect_set_release_support() before
  67. Vect_close() if you want to use valgrind.
  68. * Example (see also http://bambi.otago.ac.nz/hamish/grass/memleak/v.in.ascii/):
  69. CMD="v.in.ascii -zt z=3 in=lidaratm2_250k.txt out=lidaratm2_250k fs=,"
  70. valgrind -v --tool=addrcheck --leak-check=yes --show-reachable=yes $CMD --o
  71. * On 64bit boxed valgrind is not supported. An alternative is 'memusage':
  72. memusage -t -T v.in.ogr -o dsn=clcit2000 layer=LAB,ARC \
  73. type=centroid,boundary output=corine2000_it
  74. ----------------------------------------------------
  75. Profiling GRASS with GCC:
  76. Profiling allows the compiler to insert code that collects various
  77. statistics for later analysis. Profiling with GCC is particularly
  78. useful for quickly locating bottleneck functions, determining how
  79. much time is spent in a particular function, and how many times that
  80. function was called.
  81. To profile the entire GRASS package, the following steps should be
  82. followed for success:
  83. * Before running 'configure', both the CFLAGS and LDFLAGS environment
  84. variables need to be altered by adding the -pg flag to enable
  85. profiling. This can be accomplished by the following:
  86. CFLAGS='-pg' LDFLAGS='-pg' ./configure ...
  87. CFLAGS and LINK_FLAGS in include/Make/Platform.make can be manually
  88. edited after running 'configure', also.
  89. * 'configure' must be called with --disable-shared if you intend to
  90. profile GRASS libraries (recommended)
  91. * make GRASS as normal
  92. * In order to run GRASS without errors, lib/init must be recompiled
  93. without linking using the -pg flag. Edit include/Make/Platform.make
  94. and remove -pg from LINK_FLAGS. 'cd lib/init; make clean; make'.
  95. GRASS can now be installed as normal.
  96. When running a GRASS C module, a file called gmon.out is created when
  97. the module completes execution. This file can be analyzed with
  98. the GCC tool 'gprof'.
  99. Note that when 'make distclean' is run, the manual changes to
  100. include/Make/Platform.make are also removed.