Commits

Anonymous committed 30fc18d

sb135: #i116050# make osl_trace output atomic

Comments (0)

Files changed (6)

sal/osl/all/makefile.mk

 			$(SLO)$/utility.obj\
 			$(SLO)$/filepath.obj\
 			$(SLO)$/debugbase.obj\
-            $(SLO)$/loadmodulerelative.obj
+            $(SLO)$/loadmodulerelative.obj \
+            $(SLO)/printtrace.obj
 
 #			$(SLO)$/readline.obj\
 
 			$(OBJ)$/utility.obj\
 			$(OBJ)$/filepath.obj\
 			$(OBJ)$/debugbase.obj\
-            $(OBJ)$/loadmodulerelative.obj
+            $(OBJ)$/loadmodulerelative.obj \
+            $(OBJ)/printtrace.obj
 
 #			$(OBJ)$/readline.obj\
 #.ENDIF

sal/osl/all/printtrace.cxx

+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org.  If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+#include "precompiled_sal.hxx"
+
+#include "sal/config.h"
+
+#include <cstdarg>
+#include <cstdio>
+#include <cstring>
+
+#include <stdio.h> // snprintf, vsnprintf
+
+#include "osl/diagnose.h"
+#include "osl/thread.hxx"
+#include "rtl/string.h"
+#include "sal/types.h"
+
+#include "printtrace.h"
+
+void printTrace(unsigned long pid, char const * format, std::va_list arguments)
+{
+    char buf[1024];
+    int n1 = snprintf(
+        buf, sizeof buf, "Trace %lu/%" SAL_PRIuUINT32 ": \"", pid,
+        osl::Thread::getCurrentIdentifier());
+    OSL_ASSERT(
+        n1 >= 0 &&
+        (static_cast< unsigned int >(n1) <
+         sizeof buf - RTL_CONSTASCII_LENGTH("\"...\n")));
+    int n2 = sizeof buf - n1 - RTL_CONSTASCII_LENGTH("\"...\n");
+    int n3 = vsnprintf(buf + n1, n2, format, arguments);
+    if (n3 < 0) {
+        std::strcpy(buf + n1, "\"???\n");
+    } else if (n3 < n2) {
+        std::strcpy(buf + n1 + n3, "\"\n");
+    } else {
+        std::strcpy(buf + n1 + n2 - 1, "\"...\n");
+    }
+    std::fputs(buf, stderr);
+}

sal/osl/inc/printtrace.h

+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org.  If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+#ifndef INCLUDED_SAL_OSL_INC_PRINTTRACE_H
+#define INCLUDED_SAL_OSL_INC_PRINTTRACE_H
+
+#include "sal/config.h"
+
+#include <stdarg.h>
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+/* called internally by osl_trace */
+void printTrace(unsigned long pid, char const * format, va_list arguments);
+
+#if defined __cplusplus
+}
+#endif
+
+#endif

sal/osl/os2/diagnose.c

 #include <osl/diagnose.h>
 #include <osl/thread.h>
 
+#include "printtrace.h"
+
 BYTE oslTraceEnv[] = "OSL_TRACE_TO_FILE";
 
 typedef pfunc_osl_printDebugMessage oslDebugMessageFunc;
 /************************************************************************/
 /* osl_trace */
 /************************************************************************/
