From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56406 invoked by alias); 15 Sep 2016 19:12:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 56380 invoked by uid 89); 15 Sep 2016 19:12:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=teams, distributions, decades, H*r:4.80.1 X-HELO: telf.telf.com Received: from tel.telf.com (HELO telf.telf.com) (192.254.205.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Sep 2016 19:12:18 +0000 Received: from rrcs-70-60-125-182.midsouth.biz.rr.com ([70.60.125.182]:4962 helo=[10.0.9.33]) by telf.telf.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.80.1) (envelope-from ) id 1bkc52-0002bo-4P; Thu, 15 Sep 2016 15:12:16 -0400 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: Restored Objective-C language support From: Giah de Barag In-Reply-To: Date: Thu, 15 Sep 2016 19:12:00 -0000 Cc: Matt Rice , Tom Tromey Content-Transfer-Encoding: quoted-printable Message-Id: <63783A0C-3734-4A0C-85B1-4DDC54EC0979@crelg.com> References: <3AC64B67-79FD-4F55-8F6E-3784C3C4A13B@crelg.com> <87intyrt26.fsf@tromey.com> To: GDB Patches X-Get-Message-Sender-Via: telf.telf.com: authenticated_id: gdb@crelg.com X-SW-Source: 2016-09/txt/msg00170.txt.bz2 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=E2=80=99s 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 =3D find_function_in_inferior("_NSNewStringFromCString", NUL= L); nsstringValue =3D call_function_by_hand(function, 1, &stringValue[2]); } else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0).mi= nsym) { function =3D find_function_in_inferior("+[NSString stringWithCString:]", NULL); type =3D builtin_type (gdbarch)->builtin_long; stringValue[0] =3D value_from_longest=20 (type, lookup_objc_class (gdbarch, "NSString")); stringValue[1] =3D value_from_longest=20 (type, lookup_child_selector (gdbarch, "stringWithCString:")); nsstringValue =3D 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 =E2=80=9Cpo=E2=80=9D (pr= int 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=E2=80=99s 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 =3D 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 =E2=80=9Cbase=E2=80=9D 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 =E2=80=9Cmake=E2=80=9D and =E2=80=9Cbase=E2=80=9D 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)=20 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.