[Libreoffice-commits] core.git: include/sal sal/inc sal/osl sal/util

Noel Grandin noel.grandin at collabora.co.uk
Tue Jan 10 06:31:57 UTC 2017


 include/sal/detail/log.h     |    1 -
 include/sal/log.hxx          |   24 +++++++++++++++++++++---
 sal/inc/misc.hxx             |    2 +-
 sal/osl/all/log.cxx          |   29 ++++++++++++++++++++---------
 sal/osl/unx/backtraceapi.cxx |    2 +-
 sal/osl/w32/backtrace.cxx    |    6 +++---
 sal/util/sal.map             |    5 +++++
 7 files changed, 51 insertions(+), 18 deletions(-)

New commits:
commit 56d071c10ca8016848f1f059aa3eb197fe928844
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Dec 8 11:22:37 2016 +0200

    rename SAL_DEBUG_TRACE to SAL_DEBUG_BACKTRACE
    
    since "trace" is such a generic term, this makes it easier to actually find the feature when you need it.
    
    And add feature to limit stack depth of the reported backtrace.
    
    Change-Id: Iab3e4ceb2e8480e7b5e2b920eb6c5d7631e21c43
    Reviewed-on: https://gerrit.libreoffice.org/31752
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sal/detail/log.h b/include/sal/detail/log.h
index ab97185..11ece36 100644
--- a/include/sal/detail/log.h
+++ b/include/sal/detail/log.h
@@ -52,7 +52,6 @@ extern "C" {
 
 enum sal_detail_LogLevel {
     SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
-    SAL_DETAIL_LOG_LEVEL_DEBUG_TRACE = SAL_MAX_ENUM - 1,
     SAL_DETAIL_LOG_LEVEL_DEBUG = SAL_MAX_ENUM
 };
 
diff --git a/include/sal/log.hxx b/include/sal/log.hxx
index 8b4ef0a..4438ec5 100644
--- a/include/sal/log.hxx
+++ b/include/sal/log.hxx
@@ -30,6 +30,10 @@ extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_log(
     enum sal_detail_LogLevel level, char const * area, char const * where,
     char const * message);
 
+extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_log_backtrace(
+    enum sal_detail_LogLevel level, char const * area, char const * where,
+    char const * message, int maxNoStackFramesToDisplay);
+
 namespace sal { namespace detail {
 
 inline void SAL_CALL log(
@@ -343,9 +347,23 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
 
   See @ref sal_log "basic logging functionality" for details.
 */
-#define SAL_DEBUG_TRACE(stream) \
-    SAL_DETAIL_LOG_STREAM( \
-        SAL_LOG_TRUE, ::SAL_DETAIL_LOG_LEVEL_DEBUG_TRACE, NULL, NULL, stream)
+#define SAL_DEBUG_BACKTRACE(stream, maxNoStackFramesToDisplay) \
+    do { \
+        if (sizeof ::sal::detail::getResult(::sal::detail::StreamStart() << stream) == 1) \
+        { \
+            ::sal_detail_log_backtrace( \
+                ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, \
+                ::sal::detail::unwrapStream( \
+                    ::sal::detail::StreamStart() << stream)); \
+        } else { \
+            ::std::ostringstream sal_detail_stream; \
+            sal_detail_stream << stream; \
+            ::sal::detail::log( \
+                ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, sal_detail_stream); \
+        } \
+    } while (false)
+
+
 
 #endif
 
diff --git a/sal/inc/misc.hxx b/sal/inc/misc.hxx
index b93868e..440c00c 100644
--- a/sal/inc/misc.hxx
+++ b/sal/inc/misc.hxx
@@ -12,7 +12,7 @@
 #include <rtl/ustring.hxx>
 
 /// Build a debugging backtrace from current PC location.
-rtl_uString *osl_backtraceAsString(void);
+rtl_uString *osl_backtraceAsString(int maxNoStackFramesToDisplay);
 
 #endif // INCLUDED_SAL_INC_INTERNAL_MISC_H
 
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 23f45cd..7245a51 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -68,7 +68,6 @@ char const * toString(sal_detail_LogLevel level) {
     case SAL_DETAIL_LOG_LEVEL_WARN:
         return "warn";
     case SAL_DETAIL_LOG_LEVEL_DEBUG:
-    case SAL_DETAIL_LOG_LEVEL_DEBUG_TRACE:
         return "debug";
     default:
         assert(false); // this cannot happen
@@ -188,8 +187,7 @@ void maybeOutputTimestamp(std::ostringstream &s) {
 #endif
 
 bool isDebug(sal_detail_LogLevel level) {
-    return level == SAL_DETAIL_LOG_LEVEL_DEBUG ||
-        level == SAL_DETAIL_LOG_LEVEL_DEBUG_TRACE;
+    return level == SAL_DETAIL_LOG_LEVEL_DEBUG;
 }
 
 bool report(sal_detail_LogLevel level, char const * area) {
@@ -298,10 +296,6 @@ void log(
     }
 
     s << message;
-    if (level == SAL_DETAIL_LOG_LEVEL_DEBUG_TRACE) {
-        s << " at:\n";
-        s << OUString(osl_backtraceAsString(), SAL_NO_ACQUIRE);
-    }
     s << '\n';
 
 #if defined ANDROID
@@ -314,7 +308,6 @@ void log(
         android_log_level = ANDROID_LOG_WARN;
         break;
     case SAL_DETAIL_LOG_LEVEL_DEBUG:
-    case SAL_DETAIL_LOG_LEVEL_DEBUG_TRACE:
         android_log_level = ANDROID_LOG_DEBUG;
         break;
     default:
@@ -336,7 +329,6 @@ void log(
             prio = LOG_WARNING;
             break;
         case SAL_DETAIL_LOG_LEVEL_DEBUG:
-        case SAL_DETAIL_LOG_LEVEL_DEBUG_TRACE:
             prio = LOG_DEBUG;
             break;
         default:
@@ -359,6 +351,16 @@ void log(
 #endif
 }
 
+void log_backtrace(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    char const * message, int maxNoStackFramesToDisplay)
+{
+    OUString buff = OUString::createFromAscii(message) +
+                    " at:\n" +
+                    OUString(osl_backtraceAsString(maxNoStackFramesToDisplay), SAL_NO_ACQUIRE);
+    log(level, area, where, buff.toUtf8().getStr());
+}
+
 }
 
 void sal_detail_log(
@@ -370,6 +372,15 @@ void sal_detail_log(
     }
 }
 
+void sal_detail_log_backtrace(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    char const * message, int maxNoStackFramesToDisplay)
+{
+    if (report(level, area)) {
+        log_backtrace(level, area, where, message, maxNoStackFramesToDisplay);
+    }
+}
+
 void sal_detail_logFormat(
     sal_detail_LogLevel level, char const * area, char const * where,
     char const * format, ...)
diff --git a/sal/osl/unx/backtraceapi.cxx b/sal/osl/unx/backtraceapi.cxx
index 1895c43..d42fe67 100644
--- a/sal/osl/unx/backtraceapi.cxx
+++ b/sal/osl/unx/backtraceapi.cxx
@@ -13,7 +13,7 @@
 #include "misc.hxx"
 
 // FIXME: no-op for now; it needs implementing, cf. above.
-rtl_uString *osl_backtraceAsString()
+rtl_uString *osl_backtraceAsString(int /*maxNoStackFramesToDisplay*/)
 {
     OUStringBuffer aBuf;
     OUString aStr = aBuf.makeStringAndClear();
diff --git a/sal/osl/w32/backtrace.cxx b/sal/osl/w32/backtrace.cxx
index b618c68..e4e71c2 100644
--- a/sal/osl/w32/backtrace.cxx
+++ b/sal/osl/w32/backtrace.cxx
@@ -17,15 +17,15 @@
 
 #include <rtl/ustrbuf.hxx>
 
-rtl_uString *osl_backtraceAsString()
+rtl_uString *osl_backtraceAsString(int maxNoStackFramesToDisplay)
 {
     OUStringBuffer aBuf;
 
     HANDLE hProcess = GetCurrentProcess();
     SymInitialize( hProcess, nullptr, true );
 
-    void * aStack[ 512 ];
-    sal_uInt32 nFrames = CaptureStackBackTrace( 0, 512, aStack, nullptr );
+    void * aStack[ maxNoStackFramesToDisplay ];
+    sal_uInt32 nFrames = CaptureStackBackTrace( 0, maxNoStackFramesToDisplay, aStack, nullptr );
 
     SYMBOL_INFO  * pSymbol;
     pSymbol = static_cast<SYMBOL_INFO *>(calloc( sizeof( SYMBOL_INFO ) + 1024 * sizeof( char ), 1 ));
diff --git a/sal/util/sal.map b/sal/util/sal.map
index c8f3a74..96ea9d1 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -728,6 +728,11 @@ PRIVATE_1.2 { # LibreOffice 3.5
         sal_detail_logFormat;
 } PRIVATE_1.1;
 
+PRIVATE_1.3 { # LibreOffice 5.4
+    global:
+        sal_detail_log_backtrace;
+} PRIVATE_1.2;
+
 PRIVATE_textenc.1 { # LibreOffice 3.6
     global:
         _ZN3sal6detail7textenc20convertCharToUnicode*;


More information about the Libreoffice-commits mailing list