Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

debug.rst 6.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  1. .. index:: ! debug
  2. ************************
  3. Debugging for Developers
  4. ************************
  5. GMT developers may need to run GMT in a debugger to figure out the problem reported by
  6. an issue. Often there is a bit of detective work involved to find out where a module
  7. crashes and then step carefully through that section, examining variables etc., to learn
  8. why something fails. This process depends on the particular debug tool one uses. This page
  9. will explain the steps a developer must take to build gmt so it is suitable for your debug
  10. tool and how to use that tool.
  11. Xcode on macOS
  12. --------------
  13. Developers on macOS are most likely to want to use Xcode for this purpose. Chances are they
  14. are already using the command-line tools from Xcode (gcc, linker) anyway. To use the GUI
  15. part of Xcode you must have installed the full Xcode (you most likely did, but there are
  16. ways to *only* install the command-line tools, so make sure you have an Xcode icon under
  17. Applications). Xcode may change as versions change; the images below is for Xcode 10-11.
  18. #. You will need to make some changes to your *cmake/ConfigUserAdvanced.cmake* file. Scroll down to the
  19. section that says "# Extra debugging for developers:" and uncomment the ~6 lines that has
  20. the if-test on "Xcode". This will pass a few flags that are used when debugging via Xcode.
  21. Also uncomment the two "add_definitions" lines that contain the word "DEBUG" in it somewhere.
  22. #. You will need to build GMT again. I recommend you do this in a separate build directory (I
  23. call mine *xbuild*, and while at it I use *rbuild* for "Release Builds" and *dbuild* for regular
  24. debug command line builds, and *build* for the final build for the releases). If you are in
  25. the *xbuild* directory, these two commands will do the build::
  26. cmake -DCMAKE_INSTALL_PREFIX=gmt6 -DCMAKE_BUILD_TYPE=Debug -G Xcode ..
  27. xcodebuild
  28. #. After this step you can launch the Xcode application and then use the File->Open menu to
  29. open the project file *xbuild/GMT.xcodeproj*. After it opens it may looks something like
  30. this (click on the figure to enlarge it):
  31. .. figure:: /_images/xcode-1.*
  32. :width: 100%
  33. :align: center
  34. #. Pull down the tab that says "@ ALL_BUILD" and select "gmt" about 35 lines down, then in the
  35. left sidebar open the folder called gmt->Source Files and select gmt.c. Now you may wish
  36. to drag the window to be a bit wider so the lines don't wrap around so much. After that step
  37. your screen may look more like this:
  38. .. figure:: /_images/xcode-2.*
  39. :width: 100%
  40. :align: center
  41. #. Scroll down to the part around line 119 and click the line number to place a stop point; it
  42. will add a blue fat arrow at that line:
  43. .. figure:: /_images/xcode-3.*
  44. :width: 100%
  45. :align: center
  46. This is *usually* the first stop you want in Xcode. The exception would be if you are debugging
  47. gmt.c itself or you need to examine the code that creates the session via a call to GMT_Create_Session
  48. earlier in the program.
  49. #. Now we need to specify the particular command we wish to debug. Let's pretend that :doc:`pstext`
  50. crashes when we run the command::
  51. gmt pstext my_text.txt -R0/30/-10/20 -JM15c -Baf -F+f16p > text.ps
  52. Copy that command minus the initial "gmt " part. Now pull down the menu item "Product->Scheme->Edit Scheme",
  53. then make sure "Arguments" is highlighted in blue in the top table, then click the "+" symbol beneath the
  54. section that says "Arguments Passed on Launch" and paste in our command; it should result in this display:
  55. .. figure:: /_images/xcode-4.*
  56. :width: 100%
  57. :align: center
  58. Normally you do not need to set any "Environmental Variables", but if you are debugging a module that
  59. calls an external program (e.g., gs, gdal_translate, etc.) then you may need to add the name PATH and
  60. place the path to that program under "Value". Likewise, if the module needs to find a particular environmental
  61. setting like $X2SYS_HOME, then you must set those here as well.
  62. #. Any data files your command will read must either be placed in the *xbuild/src/Debug* subdirectory or you must
  63. change the command you pasted above to use the full path instead. In other words, when Xcode runs
  64. your command, your current directory becomes *xbuild/src/Debug*.
  65. #. Click close and hit the "Play" button next to the green circle in the top left corner. It may do some
  66. building and indexing before it starts and then stops at your highlighted line, opening up a display console
  67. below the source code:
  68. .. figure:: /_images/xcode-5.*
  69. :width: 100%
  70. :align: center
  71. You will see the current line is highlighted light greenish and the execution is stopped. Below the code is a new window that
  72. lists some of the variables in the current scope. You can examine that window to see what the variables are set
  73. to, you can type "print variable" in the lldb command window on the right (e.g., "print argc"), or you can place
  74. the cursor over a variable and a pop-up box will display its value. Below I placed the cursor on the variable
  75. "module" on line 119 and this is what it looks like (minus the cursor which is not screen-grabbed!).
  76. .. figure:: /_images/xcode-6.*
  77. :width: 100%
  78. :align: center
  79. #. The tool bar below the source code has a pause-play button (continue to next stop point), a step-over button (execute
  80. next step but do not go *into* a function, the step-into button (execute next step which may be going into a function)
  81. and the step-out button (finish running current function then step back out). Step into the GMT_Call_Module function
  82. using the step-into button, then scroll down to around line 10094 and place another stop point there like I did. Press
  83. the pause-play button and you are now about to call your actual C function that correspond to the module (here pstext):
  84. .. figure:: /_images/xcode-7.*
  85. :width: 100%
  86. :align: center
  87. #. Click the step-into button and find yourself at the first executable line of code in GMT_pstext, the underlying
  88. C function at the heart of the pstext module. You can now step your way down the code, using step-over to avoid going
  89. into the details of GMT sub-functions (or step-into it if that is the problem), set stop points and push pause-play to
  90. advance to the next stop point, examine variables, and so on.
  91. .. figure:: /_images/xcode-8.*
  92. :width: 100%
  93. :align: center
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...