os/kernelhwsrv/kernel/eka/drivers/debug/smdebug/d_sm_process.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/drivers/debug/smdebug/d_sm_process.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,153 @@
     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 +// Responsible for dealing with process lists in the SM framework
    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 process 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::GetProcessList(const TListItem* aItem, bool aCheckConsistent)
    1.40 +	{
    1.41 +	Kern::Printf("\nDumping the process list");
    1.42 +
    1.43 +	if(aItem->iListScope != EScopeGlobal)
    1.44 +		{
    1.45 +		return KErrArgument; //No other scope makes sense for process list
    1.46 +		}
    1.47 +
    1.48 +	//Check that the process obj con lock is ok if required
    1.49 +	DObjectCon* objCon = Kern::Containers()[EProcess];
    1.50 +
    1.51 +	if(aCheckConsistent && objCon->Lock()->iHoldCount)
    1.52 +		{
    1.53 +		return KErrNotReady;
    1.54 +		}
    1.55 +
    1.56 +	//Look at the buffer
    1.57 +	TUint8* buffer = (TUint8*)aItem->iBufferAddress;
    1.58 +	TUint8* bufferPos = Align4(buffer + sizeof(TListReturn));
    1.59 +	TUint8* bufferEnd = buffer + aItem->iBufferSize;
    1.60 +
    1.61 +	TListReturn* listResp = (TListReturn*)buffer;	
    1.62 +	listResp->iReqNo = EProcess;
    1.63 +	listResp->iNumberItems = 0;
    1.64 +	listResp->iDataSize = 0;
    1.65 +
    1.66 +	DProcess** firstProcess = (DProcess**)objCon->iObjects;
    1.67 +
    1.68 +	TInt numProcesses = objCon->Count();
    1.69 +	for(TInt cnt = 0; cnt < numProcesses; cnt++)
    1.70 +		{
    1.71 +		//Get process and see if we want to list it
    1.72 +		DProcess* proc = firstProcess[cnt];
    1.73 +		if(proc && (proc->iId >= aItem->iStartElement) )
    1.74 +			{
    1.75 +			TUint32 sizeOfProc = 0;
    1.76 +			TInt err = AppendProcessToBuffer(proc, bufferPos, bufferEnd, sizeOfProc);
    1.77 +			if(KErrNone != err)
    1.78 +				{
    1.79 +				return err;
    1.80 +				}
    1.81 +			++(listResp->iNumberItems);
    1.82 +			listResp->iDataSize += sizeOfProc;
    1.83 +			bufferPos += sizeOfProc;
    1.84 +			}
    1.85 +		}
    1.86 +
    1.87 +	return KErrNone;
    1.88 +	}
    1.89 +
    1.90 +/**
    1.91 + * Writes the required process details to the stop mode response buffer in the form of a 
    1.92 + * TProcessListEntry structure
    1.93 + * @param aProc Process to write
    1.94 + * @param aBuffer Buffer to write to
    1.95 + * @param aBufferEnd Where the buffer ends
    1.96 + * @return TInt KErrTooBig if there is no more space in buffer or one of the other system wide error codes
    1.97 + */
    1.98 +TInt StopModeDebug::AppendProcessToBuffer(DProcess* aProc, TUint8* aBuffer, TUint8* aBufferEnd, TUint32& aProcSize)
    1.99 +	{
   1.100 +	TFullName procName;
   1.101 +	GetObjectFullName(aProc, procName);
   1.102 +	TUint32	dynamicNameLength = procName.Length();
   1.103 +
   1.104 +	DCodeSeg* codeSeg = aProc->iCodeSeg;
   1.105 +	TUint16 fileNameLength = (codeSeg) ? (*codeSeg->iFileName).Length() : 0;
   1.106 +
   1.107 +	//Struct size is unicode so the filenames are twice as long, plus the size of the struct minus one character that 
   1.108 +	//lives inside the struct itself. Also, this is word aligned
   1.109 +	TUint32 structSize = Align4( (2*fileNameLength) + (2*dynamicNameLength) + sizeof(TProcessListEntry) - sizeof(TUint16));
   1.110 +	aProcSize = structSize;
   1.111 +
   1.112 +	//Is there space to write this to the buffer
   1.113 +	if(aBuffer + structSize < aBufferEnd)
   1.114 +		{
   1.115 +		TProcessListEntry& entry = *(TProcessListEntry*)(aBuffer);
   1.116 +
   1.117 +		entry.iProcessId = (TUint64)aProc->iId;
   1.118 +		entry.iFileNameLength = fileNameLength;
   1.119 +		entry.iDynamicNameLength = dynamicNameLength;
   1.120 +		entry.iUid3 = aProc->iUids.iUid[2].iUid;
   1.121 +		entry.iAttributes = aProc->iAttributes;
   1.122 +
   1.123 +		//Write the filename
   1.124 +		if(codeSeg)
   1.125 +			{
   1.126 +			//create TPtr to where the file name should be written
   1.127 +			TPtr name = TPtr((TUint8*)&(entry.iNames[0]), fileNameLength*2, fileNameLength*2);
   1.128 +
   1.129 +			//copy the file name
   1.130 +			TInt err = CopyAndExpandDes(*codeSeg->iFileName, name);
   1.131 +			if(KErrNone != err)
   1.132 +				{
   1.133 +				return KErrGeneral;
   1.134 +				}
   1.135 +			}
   1.136 +
   1.137 +		//create TPtr to where the dynamic name should be written
   1.138 +		TPtr name = TPtr((TUint8*)(&(entry.iNames[0]) + fileNameLength), dynamicNameLength*2, dynamicNameLength*2);
   1.139 +
   1.140 +		//copy the dynamic name
   1.141 +		TInt err = CopyAndExpandDes(procName, name);
   1.142 +		if(KErrNone != err)
   1.143 +			{
   1.144 +			return KErrGeneral;
   1.145 +			}	
   1.146 +
   1.147 +		return KErrNone;
   1.148 +		}
   1.149 +	else
   1.150 +		{
   1.151 +		return KErrTooBig;
   1.152 +		}
   1.153 +	}
   1.154 +
   1.155 +#endif
   1.156 +