home *** CD-ROM | disk | FTP | other *** search
/ Peanuts NeXT Software Archives / Peanuts-Update.iso / Mirrors / GNUStep / contrib / gdb-objc.README / text0000.txt < prev   
Encoding:
Text File  |  1997-11-11  |  5.2 KB  |  130 lines

  1.  
  2. Since I realized that most people cannot receive the gnu.gdb.bug newsgroup, I  
  3. thought I would go ahead and post this here too.  This only applies to  
  4. Objective C programs compiled with GCC and debugged with GDB.
  5.  
  6. The following patch (sent separately as a uuencoded diff file) should be able  
  7. to be applied to any gdb source version 4.16 or later.  I have tested these  
  8. changes on HPUX, Solaris and MS Windows, and I hope they will be portable to  
  9. other platforms as well (perhaps with a little tweaking).  Here is the README  
  10. file:
  11.  
  12.  
  13. GDB Language Support for Objective C
  14. Submitted by Michael Snyder
  15. NeXT Software, Inc.
  16.  
  17. This is a portable implementation of NeXT's gdb support for debugging
  18. Objective C.  This has only been tested with Gnu's GCC-based Objective
  19. C compiler, and may not work with other compilers or runtime
  20. libraries.  It has been tested to a limited extent with the public
  21. version of GCC and GnuStep, with the majority of the testing being
  22. done under NeXT's proprietary versions of the compiler and OpenStep.
  23. It has been tested on Microsoft Windows NT (Gnu and NeXT compilers),
  24. Solaris (NeXT compiler), and HPUX (NeXT compiler).  I expect it to
  25. work on other platforms in the Gnu environment, but would not be
  26. surprised if some tweaking were required.
  27.  
  28. Language specific features:
  29.  * Auto-recognition of Objective C source code (by the ".m" extension)
  30.  * Demangling of Objective C mangled method names in backtraces etc.
  31.  * Accepts demangled (native) form for Objective C method names
  32.    for setting breakpoints etc.
  33.  * Understands class scope for instance variables in expressions
  34.    (automatically dereferences things from the "self" pointer)
  35.  * Step into Objective C message calls
  36.  * Call Objective C methods and print their return values
  37.    (in native syntax, eg. "print [MyClass myMethod:42]")
  38.  * LIST or BREAK on selectors gives a list of matching implementations
  39.    (just like what happens with overloaded C++ member functions)
  40.  * Tab-completion on methods and selectors
  41.  * @selector operator
  42.  * INFO CLASS and INFO SELECTOR commands
  43.  * NSString literals in expressions (eg. @"foo")
  44.  * Class names recognised with or without the keyword "struct"
  45.  
  46.  
  47.  
  48. Auto language recognition:
  49. Objective C is a first-class language in gdb (just like C++ or
  50. FORTRAN).  Gdb auto-detects Objective C source files by the ".m"
  51. extension, enabling name demangling and other language features.
  52. Should you need to force the current language to Objective C (eg. for
  53. programs compiled with no symbol information), use:
  54.      "SET LANGUAGE objective-c".
  55.  
  56.  
  57. Symbol Demangling:
  58. Objective C methods names are mangled by GCC into a form that looks
  59. like (for example) "_i_Classname_Categoryname_Selectorname__" where
  60. colons (":") in the selector name are replaced with underscores ("_").
  61. Gdb will reverse this mangling to present the method name as
  62. "-[Classname(Categoryname) Selectorname::]".  Unfortunately this
  63. mangling scheme is not uniquely reversable if class, category or
  64. selector names contain underscores, so gdb will demangle such names
  65. incorrectly.
  66.  
  67.  
  68. Native-form Names of Objective C Methods:
  69. Breakpoint commands etc. can refer to Objective C methods in their
  70. demangled form:
  71.     (gdb) BREAK +[Classname Selector:withArg:andArg:]
  72.  
  73.  
  74. Class scope:
  75. If you are debugging in an Objective C method of a class that has an
  76. instance variable (eg. "foo"), you can refer to that variable by name,
  77.     (gdb) print foo
  78. without having to refer to it thru the self pointer:
  79.     (gdb) print self->foo    // C++ analogy: this->foo
  80.  
  81.  
  82.  
  83. Calls to Objective C Methods in expressions:
  84. The PRINT and CALL commands can be used to call Objective C methods
  85. using the native syntax (and print their return values):
  86.     (gdb) call  [foo withBar: 12 andBaz: 14]
  87.     (gdb) print $myfoo = [[Foo alloc] init]
  88.  
  89.  
  90. Selectors treated as overloaded functions:
  91. The BREAK and LIST commands can take a raw selector as an argument.
  92. If the selector is implemented by more than one class, gdb will
  93. present a list of the possible matches, just as it would in the case
  94. of a C++ overloaded member function.  The user can select one,
  95. several, or all of the matches from the list.
  96.     (gdb) break init
  97.     [0] cancel
  98.     [1] all
  99.     [2] -[Change init] at Change.m:20
  100.     [3] -[ChangeManager init] at ChangeManage.m:30
  101.     [4] -[DrawApp init] at DrawApp.m:130
  102.     >
  103.  
  104.  
  105. INFO CLASS and INFO SELECTOR commands:
  106. By analogy with the INFO FUNCTION and INFO TYPE commands, these accept
  107. a regular expression and print a list of Objective C classes or selectors
  108. that match.
  109.  
  110.  
  111. NSString literals:
  112. Many Objective C methods expect an NSString literal as an argument,
  113. and many expressions that might be cut-and-paste evaluated from an
  114. Objective C program contain such literals.  As a convenience, GDB
  115. will accept such a literal, and build an NSString constant in the
  116. child process address space.
  117.     (gdb) print [NSImage imageNamed: @"Cross.tiff"]
  118.  
  119.  
  120. Builtin typedefs for classes:
  121. As with C++, the Objective C language does not expect you to use
  122. the keyword "struct" in front of a class name.  However the GCC
  123. compiler emits the type symbols for classes as structs.  GDB will
  124. automatically create an internal typedef symbol that might look like:
  125.     typedef struct NSString NSString;
  126. so that the user can use casts like "(NSString *) 0" instead of
  127. having to type "(struct NSString *) 0" (although the later will
  128. still be accepted too).
  129.  
  130.