Changes between Version 2 and Version 3 of DebugMode


Ignore:
Timestamp:
Oct 29, 2021, 8:01:59 PM (4 years ago)
Author:
abierjon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DebugMode

    v2 v3  
    6464=== USING GDB FOR DEBUG
    6565
    66 If you have a really vicious bug in your code, you may want to use the gdb tool. Here is some advice to use it, but it is not exhaustive, so please complete this info as it pleases you. You can also find more details in the [https://sourceware.org/gdb/current/onlinedocs/gdb/GNU-Free-Documentation-License.html#GNU-Free-Documentation-License GDB documentation]
     66If you have a really vicious bug in your code, you may want to use the **gdb** tool. Here is some advice to use it, but it is not exhaustive, so please complete this info if you can. You can also find more details in the [https://sourceware.org/gdb/current/onlinedocs/gdb/GNU-Free-Documentation-License.html#GNU-Free-Documentation-License GDB documentation]
    6767
    68 To use gdb, go in your simulation repository (where your have all your .def and start files, and your gcm executable ''gcm_exec.e''), and source your arch.env from your trunk/LMDZ.COMMON to have the required librairies to run the model.
    69 Then, run the command
    70 {{{
    71  gdb gcm_exec.e
    72 }}}
     68To use gdb, you have to compile your model with the {{{-debug}}} option.
     69Once it's done, go in your simulation repository (where your have all your .def and start files, and your gcm executable ''gcm_exec_debug.e''), and source your arch.env from your trunk/LMDZ.COMMON to have the required librairies to run the model.
     70Then, run the command  {{{ gdb gcm_exec_debug.e }}}
    7371
    74 It opens a gdb session. You can now run the model and interact with it while it runs. For instance, you can create ''break points'', which stop the run at a given point. You can then look at some variables via the ''print'' command, then continue the run. Here is an example below :
     72It opens a gdb session. You can now run the model and interact with it while it runs. For instance, you can create ''break points'', which stop the run at a given point. **Be careful** : if you specify a break point at a given line of the code, it has to be the line number from the **compiled** version of the program! (.f or .f90, in LMDZ.COMMON/tmp_src/).
     73
     74You can then look at some variables via the ''print'' command, then continue the run. Here is an example below :
    7575
    7676{{{
    77  (gdb) break aeropacity_mod.f:183
    78  (gdb) run
     77>>> gdb gcm_exec_debug.e
     78
     79 (gdb) break aeropacity_mod.f:183                                                                        ###<--- define a break point before running the program
     80
     81 (gdb) run                                                                                               ###<--- start the program
    7982Starting program:...
    8083.....
    8184.....
    82 Breakpoint 1, aeropacity_mod::aeropacity (ngrid=3010, nlayer=54, nq=11, zday=0.0041666666666666666, pplay=..., pplev=..., ls=3.723693225921032e-05, pq=..., pt=...,
     85Breakpoint 1, aeropacity_mod::aeropacity (ngrid=3010, nlayer=54, nq=11, zday=0.0041666666666666666, pplay=..., pplev=..., ls=3.723693225921032e-05, pq=..., pt=...,           ###<--- reach break point 1
    8386    tauscaling=..., dust_rad_adjust=..., irtoviscoef=..., tau_pref_scenario=..., tau_pref_gcm=..., tau=..., taucloudtes=..., aerosol=..., dsodust=..., reffrad=...,
    8487    qrefvis3d=..., qrefir3d=..., omegarefir3d=..., totstormfract=..., clearatm=4294967295, dsords=..., dsotop=..., alpha_hmons=..., nohmons=4294967295, clearsky=.FALSE.,
     
    8689    at /scratch/cnt0027/lmd1167/abierjon/simurefs_topflows_GCM6/trunk_r2577/LMDZ.COMMON/libo/X64_OCCIGEN_64x48x54_phymars_para.e/.config/ppsrc/phys/aeropacity_mod.f:183
    8790183           tau(1:ngrid,1:naerkind)=0
    88 Missing separate debuginfos, use: debuginfo-install glibc-2.17-324.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 numactl-devel-2.0.12-5.el7.x86_64 zlib-1.2.7-19.el7_9.x86_64
    89 (gdb) break aeropacity_mod.f:266
     91
     92 (gdb) break aeropacity_mod.f:266                                                                        ###<--- define a new break point
    9093Breakpoint 2 at 0x13e792a: file /scratch/cnt0027/lmd1167/abierjon/simurefs_topflows_GCM6/trunk_r2577/LMDZ.COMMON/libo/X64_OCCIGEN_64x48x54_phymars_para.e/.config/ppsrc/phys/aeropacity_mod.f, line 266.
    91 (gdb) continue
     94
     95 (gdb) continue                                                                                          ###<--- resume the program from break point 1
    9296Continuing.
    9397.....
    9498.....
     99Breakpoint 2, aeropacity_mod::aeropacity (ngrid=3010, nlayer=54, nq=11, zday=0.0041666666666666666, pplay=..., pplev=..., ls=3.723693225921032e-05, pq=..., pt=...,           ###<--- reach break point 2
     100    tauscaling=..., dust_rad_adjust=..., irtoviscoef=..., tau_pref_scenario=..., tau_pref_gcm=..., tau=..., taucloudtes=..., aerosol=..., dsodust=..., reffrad=...,
     101    qrefvis3d=..., qrefir3d=..., omegarefir3d=..., totstormfract=..., clearatm=4294967295, dsords=..., dsotop=..., alpha_hmons=..., nohmons=4294967295, clearsky=.FALSE.,
     102    totcloudfrac=...)
     103    at /scratch/cnt0027/lmd1167/abierjon/simurefs_topflows_GCM6/trunk_r2577/LMDZ.COMMON/libo/X64_OCCIGEN_64x48x54_phymars_para.e/.config/ppsrc/phys/aeropacity_mod.f:271
     104271           IF(iaervar.eq.1) THEN
     105
     106 (gdb) print iaervar                                                                                     ###<--- print the value of a local variable of aeropacity at break point 2
     107$1 = 4
     108
     109 (gdb) quit                                                                                              ###<--- quit gdb
    95110}}}
     111
     112Try  {{{(gdb) print MODULENAME::VARNAME}}}  if you want to print a variable (''VARNAME'') from another module (''MODULENAME'') that the subroutine is using. If you want to look at a variable saved in a Fortran ''COMMON'' block (ex: variables from the infamous ''callkeys.h''), doing  {{{(gdb) info common}}}  will print the value of all the variables from the ''COMMON'' blocks.