1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/drivers/debug/smdebug/d_sm_codeseg.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,188 @@
1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Stop-mode debug interface implementation as defined in sm_debug_api.h
1.18 +//
1.19 +
1.20 +/**
1.21 + * @file
1.22 + * @internalComponent
1.23 + * @prototype
1.24 +*/
1.25 +
1.26 +#ifdef __LAUNCH_AS_EXTENSION__
1.27 +
1.28 +#include <rm_debug_api.h>
1.29 +#include <sm_debug_api.h>
1.30 +#include "d_rmd_breakpoints.h"
1.31 +
1.32 +using namespace Debug;
1.33 +
1.34 +/**
1.35 + * Stop Mode routine to retrieve the code seg list and place it in the response buffer
1.36 + * @param aItem List item describing the list
1.37 + * @return One of the system wide error codes
1.38 + */
1.39 +TInt StopModeDebug::GetCodeSegList(const TListItem* aItem, bool aCheckConsistent)
1.40 + {
1.41 + if(aCheckConsistent)
1.42 + {
1.43 + DMutex* codeMutex = Kern::CodeSegLock();
1.44 + if(!codeMutex || codeMutex->iHoldCount)
1.45 + {
1.46 + return ExitPoint(KErrNotReady);
1.47 + }
1.48 + }
1.49 +
1.50 + TUint8* bufferInitial = (TUint8*)aItem->iBufferAddress;
1.51 + TUint8* buffer = (TUint8*)aItem->iBufferAddress + 12;
1.52 + TUint32 bufferSize = aItem->iBufferSize;
1.53 +
1.54 + TUint32* buffer32 = (TUint32*)aItem->iBufferAddress;
1.55 + *buffer32 = (TUint32)aItem;
1.56 + TUint32* size = buffer32+1;
1.57 + *size = 12;
1.58 + TUint32* nextElementSize = buffer32+2;
1.59 + *nextElementSize = 0;
1.60 + TUint32 start = aItem->iStartElement;
1.61 +
1.62 + while(1)
1.63 + {
1.64 + DEpocCodeSeg* codeSeg = GetNextCodeSeg(start, aItem->iListScope, aItem->iScopeData);
1.65 + if(!codeSeg)
1.66 + {
1.67 + *size = buffer-bufferInitial;
1.68 + return KErrNone; // we're done
1.69 + }
1.70 + start = (TUint32)codeSeg + 1;
1.71 +
1.72 + TInt ret = ProcessCodeSeg(buffer, bufferSize, codeSeg);
1.73 + if(KErrNone != ret)
1.74 + {
1.75 + if(ret > 0)
1.76 + {
1.77 + Kern::Printf("Next element is %d bytes big\n", ret);
1.78 + *nextElementSize = ret;
1.79 + ret = KErrTooBig;
1.80 + }
1.81 + *size = buffer-bufferInitial;
1.82 + return ret;
1.83 + }
1.84 + }
1.85 + }
1.86 +
1.87 +DEpocCodeSeg* StopModeDebug::GetNextCodeSeg(const TUint32 aStart, const TListScope aListScope, const TUint64 aScopeData)
1.88 + {
1.89 + switch(aListScope)
1.90 + {
1.91 + case EScopeGlobal:
1.92 + return GetNextGlobalCodeSeg(aStart);
1.93 + case EScopeThreadSpecific:
1.94 + return GetNextThreadSpecificCodeSeg(aStart, aScopeData);
1.95 + default:
1.96 + return NULL;
1.97 + }
1.98 + }
1.99 +
1.100 +DEpocCodeSeg* StopModeDebug::GetNextThreadSpecificCodeSeg(const TUint32 aStart, const TUint64 aThreadId)
1.101 + {
1.102 + return NULL;
1.103 + }
1.104 +
1.105 +DEpocCodeSeg* StopModeDebug::GetNextGlobalCodeSeg(const TUint32 aStart)
1.106 + {
1.107 + //get global code seg list
1.108 + SDblQue* codeSegList = Kern::CodeSegList();
1.109 +
1.110 + DEpocCodeSeg* codeSeg = NULL;
1.111 + for (SDblQueLink* codeSegPtr= codeSegList->First(); codeSegPtr!=(SDblQueLink*) (codeSegList); codeSegPtr=codeSegPtr->iNext)
1.112 + {
1.113 + DEpocCodeSeg* tempCodeSeg = (DEpocCodeSeg*)_LOFF(codeSegPtr,DCodeSeg, iLink);
1.114 + if((TUint32)tempCodeSeg >= aStart)
1.115 + {
1.116 + if(!codeSeg || tempCodeSeg < codeSeg)
1.117 + {
1.118 + codeSeg = tempCodeSeg;
1.119 + }
1.120 + }
1.121 + }
1.122 + return codeSeg;
1.123 + }
1.124 +
1.125 +TInt StopModeDebug::ProcessCodeSeg(TUint8*& aBuffer, TUint32& aBufferSize, DEpocCodeSeg* aCodeSeg)
1.126 + {
1.127 + //create a memory info object for use in the loop
1.128 + TModuleMemoryInfo memoryInfo;
1.129 +
1.130 + //get the memory info
1.131 + TInt err = aCodeSeg->GetMemoryInfo(memoryInfo, NULL);
1.132 + if(err != KErrNone)
1.133 + {
1.134 + //there's been an error so return it
1.135 + return err;
1.136 + }
1.137 + //calculate data values
1.138 + TFileName fileName(aCodeSeg->iFileName->Ptr());
1.139 + TBool isXip = (aCodeSeg->iXIP) ? ETrue : EFalse;
1.140 +
1.141 + //get the code seg type
1.142 + TCodeSegType type =
1.143 + aCodeSeg->IsExe() ? EExeCodeSegType :
1.144 + aCodeSeg->IsDll() ? EDllCodeSegType :
1.145 + EUnknownCodeSegType;
1.146 +
1.147 + //append data to buffer
1.148 + return AppendCodeSegData(aBuffer, aBufferSize, memoryInfo, isXip, type, fileName, aCodeSeg);
1.149 + }
1.150 +
1.151 +TInt StopModeDebug::AppendCodeSegData(TUint8*& aBuffer, TUint32& aBufferSize, const TModuleMemoryInfo& aMemoryInfo, const TBool aIsXip, const TCodeSegType aCodeSegType, const TDesC8& aFileName, DEpocCodeSeg* aCodeSeg)
1.152 + {
1.153 + //get some data elements to put in buffer
1.154 + TUint16 fileNameLength = aFileName.Length();
1.155 +
1.156 + //calculate the resultant size
1.157 + TUint dataSize = Align4(sizeof(TCodeSegListEntry) + (2*fileNameLength) - sizeof(TUint16));
1.158 + if(dataSize > aBufferSize)
1.159 + {
1.160 + // data won't fit in the buffer so quit
1.161 + return dataSize;
1.162 + }
1.163 + //Create a TCodeSegListEntry which references the buffer.
1.164 + TCodeSegListEntry& entry = *(TCodeSegListEntry*)aBuffer;
1.165 + entry.iCodeBase = aMemoryInfo.iCodeBase;
1.166 + entry.iCodeSize = aMemoryInfo.iCodeSize;
1.167 + entry.iConstDataSize = aMemoryInfo.iConstDataSize;
1.168 + entry.iInitialisedDataBase = aMemoryInfo.iInitialisedDataBase;
1.169 + entry.iInitialisedDataSize = aMemoryInfo.iInitialisedDataSize;
1.170 + entry.iUninitialisedDataSize = aMemoryInfo.iUninitialisedDataSize;
1.171 + entry.iIsXip = aIsXip;
1.172 + entry.iCodeSegType = aCodeSegType;
1.173 + entry.iNameLength = fileNameLength;
1.174 + //entry.iSpare1 = (TUint32)aCodeSeg;
1.175 +
1.176 + //have to convert the stored name to 16 bit Unicode
1.177 + TPtr name = TPtr((TUint8*)&(entry.iName[0]), fileNameLength*2, fileNameLength*2);
1.178 + TInt err = CopyAndExpandDes(aFileName, name);
1.179 + if(err != KErrNone)
1.180 + {
1.181 + return KErrGeneral;
1.182 + }
1.183 +
1.184 + //increase length
1.185 + aBufferSize-=dataSize;
1.186 + aBuffer+=dataSize;
1.187 + return KErrNone;
1.188 + }
1.189 +
1.190 +#endif
1.191 +