From: Giah de Barag <gdb@crelg.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Matt Rice <ratmice@gmail.com>, Tom Tromey <tom@tromey.com>
Subject: Re: Restored Objective-C language support
Date: Thu, 15 Sep 2016 19:12:00 -0000 [thread overview]
Message-ID: <63783A0C-3734-4A0C-85B1-4DDC54EC0979@crelg.com> (raw)
In-Reply-To: <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.
next prev parent reply other threads:[~2016-09-15 19:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-13 21:21 Giah de Barag
2016-09-14 22:54 ` Tom Tromey
2016-09-15 0:31 ` Matt Rice
2016-09-15 19:12 ` Giah de Barag [this message]
2016-09-16 5:52 ` Giah de Barag
2016-09-27 21:03 ` Giah de Barag
2016-10-12 2:14 ` Tom Tromey
2016-09-14 6:09 Roland Schwingel
2016-09-14 7:25 ` Giah de Barag
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=63783A0C-3734-4A0C-85B1-4DDC54EC0979@crelg.com \
--to=gdb@crelg.com \
--cc=gdb-patches@sourceware.org \
--cc=ratmice@gmail.com \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox