Kaydet (Commit) 94427a1b authored tarafından Michael Meeks's avatar Michael Meeks

sal: add SAL_DEBUG_TRACE debugging API for Windows, with UNX stub.

Change-Id: I2fdbc2ac10f483eee154bdf69479ba217a91ef7f
Reviewed-on: https://gerrit.libreoffice.org/19605Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 08e5fc25
......@@ -52,6 +52,7 @@ 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
};
......
......@@ -316,6 +316,18 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
SAL_DETAIL_LOG_STREAM( \
SAL_LOG_TRUE, ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, stream)
/**
Produce temporary debugging output from stream along with a
stack trace of the calling location. This macro is meant to
be used only while working on code and should never exist
in production code.
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)
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -48,6 +48,7 @@ $(eval $(call gb_Library_use_externals,sal,\
$(eval $(call gb_Library_use_system_win32_libs,sal,\
advapi32 \
comdlg32 \
dbghelp \
mpr \
ole32 \
shell32 \
......@@ -146,6 +147,7 @@ endif
ifneq ($(OS),WNT)
$(eval $(call gb_Library_add_exception_objects,sal,\
sal/osl/unx/backtraceapi \
sal/osl/unx/conditn \
sal/osl/unx/file \
sal/osl/unx/file_error_transl \
......@@ -215,6 +217,7 @@ else # $(OS) == WNT
# .ENDIF
$(eval $(call gb_Library_add_exception_objects,sal,\
sal/osl/w32/backtrace \
sal/osl/w32/file \
sal/osl/w32/file_dirvol \
sal/osl/w32/file_url \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SAL_INC_INTERNAL_MISC_H
#define INCLUDED_SAL_INC_INTERNAL_MISC_H
#include <rtl/ustring.hxx>
/// Build a debugging backtrace from current PC location.
rtl_uString *osl_backtraceAsString(void);
#endif // INCLUDED_SAL_INC_INTERNAL_MISC_H
......@@ -25,6 +25,7 @@
#include "sal/detail/log.h"
#include "sal/log.hxx"
#include "sal/types.h"
#include "internal/misc.hxx"
#include "logformat.hxx"
......@@ -70,6 +71,7 @@ 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";
}
}
......@@ -199,7 +201,14 @@ void log(
+ (std::strncmp(where, SRCDIR "/", nStrLen) == 0
? nStrLen : 0));
}
s << message << '\n';
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
int android_log_level;
switch (level) {
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <rtl/ustrbuf.hxx>
#include "internal/misc.hxx"
// FIXME: no-op for now; it needs implementing, cf. above.
rtl_uString *osl_backtraceAsString()
{
OUStringBuffer aBuf;
OUString aStr = aBuf.makeStringAndClear();
rtl_uString_acquire( aStr.pData );
return aStr.pData;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "internal/misc.hxx"
#include <windows.h>
#include <process.h>
#include <iostream>
#define OPTIONAL
#include <DbgHelp.h>
// No-op for now; it needs implementing.
rtl_uString *osl_backtraceAsString()
{
OUStringBuffer aBuf;
HANDLE hProcess = GetCurrentProcess();
SymInitialize( hProcess, NULL, true );
void * aStack[ 512 ];
sal_uInt32 nFrames = CaptureStackBackTrace( 0, 512, aStack, NULL );
SYMBOL_INFO * pSymbol;
pSymbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 1024 * sizeof( char ), 1 );
pSymbol->MaxNameLen = 1024 - 1;
pSymbol->SizeOfStruct = sizeof( SYMBOL_INFO );
for( sal_uInt32 i = 0; i < nFrames; i++ )
{
SymFromAddr( hProcess, ( DWORD64 )aStack[ i ], 0, pSymbol );
aBuf.append( (sal_Int32)(nFrames - i - 1) );
aBuf.append( ": " );
aBuf.appendAscii( pSymbol->Name );
aBuf.append( " - 0x" );
aBuf.append( (sal_Int64)pSymbol->Address, 16 );
aBuf.append( "\n" );
}
free( pSymbol );
OUString aStr = aBuf.makeStringAndClear();
rtl_uString_acquire( aStr.pData );
return aStr.pData;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment