Author: rfm
Date: Sun Mar 1 20:37:28 2015
New Revision: 38370
URL: http://svn.gna.org/viewcvs/gnustep?rev=38370&view=rev
Log:
NSLog updates for consistency with latest OSX
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Documentation/Base.gsdoc
libs/base/trunk/Headers/GNUstepBase/config.h.in
libs/base/trunk/Source/GSPrivate.h
libs/base/trunk/Source/NSLog.m
libs/base/trunk/configure
libs/base/trunk/configure.ac
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=38370&r1=38369&r2=38370&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Sun Mar 1 20:37:28 2015
@@ -1,3 +1,17 @@
+2015-02-28 Richard Frith-Macdonald <[email protected]>
+
+ * configure.ac: Check for gettid availability
+ * configure: Regenerate
+ * Headers/GNUstepBase/config.h.in: Regenerate
+ * Source/GSPrivate.h: Update comment on GSLogThread
+ * Documentation/Base.gsdoc: Update doc of GSLogThread
+ * Source/NSLog.m: Change to log thread ID (to match OSX which now
+ logs the thread ID along with the process ID). Change the meaning
+ of the GSLogThread user default (which used to turn on logging of
+ the thread ID) so that it now turns on logging of the thread name
+ (where a thread name has been set) and the NSThread address if no
+ name has been set.
+
2015-02-16 Wolfgang Lux <[email protected]>
* Source/NSData.m (writeToFile:options:error:): Fix leak of open
Modified: libs/base/trunk/Documentation/Base.gsdoc
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Documentation/Base.gsdoc?rev=38370&r1=38369&r2=38370&view=diff
==============================================================================
--- libs/base/trunk/Documentation/Base.gsdoc (original)
+++ libs/base/trunk/Documentation/Base.gsdoc Sun Mar 1 20:37:28 2015
@@ -165,8 +165,8 @@
<p>
Setting the user default <code>GSLogThread</code> to
<code>YES</code> will cause NSLog and debug output to
- include the current thread in the logged message.<br />
- This is useful for debugging multi-threaded applications.
+ include the current thread name in the logged message.<br />
+ This may be useful for debugging multi-threaded applications.
</p>
</desc>
<term>GSMacOSXCompatible</term>
Modified: libs/base/trunk/Headers/GNUstepBase/config.h.in
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Headers/GNUstepBase/config.h.in?rev=38370&r1=38369&r2=38370&view=diff
==============================================================================
--- libs/base/trunk/Headers/GNUstepBase/config.h.in (original)
+++ libs/base/trunk/Headers/GNUstepBase/config.h.in Sun Mar 1 20:37:28 2015
@@ -293,6 +293,9 @@
/* Define to 1 if you have the `getpwuid_r' function. */
#undef HAVE_GETPWUID_R
+/* Define if you have gettid() */
+#undef HAVE_GETTID
+
/* Define if you have this function */
#undef HAVE_GICONV
@@ -454,6 +457,9 @@
/* Define to 1 if you have the <pthread.h> header file. */
#undef HAVE_PTHREAD_H
+
+/* Define to 1 if you have the `pthread_set_name_np' function. */
+#undef HAVE_PTHREAD_SET_NAME_NP
/* Define this if you work on sysv */
#undef HAVE_PTS_STREAM_MODULES
@@ -775,7 +781,7 @@
/* Define as the link to exe of process in /proc filesystem. */
#undef PROCFS_EXE_LINK
-/* Description: Define set name function for pthread */
+/* Description: Define setname function for pthread with three args */
#undef PTHREAD_SETNAME
/* Define to 1 if the `setpgrp' function takes no argument. */
Modified: libs/base/trunk/Source/GSPrivate.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSPrivate.h?rev=38370&r1=38369&r2=38370&view=diff
==============================================================================
--- libs/base/trunk/Source/GSPrivate.h (original)
+++ libs/base/trunk/Source/GSPrivate.h Sun Mar 1 20:37:28 2015
@@ -235,7 +235,7 @@
GSMacOSXCompatible, // General behavior flag.
GSOldStyleGeometry, // Control geometry string output.
GSLogSyslog, // Force logging to go to syslog.
- GSLogThread, // Include thread ID in log message.
+ GSLogThread, // Include thread name in log message.
GSLogOffset, // Include time zone offset in message.
NSWriteOldStylePropertyLists, // Control PList output.
GSUserDefaultMaxFlag // End marker.
Modified: libs/base/trunk/Source/NSLog.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSLog.m?rev=38370&r1=38369&r2=38370&view=diff
==============================================================================
--- libs/base/trunk/Source/NSLog.m (original)
+++ libs/base/trunk/Source/NSLog.m Sun Mar 1 20:37:28 2015
@@ -37,6 +37,33 @@
#import "Foundation/NSThread.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
+#if defined(HAVE_GETTID)
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#endif
+
+/* Return the current thread ID as an unsigned long.
+ * Ideally, we use the operating-system's notion of a thread ID so
+ * that external process monitoring software will be using the same
+ * value that we log. If we don't know the system's mechanism, we
+ * use the address of the current NSThread object so that, even if
+ * it makes no sense externally, it can still be used to show that
+ * different threads generated different logs.
+ */
+static unsigned long
+GSThreadID()
+{
+#if defined(__MINGW__)
+ return (unsigned long)GetCurrentThreadId();
+#elsif defined(HAVE_GETTID)
+ return (unsigned long)syscall(SYS_gettid);
+#else
+ return (unsigned long)GSCurrentThread();
+#endif
+}
+
+// Some older BSD systems used a non-standard range of thread priorities.
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#elif HAVE_SYS_SLOG_H
@@ -302,8 +329,8 @@
* </p>
* <p>
* In GNUstep, the GSLogThread user default may be set to YES in
- * order to instruct this function to include the internal ID of
- * the current thread after the process ID. This can help you
+ * order to instruct this function to include the name (if any)
+ * of the current thread after the process ID. This can help you
* to track the behavior of a multi-threaded program.<br />
* Also the GSLogOffset user default may be set to YES in order
* to instruct this function to include the time zone offset in
@@ -326,8 +353,9 @@
void
NSLogv(NSString* format, va_list args)
{
- NSString *prefix;
- NSString *message;
+ NSMutableString *prefix;
+ NSString *message;
+ NSString *threadName = nil;
static int pid = 0;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
@@ -345,23 +373,39 @@
#endif
}
+ if (GSPrivateDefaultsFlag(GSLogThread) == YES)
+ {
+ NSThread *t = GSCurrentThread();
+
+ threadName = [t name];
+ /* If no name has been set for the current thread, we log the address
+ * of the NSThread object instead.
+ */
+ if ([threadName length] == 0)
+ {
+ threadName = [NSString stringWithFormat: @"%lu", (unsigned long)t];
+ }
+ }
+
+ prefix = [NSMutableString stringWithCapacity: 1000];
+
#ifdef HAVE_SYSLOG
if (GSPrivateDefaultsFlag(GSLogSyslog) == YES)
{
- if (GSPrivateDefaultsFlag(GSLogThread) == YES)
- {
- prefix = [NSString stringWithFormat: @"[thread:%"PRIxPTR"] ",
- (NSUInteger)GSCurrentThread()];
- }
+ if (nil != threadName)
+ {
+ [prefix appendFormat: @"[thread:%lu,%@] ", GSThreadID(), threadName];
+ }
else
- {
- prefix = @"";
- }
+ {
+ [prefix appendFormat: @"[thread:%lu] ", GSThreadID()];
+ }
}
else
#endif
{
NSString *fmt;
+ NSString *cal;
if (GSPrivateDefaultsFlag(GSLogOffset) == YES)
{
@@ -371,33 +415,30 @@
{
fmt = @"%Y-%m-%d %H:%M:%S.%F";
}
-
- if (GSPrivateDefaultsFlag(GSLogThread) == YES)
- {
- prefix = [NSString
- stringWithFormat: @"%@ %@[%d,%"PRIxPTR"x] ",
- [[NSCalendarDate calendarDate] descriptionWithCalendarFormat: fmt],
- [[NSProcessInfo processInfo] processName],
- pid, (NSUInteger)GSCurrentThread()];
- }
+ cal = [[NSCalendarDate calendarDate] descriptionWithCalendarFormat: fmt];
+
+ [prefix appendString: cal];
+ [prefix appendString: @" "];
+ [prefix appendString: [[NSProcessInfo processInfo] processName]];
+ if (nil == threadName)
+ {
+ [prefix appendFormat: @"[%d:%lu] ",
+ pid, GSThreadID()];
+ }
else
- {
- prefix = [NSString
- stringWithFormat: @"%@ %@[%d] ",
- [[NSCalendarDate calendarDate] descriptionWithCalendarFormat: fmt],
- [[NSProcessInfo processInfo] processName],
- pid];
- }
- }
-
- /* Check if there is already a newline at the end of the format */
- if ([format hasSuffix: @"\n"] == NO)
- {
- format = [format stringByAppendingString: @"\n"];
- }
- message = [NSString stringWithFormat: format arguments: args];
-
- prefix = [prefix stringByAppendingString: message];
+ {
+ [prefix appendFormat: @"[%d:%lu,%@] ",
+ pid, GSThreadID(), threadName];
+ }
+ }
+
+ message = [[NSString alloc] initWithFormat: format arguments: args];
+ [prefix appendString: message];
+ [message release];
+ if ([prefix hasSuffix: @"\n"] == NO)
+ {
+ [prefix appendString: @"\n"];
+ }
if (myLock == nil)
{
Modified: libs/base/trunk/configure
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/configure?rev=38370&r1=38369&r2=38370&view=diff
==============================================================================
--- libs/base/trunk/configure (original)
+++ libs/base/trunk/configure Sun Mar 1 20:37:28 2015
@@ -13711,7 +13711,6 @@
#--------------------------------------------------------------------
-
for ac_func in pthread_set_name_np
do
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
@@ -13989,6 +13988,77 @@
;;
esac
+fi
+
+#--------------------------------------------------------------------
+# Check whether we can get the system thread ID
+#--------------------------------------------------------------------
+{ $as_echo "$as_me:$LINENO: checking for gettid()" >&5
+$as_echo_n "checking for gettid()... " >&6; }
+if test "${ac_cv_gettid+set}" = set; then
+ $as_echo_n "(cached) " >&6
+else
+ if test "$cross_compiling" = yes; then
+ ac_cv_gettid=no
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+int main(int argc, char **argv) {
+pid_t t = syscall(SYS_gettid); return t == -1 ? 1 : 0; }
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_gettid=yes
+else
+ $as_echo "$as_me: program exited with status $ac_status" >&5
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_gettid=no
+fi
+rm -rf conftest.dSYM
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext
conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_gettid" >&5
+$as_echo "$ac_cv_gettid" >&6; }
+if test "$ac_cv_gettid" = "yes"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_GETTID 1
+_ACEOF
+
fi
#--------------------------------------------------------------------
Modified: libs/base/trunk/configure.ac
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/configure.ac?rev=38370&r1=38369&r2=38370&view=diff
==============================================================================
--- libs/base/trunk/configure.ac (original)
+++ libs/base/trunk/configure.ac Sun Mar 1 20:37:28 2015
@@ -1748,7 +1748,6 @@
# Check if we can name pthreads
#--------------------------------------------------------------------
-
AC_CHECK_FUNCS(pthread_set_name_np)
if test $ac_cv_func_pthread_set_name_np == yes; then
AC_DEFINE(PTHREAD_SETNAME(a), (pthread_set_name_np(pthread_self(), a), 0),
@@ -1784,6 +1783,21 @@
[Description: Define setname function for pthread with three args])
;;
esac
+fi
+
+#--------------------------------------------------------------------
+# Check whether we can get the system thread ID
+#--------------------------------------------------------------------
+AC_CACHE_CHECK([for gettid()], ac_cv_gettid,
+[AC_TRY_RUN(#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+int main(int argc, char **argv) {
+pid_t t = syscall(SYS_gettid); return t == -1 ? 1 : 0; },
+[ac_cv_gettid=yes], [ac_cv_gettid=no], [ac_cv_gettid=no])])
+if test "$ac_cv_gettid" = "yes"; then
+ AC_DEFINE(HAVE_GETTID, 1, [Define if you have gettid()])
fi
#--------------------------------------------------------------------
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs