VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /usr/share/doc/gnustep-base-doc/Base/General/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/gnustep-base-doc/Base/General/Debugging.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
    <title>Debugging with GDB</title>
  </head>
  <body>
    <font face="serif">
    <a href="Tools.html">Up</a>
    <br />
    <h1><a name="title$Debugging">Debugging with GDB</a></h1>
    <h3>Authors</h3>
    <dl>
      <dt>Adam Fedor</dt>
      <dd>
      </dd>
    </dl>
    <p><b>Copyright:</b> (C) Copyright (C) 2005 Free Software Foundation, Inc.</p>

    
          <h1><a name="001000000000">Debugging</a></h1>
    <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>

          <h2><a name="001001000000">Basic GDB usage</a></h2>
    <p>

      To start the debugger, specify the program you want to debug:
          </p>
<pre>
      gdb myprogram
      </pre>
    <p>

      With GNUstep you can also use the debugtool and debugapp scripts
      to begin a debugging session:
          </p>
<pre>	
      debugapp MyApp.app
      </pre>
    <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>
    <ul>
      <li>
        run <var>args</var> - Run the program
      </li>
      <li>
        break <var>func/method</var> - Stop at a function or method
      </li>
      <li>
        print <var>var/func</var> - Print value of a variable/function
      </li>
      <li>
        backtrace - List the fuction stack
      </li>
      <li>
        frame <var>value</var> - Move up and down the fuction stack
      </li>
      <li>
        help - Get help on gdb commands
      </li>
      <li>
        quit - Quit the program
      </li>
    </ul>

          <h2><a name="001002000000">The <em>run</em> command</a></h2>
    <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>
<pre>
      run -NSOpen=afile.txt
      </pre>

          <h2><a name="001003000000">The <em>break</em> command</a></h2>
    <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>
<pre>
      break afile.m:345
      </pre>
    <p>

      will stop the debugger at line 345 in the file <code>afile.m</code>.
          </p>
<pre>
      break a_function
      </pre>
    <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>
<pre>
      -[Class methodName]
      </pre>
    <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>
<pre>
      break -[Fruit create]
      </pre>
    <p>

      One can also specify just a method name:
          </p>
<pre>
      break initWithValue:
      </pre>
    <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>

          <h2><a name="001004000000">The <em>print</em> command</a></h2>
    <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>
<pre>
      print aVariable
      print anIvar
      print self-&gt;anIvar
      print anArray[4]
      print aStruct.subvalue
      print *(int *)pointerValue
      </pre>
    <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>
<pre>
      print aVariable = 4
      </pre>
    <p>

      One can also print the value of a function. Here gdb will actually
      call the function you specify and return the output:
          </p>
<pre>
      print my_function(4, &quot;hithere&quot;)
      </pre>
    <p>

      When debugging Objective-C programs, the same thing can be done
      with methods.
          </p>
<pre>
      print -[object hash]
      </pre>
    <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>
<pre>
      po anObject
      </pre>
    <p>

      Which is the same as typing
          </p>
<pre>
      print -[myObject desciption]
      </pre>

          <h2><a name="001005000000">Other command</a></h2>
    <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>
    <br />
    <a href="Tools.html">Up</a>
    </font>
</body>
</html>

VaKeR 2022