diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-02-09 13:19:11 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-02-09 15:56:50 +0000 |
commit | b6a69585b00867005820c1dd94e10e0e6b545e2a (patch) | |
tree | 39c76e48dffcfbadd619cf7dc52bb9def0f85691 /sal/osl | |
parent | 6851074c8a515ec5a7856d4b744e3425c8829a29 (diff) |
Fold sal_detail_log_backtrace into sal_detail_log
...the latter is LO-privately exported from sal, so it should be OK to add one
more parameter to it.
Change-Id: If6bf3458433aac2cc8b4e0cbd1602306051a777b
Reviewed-on: https://gerrit.libreoffice.org/34080
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal/osl')
-rw-r--r-- | sal/osl/all/log.cxx | 29 | ||||
-rw-r--r-- | sal/osl/unx/backtraceapi.cxx | 17 | ||||
-rw-r--r-- | sal/osl/w32/backtrace.cxx | 23 |
3 files changed, 35 insertions, 34 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index 7a6c3072b940..774e7e87746c 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -192,7 +192,7 @@ bool isDebug(sal_detail_LogLevel level) { void log( sal_detail_LogLevel level, char const * area, char const * where, - char const * message) + char const * message, sal_uInt32 backtraceDepth) { std::ostringstream s; #if !defined ANDROID @@ -218,6 +218,9 @@ void log( } s << message; + if (backtraceDepth != 0) { + s << " at:\n" << osl::detail::backtraceAsString(backtraceDepth); + } s << '\n'; #if defined ANDROID @@ -273,32 +276,14 @@ 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" - + osl::detail::backtraceAsString(maxNoStackFramesToDisplay); - log(level, area, where, buff.toUtf8().getStr()); -} - } void sal_detail_log( sal_detail_LogLevel level, char const * area, char const * where, - char const * message) -{ - if (sal_detail_log_report(level, area)) { - log(level, area, where, message); - } -} - -void sal_detail_log_backtrace( - sal_detail_LogLevel level, char const * area, char const * where, - char const * message, int maxNoStackFramesToDisplay) + char const * message, sal_uInt32 backtraceDepth) { if (sal_detail_log_report(level, area)) { - log_backtrace(level, area, where, message, maxNoStackFramesToDisplay); + log(level, area, where, message, backtraceDepth); } } @@ -317,7 +302,7 @@ void sal_detail_logFormat( } else if (n >= len) { std::strcpy(buf + len - 1, "..."); } - log(level, area, where, buf); + log(level, area, where, buf, 0); va_end(args); } } diff --git a/sal/osl/unx/backtraceapi.cxx b/sal/osl/unx/backtraceapi.cxx index 267a331ae1c1..91be8d5d40c4 100644 --- a/sal/osl/unx/backtraceapi.cxx +++ b/sal/osl/unx/backtraceapi.cxx @@ -11,11 +11,13 @@ #include <cassert> #include <cstdlib> +#include <limits> #include <memory> #include <o3tl/runtimetooustring.hxx> #include <rtl/ustrbuf.hxx> #include <rtl/ustring.hxx> +#include <sal/types.h> #include "backtrace.h" #include "backtraceasstring.hxx" @@ -32,14 +34,15 @@ struct FreeGuard { } -OUString osl::detail::backtraceAsString(int maxNoStackFramesToDisplay) -{ - assert(maxNoStackFramesToDisplay >= 0); - if (maxNoStackFramesToDisplay == 0) { - return OUString(); +OUString osl::detail::backtraceAsString(sal_uInt32 maxDepth) { + assert(maxDepth != 0); + auto const maxInt = static_cast<unsigned int>( + std::numeric_limits<int>::max()); + if (maxDepth > maxInt) { + maxDepth = static_cast<sal_uInt32>(maxInt); } - auto b1 = std::unique_ptr<void *[]>(new void *[maxNoStackFramesToDisplay]); - int n = backtrace(b1.get(), maxNoStackFramesToDisplay); + auto b1 = std::unique_ptr<void *[]>(new void *[maxDepth]); + int n = backtrace(b1.get(), static_cast<int>(maxDepth)); FreeGuard b2(backtrace_symbols(b1.get(), n)); b1.reset(); if (b2.buffer == nullptr) { diff --git a/sal/osl/w32/backtrace.cxx b/sal/osl/w32/backtrace.cxx index 78d9e0aed9e5..b559c5e87fc0 100644 --- a/sal/osl/w32/backtrace.cxx +++ b/sal/osl/w32/backtrace.cxx @@ -9,7 +9,8 @@ #include <sal/config.h> -#include "backtraceasstring.hxx" +#include <limits> +#include <memory> #include <windows.h> #include <process.h> @@ -18,17 +19,29 @@ #include <DbgHelp.h> #include <rtl/ustrbuf.hxx> -#include <memory> -OUString osl::detail::backtraceAsString(int maxNoStackFramesToDisplay) +#include "backtraceasstring.hxx" + +OUString osl::detail::backtraceAsString(sal_uInt32 maxDepth) { + assert(maxDepth != 0); + auto const maxUlong = std::numeric_limits<ULONG>::max(); + if (maxDepth > maxUlong) { + maxDepth = static_cast<sal_uInt32>(maxUlong); + } + OUStringBuffer aBuf; HANDLE hProcess = GetCurrentProcess(); SymInitialize( hProcess, nullptr, true ); - std::unique_ptr<void*[]> aStack(new void*[ maxNoStackFramesToDisplay ]); - sal_uInt32 nFrames = CaptureStackBackTrace( 0, maxNoStackFramesToDisplay, aStack.get(), nullptr ); + std::unique_ptr<void*[]> aStack(new void*[ maxDepth ]); + // <https://msdn.microsoft.com/en-us/library/windows/desktop/ + // bb204633(v=vs.85).aspx> "CaptureStackBackTrace function" claims that you + // "can capture up to MAXUSHORT frames", and on Windows Server 2003 and + // Windows XP it even "must be less than 63", but assume that a too large + // input value is clamped internally, instead of resulting in an error: + sal_uInt32 nFrames = CaptureStackBackTrace( 0, static_cast<ULONG>(maxDepth), aStack.get(), nullptr ); SYMBOL_INFO * pSymbol; pSymbol = static_cast<SYMBOL_INFO *>(calloc( sizeof( SYMBOL_INFO ) + 1024 * sizeof( char ), 1 )); |