This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: Restored Objective-C language support
- From: Giah de Barag <gdb at crelg dot com>
- To: GDB Patches <gdb-patches at sourceware dot org>
- Cc: Matt Rice <ratmice at gmail dot com>, Tom Tromey <tom at tromey dot com>
- Date: Thu, 15 Sep 2016 15:12:13 -0400
- Subject: Re: Restored Objective-C language support
- Authentication-results: sourceware.org; auth=none
- References: <3AC64B67-79FD-4F55-8F6E-3784C3C4A13B@crelg.com> <87intyrt26.fsf@tromey.com> <CACTLOFqqr6ab08h1LA8yv5=wOs0YBvK+x_VD93LzNn2BG3ffjA@mail.gmail.com>
GDB and Objective C
-------------------
1. GDB Objective C Language Support
2. How GDB Creates Objective C NSString Objects
3. How GDB Looks Up Objective C Selectors
4. GNUstep Source & Build Scripts
5. GNUstep and GDB Test
6. Questions Regarding the Patch
1. GDB Objective C Language Support
-----------------------------------
GDB support for Objective C (GCC libobjc and GNUstep) is deep,
powerful, and way beyond mature. The transition from Object to
NSObject was made somewhere around 1990.
GNUstep is *the* (the) GNU library of Objective C high-level types
(string, array, dictionary, set, process, thread, file, etc).
GCC libobjc is one of the two (2) low-level implementations of the
object-oriented runtime design (object, method, selector, etc.) that
work with GCC/GDB.
GNUstep is a part of the GNU software collection, is trivial to build
and package, and is a package on GNU-type system distributions.
GDB’s Objective C language support code has interacted with GNUstep
and the NSObject hierarchy for decades. That code is simple, easy to
understand, and easy to maintain.
2. How GDB Creates Objective C NSString Objects
-----------------------------------------------
Here is a look at part of the GDB/GNUstep debugger API.
In this example, GDB creates a GNUstep NSString when the user types
@"foo". It looks for a convenience function _NSNewStringFromCString,
and if not found, it sends the message stringWithCString to the
GNUstep class NSString.
if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0).minsym)
{
function = find_function_in_inferior("_NSNewStringFromCString", NULL);
nsstringValue = call_function_by_hand(function, 1, &stringValue[2]);
}
else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0).minsym)
{
function
= find_function_in_inferior("+[NSString stringWithCString:]", NULL);
type = builtin_type (gdbarch)->builtin_long;
stringValue[0] = value_from_longest
(type, lookup_objc_class (gdbarch, "NSString"));
stringValue[1] = value_from_longest
(type, lookup_child_selector (gdbarch, "stringWithCString:"));
nsstringValue = call_function_by_hand(function, 3, &stringValue[0]);
}
else
error (_("NSString: internal error -- no way to create new NSString"));
In http://svn.gna.org/svn/gnustep/libs/base/trunk/Source/NSDebug.m,
which is in the GNUstep repository, at the very end of the file, you
can see the implementation of _NSNewStringFromCString. Also there is
the function _NSPrintForDebugger which handles the “po” (print object)
command of GDB.
// GNUstep debugger support functions
NSString *_NSNewStringFromCString(const char *cstring);
const char *_NSPrintForDebugger(id object);
3. How GDB Looks Up Objective C Selectors
-----------------------------------------
Here is GDB’s code that looks up a selector.
In the previous example, GDB addressed GNUstep, the high-level type
library, to create an Objective C string (NSString), and here we are
interacting with the low-level runtime library, GCC libobjc, and its
function sel_getUid.
if (lookup_minimal_symbol("sel_getUid", 0, 0).minsym)
function = find_function_in_inferior("sel_getUid", NULL);
else
{
complaint (&symfile_complaints,
_("no way to lookup Objective-C selectors"));
return 0;
}
In https://github.com/gcc-mirror/gcc/blob/master/libobjc/selector.c at the
very end you can see sel_getUid, which takes the string name representing a
method and returns the selector for it, SEL sel_getUid (const char *name).
4. GNUstep Source & Build Scripts
---------------------------------
GNUstep is trivial to install. If it is not a package, you can check
it out and build it.
You only need the “base” library which implements the basic high-level
types like NSString and has the GDB debugger support functions.
Source:
svn co http://svn.gna.org/svn/gnustep/modules/core
(For GDB Objective C language support,
only “make” and “base” are needed.)
Build Scripts:
http://svn.gna.org/svn/gnustep/tools/scripts/trunk/
It would be good for the teams (GCC/GDB/GNUstep) to be more in step
with each other. What do you think?
5. GNUstep and GDB Test
-----------------------
This is a test of:
a) printing an object with po
b) sending a message with [obj msg:arg]
c) creating an NSString with @"foo"
d) looking up a selector with @selector(msg)
GDB console session:
(gdb) po [@"foo" performSelector:@selector(uppercaseString)]
FOO
(gdb)
6. Questions Regarding the Patch
--------------------------------
FAOD:
1. About the Contribution Checklist. Do you need me to update this
patch to conform to the Contribution Checklist?
2. About tests. Are there in fact no automated tests for objective-c
support, and do you need me to create them?
3. Are there any barriers to this patch getting into 7.11, 7.12, and
master (other than the above two questions)?
Thank you.