summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-02-09 13:19:11 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-02-09 15:56:50 +0000
commitb6a69585b00867005820c1dd94e10e0e6b545e2a (patch)
tree39c76e48dffcfbadd619cf7dc52bb9def0f85691 /sal
parent6851074c8a515ec5a7856d4b744e3425c8829a29 (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')
-rw-r--r--sal/inc/backtraceasstring.hxx3
-rw-r--r--sal/osl/all/log.cxx29
-rw-r--r--sal/osl/unx/backtraceapi.cxx17
-rw-r--r--sal/osl/w32/backtrace.cxx23
-rw-r--r--sal/util/sal.map1
5 files changed, 37 insertions, 36 deletions
diff --git a/sal/inc/backtraceasstring.hxx b/sal/inc/backtraceasstring.hxx
index d15065a48ce8..cd9ce494f789 100644
--- a/sal/inc/backtraceasstring.hxx
+++ b/sal/inc/backtraceasstring.hxx
@@ -13,11 +13,12 @@
#include <sal/config.h>
#include <rtl/ustring.hxx>
+#include <sal/types.h>
namespace osl { namespace detail {
/// Build a debugging backtrace from current PC location.
-OUString backtraceAsString(int maxNoStackFramesToDisplay);
+OUString backtraceAsString(sal_uInt32 maxDepth);
} }
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 ));
diff --git a/sal/util/sal.map b/sal/util/sal.map
index b99d5241a7dd..b04487e4d548 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -730,7 +730,6 @@ PRIVATE_1.2 { # LibreOffice 3.5
PRIVATE_1.3 { # LibreOffice 5.4
global:
- sal_detail_log_backtrace;
sal_detail_log_report;
} PRIVATE_1.2;