[PATCH] Remove DBG_TRACE_BASIC, DBG_SAVE_DISASSEMBLY and sbtrace.hxx

Thomas Arnhold thomas at arnhold.org
Mon Jan 31 00:52:51 PST 2011


---
 basic/source/classes/disas.cxx   |   13 --
 basic/source/classes/sbxmod.cxx  |   22 ---
 basic/source/comp/sbcomp.cxx     |  376 --------------------------------------
 basic/source/inc/sbtrace.hxx     |   45 -----
 basic/source/runtime/runtime.cxx |   18 --
 5 files changed, 0 insertions(+), 474 deletions(-)
 delete mode 100644 basic/source/inc/sbtrace.hxx

diff --git a/basic/source/classes/disas.cxx b/basic/source/classes/disas.cxx
index 3000391..e299717 100644
--- a/basic/source/classes/disas.cxx
+++ b/basic/source/classes/disas.cxx
@@ -36,7 +36,6 @@
 #include "sb.hxx"
 #include "iosys.hxx"
 #include "disas.hxx"
-#include "sbtrace.hxx"
 
 
 static const char* pOp1[] = {
@@ -364,10 +363,6 @@ BOOL SbiDisas::DisasLine( String& rText )
     if( !Fetch() )
         return FALSE;
 
-#ifdef DBG_TRACE_BASIC
-    String aTraceStr_STMNT;
-#endif
-
     // New line?
     if( eOp == _STMNT && nOp1 != nLine )
     {
@@ -400,10 +395,6 @@ BOOL SbiDisas::DisasLine( String& rText )
             rText.AppendAscii( "; " );
             rText += s;
             rText.AppendAscii( _crlf() );
-
-#ifdef DBG_TRACE_BASIC
-            aTraceStr_STMNT = s;
-#endif
         }
     }
 
@@ -463,10 +454,6 @@ BOOL SbiDisas::DisasLine( String& rText )
 
     rText += aPCodeStr;
 
-#ifdef DBG_TRACE_BASIC
-    dbg_RegisterTraceTextForPC( pMod, nPC, aTraceStr_STMNT, aPCodeStr );
-#endif
-
     return TRUE;
 }
 
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index c5849d7..654fa2e 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -45,7 +45,6 @@
 #include "runtime.hxx"
 #include "token.hxx"
 #include "sbunoobj.hxx"
-#include "sbtrace.hxx"
 
 #include <svtools/syntaxhighlight.hxx>
 
@@ -1121,9 +1120,6 @@ USHORT SbModule::Run( SbMethod* pMeth )
     StarBASICRef xBasic;
     if( bDelInst )
     {
-#ifdef DBG_TRACE_BASIC
-        dbg_InitTrace();
-#endif
         // #32779: Hold Basic during the execution
         xBasic = (StarBASIC*) GetParent();
 
@@ -1180,10 +1176,6 @@ USHORT SbModule::Run( SbMethod* pMeth )
             pMOD = this;
             SbiRuntime* pRt = new SbiRuntime( this, pMeth, pMeth->nStart );
 
-#ifdef DBG_TRACE_BASIC
-            dbg_traceNotifyCall( this, pMeth, pINST->nCallLvl );
-#endif
-
             pRt->pNext = pINST->pRun;
             if( pRt->pNext )
                 pRt->pNext->block();
@@ -1196,11 +1188,6 @@ USHORT SbModule::Run( SbMethod* pMeth )
             if( pRt->pNext )
                 pRt->pNext->unblock();
 
-#ifdef DBG_TRACE_BASIC
-            bool bLeave = true;
-            dbg_traceNotifyCall( this, pMeth, pINST->nCallLvl, bLeave );
-#endif
-
             // #63710 It can happen by an another thread handling at events,
             // that the show call returns to an dialog (by closing the
             // dialog per UI), before a by an event triggered further call returned,
@@ -1304,19 +1291,10 @@ void SbModule::RunInit()
         // The init code starts always here
         SbiRuntime* pRt = new SbiRuntime( this, NULL, 0 );
 
-#ifdef DBG_TRACE_BASIC
-        dbg_traceNotifyCall( this, NULL, 0 );
-#endif
-
         pRt->pNext = pINST->pRun;
         pINST->pRun = pRt;
         while( pRt->Step() ) {}
 
-#ifdef DBG_TRACE_BASIC
-        bool bLeave = true;
-        dbg_traceNotifyCall( this, NULL, 0, bLeave );
-#endif
-
         pINST->pRun = pRt->pNext;
         delete pRt;
         pMOD = pOldMod;
diff --git a/basic/source/comp/sbcomp.cxx b/basic/source/comp/sbcomp.cxx
index a9fbdeb..6b98736 100644
--- a/basic/source/comp/sbcomp.cxx
+++ b/basic/source/comp/sbcomp.cxx
@@ -32,374 +32,6 @@
 #include <basic/sbx.hxx>
 #include "sbcomp.hxx"
 #include "image.hxx"
-#include "sbtrace.hxx"
-
-
-//==========================================================================
-// Tracing, for debugging only
-
-// To activate tracing enable in sbtrace.hxx
-#ifdef DBG_TRACE_BASIC
-
-#include <hash_map>
-
-// Trace Settings
-static const char*	GpTraceFileName = "d:\\zBasic.Asm\\BasicTrace.txt";
-static const bool	GbIncludePCodes = false;
-static const int	GnIndentPerCallLevel = 4;
-static const int	GnIndentForPCode = 2;
-
-struct TraceTextData
-{
-    rtl::OString m_aTraceStr_STMNT;
-    rtl::OString m_aTraceStr_PCode;
-};
-typedef std::hash_map< sal_Int32, TraceTextData > PCToTextDataMap;
-typedef std::hash_map< ::rtl::OUString, PCToTextDataMap*, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleTraceMap;
-
-ModuleTraceMap		GaModuleTraceMap;
-ModuleTraceMap&		rModuleTraceMap = GaModuleTraceMap;
-
-static void lcl_PrepareTraceForModule( SbModule* pModule )
-{
-    String aModuleName = pModule->GetName();
-    ModuleTraceMap::iterator it = rModuleTraceMap.find( aModuleName );
-    if( it != rModuleTraceMap.end() )
-    {
-        PCToTextDataMap* pInnerMap = it->second;
-        delete pInnerMap;
-        rModuleTraceMap.erase( it );
-    }
-
-    String aDisassemblyStr;
-    pModule->Disassemble( aDisassemblyStr );
-}
-
-static void lcl_lineOut( const char* pFileName, const char* pStr, const char* pPreStr = NULL )
-{
-    const char* pPrintFirst = (pPreStr != NULL) ? pPreStr : "";
-    FILE* pFile = fopen( pFileName, "a+" );
-    if( pFile != NULL )
-    {
-        fprintf( pFile, "%s%s\n", pPrintFirst, pStr );
-        fclose( pFile );
-    }
-}
-
-const char* lcl_getSpaces( int nSpaceCount )
-{
-    static sal_Char Spaces[] = "                                                                                                    "
-        "                                                                                                    "
-        "                                                                                                    ";
-    static int nAvailableSpaceCount = strlen( Spaces );
-    static sal_Char* pSpacesEnd = Spaces + nAvailableSpaceCount;
-
-    if( nSpaceCount > nAvailableSpaceCount )
-        nSpaceCount = nAvailableSpaceCount;
-
-    return pSpacesEnd - nSpaceCount;
-}
-
-static rtl::OString lcl_toOStringSkipLeadingWhites( const String& aStr )
-{
-    static sal_Char Buffer[1000];
-
-    rtl::OString aOStr = OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US );
-    const sal_Char* pStr = aOStr.getStr();
-
-    // Skip whitespace
-    sal_Char c = *pStr;
-    while( c == ' ' || c == '\t' )
-    {
-        pStr++;
-        c = *pStr;
-    }
-
-    int nLen = strlen( pStr );
-    strncpy( Buffer, pStr, nLen );
-    Buffer[nLen] = 0;
-
-    rtl::OString aORetStr( Buffer );
-    return aORetStr;
-}
-
-String dumpMethodParameters( SbMethod* pMethod )
-{
-    String aStr;
-    if( pMethod == NULL )
-        return aStr;
-
-    SbxError eOld = SbxBase::GetError();
-
-    SbxArray* pParams = pMethod->GetParameters();
-    SbxInfo* pInfo = pMethod->GetInfo();
-    if ( pParams )
-    {
-        aStr += '(';
-        // 0 is sub itself
-        for ( USHORT nParam = 1; nParam < pParams->Count(); nParam++ )
-        {
-            SbxVariable* pVar = pParams->Get( nParam );
-            DBG_ASSERT( pVar, "Parameter?!" );
-            if ( pVar->GetName().Len() )
-                aStr += pVar->GetName();
-            else if ( pInfo )
-            {
-                const SbxParamInfo* pParam = pInfo->GetParam( nParam );
-                if ( pParam )
-                    aStr += pParam->aName;
-            }
-            aStr += '=';
-            if( pVar->GetType() & SbxARRAY )
-                aStr += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
-            else
-                aStr += pVar->GetString();
-            if ( nParam < ( pParams->Count() - 1 ) )
-                aStr += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
-        }
-        aStr += ')';
-    }
-
-    SbxBase::ResetError();
-    if( eOld != SbxERR_OK )
-        SbxBase::SetError( eOld );
-
-    return aStr;
-} 
-
-// Public functions
-void dbg_InitTrace( void )
-{
-    FILE* pFile = fopen( GpTraceFileName, "w" );
-    if( pFile != NULL )
-        fclose( pFile );
-}
-
-void dbg_traceStep( SbModule* pModule, UINT32 nPC, INT32 nCallLvl )
-{
-    SbModule* pTraceMod = pModule;
-    if( pTraceMod->ISA(SbClassModuleObject) )
-    {
-        SbClassModuleObject* pClassModuleObj = (SbClassModuleObject*)(SbxBase*)pTraceMod;
-        pTraceMod = pClassModuleObj->getClassModule();
-    }
-
-    String aModuleName = pTraceMod->GetName();
-    ModuleTraceMap::iterator it = rModuleTraceMap.find( aModuleName );
-    if( it == rModuleTraceMap.end() )
-    {
-        const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr();
-        char Buffer[200];
-        sprintf( Buffer, "TRACE ERROR: Unknown module \"%s\"", pModuleNameStr );
-        lcl_lineOut( GpTraceFileName, Buffer );
-        return;
-    }
-
-    PCToTextDataMap* pInnerMap = it->second;
-    if( pInnerMap == NULL )
-    {
-        lcl_lineOut( GpTraceFileName, "TRACE INTERNAL ERROR: No inner map" );
-        return;
-    }
-
-    PCToTextDataMap::iterator itInner = pInnerMap->find( nPC );
-    if( itInner == pInnerMap->end() )
-    {
-        const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr();
-        char Buffer[200];
-        sprintf( Buffer, "TRACE ERROR: No info for PC = %d in module \"%s\"", nPC, pModuleNameStr );
-        lcl_lineOut( GpTraceFileName, Buffer );
-        return;
-    }
-
-    //nCallLvl--;
-    //if( nCallLvl < 0 )
-    //	nCallLvl = 0;
-    int nIndent = nCallLvl * GnIndentPerCallLevel;
-
-    const TraceTextData& rTraceTextData = itInner->second;
-    const rtl::OString& rStr_STMNT = rTraceTextData.m_aTraceStr_STMNT;
-    if( rStr_STMNT.getLength() )
-        lcl_lineOut( GpTraceFileName, rStr_STMNT.getStr(), lcl_getSpaces( nIndent ) );
-
-    if( !GbIncludePCodes )
-        return;
-
-    nIndent += GnIndentForPCode;
-    const rtl::OString& rStr_PCode = rTraceTextData.m_aTraceStr_PCode;
-    if( rStr_PCode.getLength() )
-        lcl_lineOut( GpTraceFileName, rStr_PCode.getStr(), lcl_getSpaces( nIndent ) );
-}
-
-void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, INT32 nCallLvl, bool bLeave )
-{
-    static const char* pSeparator = "' ================================================================================";
-
-    SbModule* pTraceMod = pModule;
-    SbClassModuleObject* pClassModuleObj = NULL;
-    if( pTraceMod->ISA(SbClassModuleObject) )
-    {
-        pClassModuleObj = (SbClassModuleObject*)(SbxBase*)pTraceMod;
-        pTraceMod = pClassModuleObj->getClassModule();
-    }
-
-    if( nCallLvl > 0 )
-        nCallLvl--;
-    int nIndent = nCallLvl * GnIndentPerCallLevel;
-    if( !bLeave )
-    {
-        lcl_lineOut( GpTraceFileName, "" );
-        lcl_lineOut( GpTraceFileName, pSeparator, lcl_getSpaces( nIndent ) );
-    }
-
-    String aStr;
-    if( bLeave )
-    {
-        lcl_lineOut( GpTraceFileName, "}", lcl_getSpaces( nIndent ) );
-        aStr.AppendAscii( "' Leaving " );
-    }
-    else
-    {
-        aStr.AppendAscii( "Entering " );
-    }
-    String aModuleName = pTraceMod->GetName();
-    aStr += aModuleName;
-    if( pMethod != NULL )
-    {
-        aStr.AppendAscii( "::" );
-        String aMethodName = pMethod->GetName();
-        aStr += aMethodName;
-    }
-    else
-    {
-        aStr.AppendAscii( "/RunInit" );
-    }
-
-    if( pClassModuleObj != NULL )
-    {
-        aStr.AppendAscii( "[this=" );
-        aStr += pClassModuleObj->GetName();
-        aStr.AppendAscii( "]" );
-    }
-    if( !bLeave )
-        aStr += dumpMethodParameters( pMethod );
-
-    lcl_lineOut( GpTraceFileName, OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr(), lcl_getSpaces( nIndent ) );
-    if( !bLeave )
-        lcl_lineOut( GpTraceFileName, "{", lcl_getSpaces( nIndent ) );
-
-    if( bLeave )
-        lcl_lineOut( GpTraceFileName, "" );
-}
-
-void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool bTraceErrHandled, INT32 nCallLvl )
-{
-    rtl::OString aOTraceErrMsg = OUStringToOString( rtl::OUString( aTraceErrMsg ), RTL_TEXTENCODING_ASCII_US );
-
-    char Buffer[200];
-    const char* pHandledStr = bTraceErrHandled ? " / HANDLED" : "";
-    sprintf( Buffer, "*** ERROR%s, Id = %d, Msg = \"%s\" ***", pHandledStr, (int)nTraceErr, aOTraceErrMsg.getStr() );
-    int nIndent = nCallLvl * GnIndentPerCallLevel;
-    lcl_lineOut( GpTraceFileName, Buffer, lcl_getSpaces( nIndent ) );
-}
-
-void dbg_RegisterTraceTextForPC( SbModule* pModule, UINT32 nPC,
-    const String& aTraceStr_STMNT, const String& aTraceStr_PCode )
-{
-    String aModuleName = pModule->GetName();
-    ModuleTraceMap::iterator it = rModuleTraceMap.find( aModuleName );
-    PCToTextDataMap* pInnerMap;
-    if( it == rModuleTraceMap.end() )
-    {
-        pInnerMap = new PCToTextDataMap();
-        rModuleTraceMap[ aModuleName ] = pInnerMap;
-    }
-    else
-    {
-        pInnerMap = it->second;
-    }
-
-    TraceTextData aData;
-
-    rtl::OString aOTraceStr_STMNT = lcl_toOStringSkipLeadingWhites( aTraceStr_STMNT );
-    aData.m_aTraceStr_STMNT = aOTraceStr_STMNT;
-
-    rtl::OString aOTraceStr_PCode = lcl_toOStringSkipLeadingWhites( aTraceStr_PCode );
-    aData.m_aTraceStr_PCode = aOTraceStr_PCode;
-
-    (*pInnerMap)[nPC] = aData;
-}
-
-#endif
-
-
-//==========================================================================
-// For debugging only
-//#define DBG_SAVE_DISASSEMBLY
-
-#ifdef DBG_SAVE_DISASSEMBLY
-static bool dbg_bDisassemble = true;
-#include <comphelper/processfactory.hxx>
-
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
-#include <com/sun/star/io/XTextOutputStream.hpp>
-#include <com/sun/star/io/XActiveDataSource.hpp>
-
-using namespace comphelper;
-using namespace rtl;
-using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
-using namespace com::sun::star::ucb;
-using namespace com::sun::star::io;
-
-void dbg_SaveDisassembly( SbModule* pModule )
-{
-    bool bDisassemble = dbg_bDisassemble;
-    if( bDisassemble )
-    {
-        Reference< XSimpleFileAccess3 > xSFI;
-        Reference< XTextOutputStream > xTextOut;
-        Reference< XOutputStream > xOut;
-        Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
-        if( xSMgr.is() )
-        {
-            Reference< XSimpleFileAccess3 > xSFI = Reference< XSimpleFileAccess3 >( xSMgr->createInstance
-                ( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" )) ), UNO_QUERY );
-            if( xSFI.is() )
-            {
-                String aFile( RTL_CONSTASCII_USTRINGPARAM("file:///d:/zBasic.Asm/Asm_") );
-                StarBASIC* pBasic = (StarBASIC*)pModule->GetParent();
-                if( pBasic )
-                {
-                    aFile += pBasic->GetName();
-                    aFile.AppendAscii( "_" );
-                }
-                aFile += pModule->GetName();
-                aFile.AppendAscii( ".txt" );
-
-                // String aFile( RTL_CONSTASCII_USTRINGPARAM("file:///d:/BasicAsm.txt") );
-                if( xSFI->exists( aFile ) )
-                    xSFI->kill( aFile );
-                xOut = xSFI->openFileWrite( aFile );
-                Reference< XInterface > x = xSMgr->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TextOutputStream" )) );
-                Reference< XActiveDataSource > xADS( x, UNO_QUERY );
-                xADS->setOutputStream( xOut );
-                xTextOut = Reference< XTextOutputStream >( x, UNO_QUERY );
-            }
-        }
-
-        if( xTextOut.is() )
-        {
-            String aDisassemblyStr;
-            pModule->Disassemble( aDisassemblyStr );
-            xTextOut->writeString( aDisassemblyStr );
-        }
-        xOut->closeOutput();
-    }
-}
-#endif
-
 
 // Diese Routine ist hier definiert, damit der Compiler als eigenes Segment
 // geladen werden kann.
@@ -453,14 +85,6 @@ BOOL SbModule::Compile()
         }
     }
 
-#ifdef DBG_SAVE_DISASSEMBLY
-    dbg_SaveDisassembly( this );
-#endif
-
-#ifdef DBG_TRACE_BASIC
-    lcl_PrepareTraceForModule( this );
-#endif
-
     return bRet;
 }
 
diff --git a/basic/source/inc/sbtrace.hxx b/basic/source/inc/sbtrace.hxx
deleted file mode 100644
index 50625c1..0000000
--- a/basic/source/inc/sbtrace.hxx
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef _SBTRACE_HXX
-#define _SBTRACE_HXX
-
-// #define DBG_TRACE_BASIC
-
-#ifdef DBG_TRACE_BASIC
-void dbg_InitTrace( void );
-void dbg_traceStep( SbModule* pModule, UINT32 nPC, INT32 nCallLvl );
-void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, INT32 nCallLvl, bool bLeave = false );
-void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool bTraceErrHandled, INT32 nCallLvl );
-void dbg_RegisterTraceTextForPC( SbModule* pModule, UINT32 nPC,
-    const String& aTraceStr_STMNT, const String& aTraceStr_PCode );
-#endif
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index c10ef56..e8a2328 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -45,7 +45,6 @@
 #include <com/sun/star/container/XEnumerationAccess.hpp>
 #include "sbunoobj.hxx"
 #include "errobject.hxx"
-#include "sbtrace.hxx"
 
 SbxVariable* getDefaultProp( SbxVariable* pRef );
 
@@ -732,11 +731,6 @@ BOOL SbiRuntime::Step()
                 Application::Reschedule();
         }
 
-#ifdef DBG_TRACE_BASIC
-        UINT32 nPC = ( pCode - (const BYTE* )pImg->GetCode() );
-        dbg_traceStep( pMod, nPC, pINST->nCallLvl );
-#endif
-
         SbiOpcode eOp = (SbiOpcode ) ( *pCode++ );
         UINT32 nOp1, nOp2;
         if( eOp <= SbOP0_END )
@@ -773,11 +767,6 @@ BOOL SbiRuntime::Step()
         // (insbesondere nicht nach Compiler-Fehlern zur Laufzeit)
         if( nError && bRun )
         {
-#ifdef DBG_TRACE_BASIC
-            SbError nTraceErr = nError;
-            String aTraceErrMsg = GetSbData()->aErrMsg;
-            bool bTraceErrHandled = true;
-#endif
             SbError err = nError;
             ClearExprStack();
             nError = 0;
@@ -858,19 +847,12 @@ BOOL SbiRuntime::Step()
                 // Kein Error-Hdl gefunden -> altes Vorgehen
                 else
                 {
-#ifdef DBG_TRACE_BASIC
-                    bTraceErrHandled = false;
-#endif
                     pInst->Abort();
                 }
 
                 // ALT: Nur
                 // pInst->Abort();
             }
-
-#ifdef DBG_TRACE_BASIC
-            dbg_traceNotifyError( nTraceErr, aTraceErrMsg, bTraceErrHandled, pINST->nCallLvl );
-#endif
         }
     }
     return bRun;
-- 
1.7.3.5


--------------010509000101080309070109--


More information about the LibreOffice mailing list