File: Debugging.gsdoc

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (190 lines) | stat: -rw-r--r-- 6,497 bytes parent folder | download | duplicates (9)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?xml version="1.0"?>
<!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 1.0.3//EN" "http://www.gnustep.org/gsdoc-1_0_3.dtd">
<!--
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
-->
<gsdoc base="Debugging" up="Tools">
  <head>
    <title>Debugging with GDB</title>
    <author name="Adam Fedor"></author>
    <copy>Copyright (C) 2005 Free Software Foundation, Inc.</copy>
  </head>
  <body>
    <chapter>
      <heading>Debugging</heading>
      <p>
      GDB is the GNU debugger and is the main method used for debugging
      Objective-C programs. Full support for debugging Objective-C with
      GDB was added in version 6.0.  This document will describe the
      various features of GDB that help with debugging Objective-C programs.
      However, GDB is a very complex program, and not everything that it
      can do will be described here.
      </p>
      <section>
      <heading>Basic GDB usage</heading>
      <p>
      To start the debugger, specify the program you want to debug:
      </p>
      <example>
      gdb myprogram
      </example>
      <p>
      With GNUstep you can also use the debugtool and debugapp scripts
      to begin a debugging session:
      </p>
      <example>	
      debugapp MyApp.app
      </example>
      <p>
      Following is a short list of important commands that gdb accepts.
      After this list, a more detailed explaination of each command is
      given.
      </p>
      <list>
        <item>run <var>args</var> - Run the program</item>
        <item>break <var>func/method</var> - Stop at a function or method</item>
        <item>print <var>var/func</var> - Print value of a variable/function</item>
        <item>backtrace - List the fuction stack</item>
        <item>frame <var>value</var> - Move up and down the fuction stack</item>
        <item>help - Get help on gdb commands</item>
        <item>quit - Quit the program</item>
      </list>
      </section>

      <section>
      <heading>The <em>run</em> command</heading>
      <p>
      This command starts the program inside the debugger. You can optionally
      add arguments to the run command and these arguments will get passed
      directly to the program as normal command-line arguments. For instance,
      you might want to start an application and open a file:
      </p>
      <example>
      run -NSOpen=afile.txt
      </example>
      </section>

      <section>
      <heading>The <em>break</em> command</heading>
      <p>
      This command instructs the debugger to stop when it reaches a
      certain location in the program. The syntax for break can be very 
      complex. However we will only cover some simple examples. One instance
      is to break on a particular line number.
      </p>
      <example>
      break afile.m:345
      </example>
      <p>
      will stop the debugger at line 345 in the file <file>afile.m</file>.
      </p>
      <example>
      break a_function
      </example>
      <p>
      will tell the debugger to stop at the beggining of the
      <code>a_function</code> function. Finally, and most importantly
      for Objective-C programs, you can enter a fully-qualified or
      partially-qualified method name to stop at.
      A fully qualified Objective-C method name is specified as
      </p>
      <example>
      -[Class methodName]
      </example>
      <p>
      where the minus sign is used to indicate an instance method and
      a plus sign (not shown) is used to indicate a class method. The
      class name <var>Class</var> and method name <var>methodName</var> are
      enclosed in brackets, similar to the way messages are specified
      in Objective-C source code. For example, to set a breakpoint at
      the <code>create</code> instance method of class <code>Fruit</code> 
      in the program currently being debugged, enter:
      </p>
      <example>
      break -[Fruit create]
      </example>
      <p>
      One can also specify just a method name:
      </p>
      <example>
      break initWithValue:
      </example>
      <p>
      gdb will automatically determine what class this method belongs to. If
      there is more than one class that implements this method, you will
      be presented with a list of classes that implement the method from which
      you must chose one.
      </p>
      </section>

      <section>
      <heading>The <em>print</em> command</heading>
      <p>
      The print command can be used to display a wide variety of information
      that gdb knows about the program. As with the <var>break</var> command,
      the variety of things you can do is very large, but we will discuss only
      a few of the things that can be done. Below are several simple examples
      of printing the value of a variable.
      </p>
      <example>
      print aVariable
      print anIvar
      print self->anIvar
      print anArray[4]
      print aStruct.subvalue
      print *(int *)pointerValue
      </example>
      <p>
      Note that you can specify variables in the same way you specify them
      in source code, using array subscripts, pointer dereferences, etc.
      You can also set the value of a variable using print:
      </p>
      <example>
      print aVariable = 4
      </example>
      <p>
      One can also print the value of a function. Here gdb will actually
      call the function you specify and return the output:
      </p>
      <example>
      print my_function(4, "hithere")
      </example>
      <p>
      When debugging Objective-C programs, the same thing can be done
      with methods.
      </p>
      <example>
      print -[object hash]
      </example>
      <p>
      A special command has been added to gdb to print the 
      <var>description</var> of an object (based on the method of the
      same name). This is the <var>print-object</var> (or <var>po</var>)
      command:
      </p>
      <example>
      po anObject
      </example>
      <p>
      Which is the same as typing
      </p>
      <example>
      print -[myObject desciption]
      </example>
      </section>

      <section>
      <heading>Other command</heading>
      <p>
      The <var>clear</var>, <var>info line</var>, <var>jump</var>, 
      and <var>list</var> commands also accept Objective-C method
      syntax for specifying locations.
      </p>
      </section>

    </chapter>
  </body>
</gsdoc>