debugging.txt 4.8 KB

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