summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsb <sb@openoffice.org>2010-12-14 13:30:07 +0100
committersb <sb@openoffice.org>2010-12-14 13:30:07 +0100
commitf3aea77133c6e6de2f7dd0cf876a942783200f0c (patch)
tree31581cda1bee3e8bd38b2ff0c8eca1a5bf2fa4cb
parent686f98d534828e4b8f9decba5f0c73d76d249b31 (diff)
sb135: #i116050# make osl_trace output atomic
-rw-r--r--sal/osl/all/makefile.mk6
-rw-r--r--sal/osl/all/printtrace.cxx65
-rw-r--r--sal/osl/inc/printtrace.h46
-rw-r--r--sal/osl/os2/diagnose.c26
-rw-r--r--sal/osl/unx/diagnose.c32
-rwxr-xr-x[-rw-r--r--]sal/osl/w32/diagnose.c37
6 files changed, 132 insertions, 80 deletions
diff --git a/sal/osl/all/makefile.mk b/sal/osl/all/makefile.mk
index 0d105906e..5da61e8b2 100644
--- a/sal/osl/all/makefile.mk
+++ b/sal/osl/all/makefile.mk
@@ -55,7 +55,8 @@ SLOFILES= \
$(SLO)$/utility.obj\
$(SLO)$/filepath.obj\
$(SLO)$/debugbase.obj\
- $(SLO)$/loadmodulerelative.obj
+ $(SLO)$/loadmodulerelative.obj \
+ $(SLO)/printtrace.obj
# $(SLO)$/readline.obj\
@@ -64,7 +65,8 @@ OBJFILES= \
$(OBJ)$/utility.obj\
$(OBJ)$/filepath.obj\
$(OBJ)$/debugbase.obj\
- $(OBJ)$/loadmodulerelative.obj
+ $(OBJ)$/loadmodulerelative.obj \
+ $(OBJ)/printtrace.obj
# $(OBJ)$/readline.obj\
#.ENDIF
diff --git a/sal/osl/all/printtrace.cxx b/sal/osl/all/printtrace.cxx
new file mode 100644
index 000000000..5d79d9b1d
--- /dev/null
+++ b/sal/osl/all/printtrace.cxx
@@ -0,0 +1,65 @@
+/*************************************************************************
+*
+* 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);
+}
diff --git a/sal/osl/inc/printtrace.h b/sal/osl/inc/printtrace.h
new file mode 100644
index 000000000..9e1d514b0
--- /dev/null
+++ b/sal/osl/inc/printtrace.h
@@ -0,0 +1,46 @@
+/*************************************************************************
+*
+* 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
diff --git a/sal/osl/os2/diagnose.c b/sal/osl/os2/diagnose.c
index 32e00db76..eabb3eae5 100644
--- a/sal/osl/os2/diagnose.c
+++ b/sal/osl/os2/diagnose.c
@@ -35,6 +35,8 @@
#include <osl/diagnose.h>
#include <osl/thread.h>
+#include "printtrace.h"
+
BYTE oslTraceEnv[] = "OSL_TRACE_TO_FILE";
typedef pfunc_osl_printDebugMessage oslDebugMessageFunc;
@@ -53,29 +55,11 @@ void SAL_CALL osl_breakDebug()
/************************************************************************/
/* osl_trace */
/************************************************************************/
-/* comment this define to stop output thread identifier*/
-#define OSL_TRACE_THREAD 1
-void SAL_CALL osl_trace (
- const sal_Char* lpszFormat, ...)
-{
+void osl_trace(char const * pszFormat, ...) {
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_start(args, pszFormat);
+ printTrace(0, pszFormat, args); /* TODO: pid */
va_end(args);
-
- fprintf(stderr,"\n");
- fflush(stderr);
}
/*----------------------------------------------------------------------------*/
diff --git a/sal/osl/unx/diagnose.c b/sal/osl/unx/diagnose.c
index e98910da9..07341e1ec 100644
--- a/sal/osl/unx/diagnose.c
+++ b/sal/osl/unx/diagnose.c
@@ -28,7 +28,6 @@
#include "osl/diagnose.h"
#include "system.h"
-
#ifndef HAVE_DLFCN_H
#if defined(LINUX) || defined(SOLARIS)
@@ -58,6 +57,8 @@
#define INCLUDED_STDDEF_H
#endif
+#include "printtrace.h"
+
/************************************************************************/
/* Internal data structures and functions */
/************************************************************************/
@@ -301,32 +302,9 @@ pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc (
/************************************************************************/
/* osl_trace */
/************************************************************************/
-/* comment this define to stop output thread identifier*/
-#define OSL_TRACE_THREAD 1
-void SAL_CALL osl_trace (
- const sal_Char* lpszFormat, ...)
-{
+void osl_trace(char const * pszFormat, ...) {
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_start(args, pszFormat);
+ printTrace((unsigned long) getpid(), pszFormat, args);
va_end(args);
-
- fprintf(stderr,"\n");
- fflush(stderr);
}
-
-/************************************************************************/
-
diff --git a/sal/osl/w32/diagnose.c b/sal/osl/w32/diagnose.c
index 129f579c4..97fe8d275 100644..100755
--- a/sal/osl/w32/diagnose.c
+++ b/sal/osl/w32/diagnose.c
@@ -32,6 +32,8 @@
#include <osl/diagnose.h>
#include <osl/thread.h>
+#include "printtrace.h"
+
#define NO_DEBUG_CRT
static pfunc_osl_printDebugMessage _pPrintDebugMessage = NULL;
@@ -61,46 +63,21 @@ void SAL_CALL osl_breakDebug(void)
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, ...)
-{
+void osl_trace(char const * pszFormat, ...) {
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
-
+ 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);
-
+ printTrace((unsigned long) _getpid(), pszFormat, args);
va_end(args);
}