-/* comment this define to stop output thread identifier*/
-#define OSL_TRACE_THREAD 1
-void SAL_CALL osl_trace (
-	const sal_Char* lpszFormat, ...)
-{
-	va_list args;
-
-#if defined(OSL_PROFILING)
-    fprintf(stderr, "Time: %06lu : ", osl_getGlobalTimer() );
-#else
-#if defined(OSL_TRACE_THREAD)
-    fprintf(stderr,"Thread: %6d :",osl_getThreadIdentifier(NULL));
-#else
-    fprintf(stderr, "Trace Message: ");
-#endif
-#endif
-
-	va_start(args, lpszFormat);
-	vfprintf(stderr, lpszFormat, args);
-	va_end(args);
-
-    fprintf(stderr,"\n");
-    fflush(stderr);
+void osl_trace(char const * pszFormat, ...) {
+    va_list args;
+    va_start(args, pszFormat);
+    printTrace(0, pszFormat, args); /* TODO: pid */
+    va_end(args);
 }
 
 /*----------------------------------------------------------------------------*/

sal/osl/unx/diagnose.c

 #include "osl/diagnose.h"
 #include "system.h"
 
-
 #ifndef HAVE_DLFCN_H
 
 #if defined(LINUX) || defined(SOLARIS)
 #define INCLUDED_STDDEF_H
 #endif
 
+#include "printtrace.h"
+
 /************************************************************************/
 /* Internal data structures and functions */
 /************************************************************************/
 /************************************************************************/
 /* osl_trace */
 /************************************************************************/
-/* comment this define to stop output thread identifier*/
-#define OSL_TRACE_THREAD 1
-void SAL_CALL osl_trace (
-	const sal_Char* lpszFormat, ...)
-{
-	va_list args;
-
-#if defined(OSL_PROFILING)
-    fprintf(stderr, "Time: %06lu : ", osl_getGlobalTimer() );
-#else
-#if defined(OSL_TRACE_THREAD)
-    fprintf(
-        stderr, "Thread: %6lu :",
-        SAL_INT_CAST(unsigned long, osl_getThreadIdentifier(NULL)));
-#else
-    fprintf(stderr, "Trace Message: ");
-#endif
-#endif
-
-	va_start(args, lpszFormat);
-	vfprintf(stderr, lpszFormat, args);
-	va_end(args);
-
-    fprintf(stderr,"\n");
-    fflush(stderr);
+void osl_trace(char const * pszFormat, ...) {
+    va_list args;
+    va_start(args, pszFormat);
+    printTrace((unsigned long) getpid(), pszFormat, args);
+    va_end(args);
 }
-
-/************************************************************************/
-

sal/osl/w32/diagnose.c

 #include <osl/diagnose.h>
 #include <osl/thread.h>
 
+#include "printtrace.h"
+
 #define NO_DEBUG_CRT
 
 static pfunc_osl_printDebugMessage	_pPrintDebugMessage = NULL;
 	DebugBreak();
 }
 
-
-
-/* Uncomment this define to get profiling time output */
-/* #define OSL_PROFILING */
-/* comment this define to stop output thread identifier*/
-#define OSL_TRACE_THREAD 1
-void SAL_CALL osl_trace(const sal_Char* lpszFormat, ...)
-{
-	va_list args;
-    int written = 0;
-
-	va_start(args, lpszFormat);
-
-#if defined(OSL_PROFILING)
-    fprintf(stderr, "time : %06lu : ", osl_getGlobalTimer() );
-#else
-#if defined(OSL_TRACE_THREAD)
-    fprintf(stderr,"Thread: %6d :",osl_getThreadIdentifier(NULL));
-#else
-    fprintf(stderr,"Trace Message : ");
-#endif
-#endif
-
+void osl_trace(char const * pszFormat, ...) {
+    va_list args;
+    va_start(args, pszFormat);
     if ( IsDebuggerPresent() )
     {
         sal_Char	szMessage[512];
-        written = _vsnprintf( szMessage, sizeof(szMessage) - 2, lpszFormat, args );
+        int written = _vsnprintf(
+            szMessage, sizeof(szMessage) - 2, pszFormat, args );
         if ( written == -1 )
             written = sizeof(szMessage) - 2;
         szMessage[ written++ ] = '\n';
         szMessage[ written ] = 0;
         OutputDebugString( szMessage );
     }
-
-	vfprintf(stderr,lpszFormat, args);
-
-    fprintf(stderr,"\n");
-
-    fflush(stderr);
-     
-	va_end(args);
+    printTrace((unsigned long) _getpid(), pszFormat, args);
+    va_end(args);
 }
 
 sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage)