diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-10-26 14:13:10 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-12-02 16:47:16 +0000 |
commit | 94427a1b000344b24948374953a099571901a2ed (patch) | |
tree | e5a7551267810f07c884f276b47991109bd118c8 /sal/osl/w32 | |
parent | 08e5fc257fa8c106be34bb034ebe5e00b6fcf711 (diff) |
sal: add SAL_DEBUG_TRACE debugging API for Windows, with UNX stub.
Change-Id: I2fdbc2ac10f483eee154bdf69479ba217a91ef7f
Reviewed-on: https://gerrit.libreoffice.org/19605
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'sal/osl/w32')
-rw-r--r-- | sal/osl/w32/backtrace.cxx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/sal/osl/w32/backtrace.cxx b/sal/osl/w32/backtrace.cxx new file mode 100644 index 000000000000..80f0856e9e12 --- /dev/null +++ b/sal/osl/w32/backtrace.cxx @@ -0,0 +1,52 @@ +/* -*- 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: */ |