os/kernelhwsrv/kernel/eka/include/drivers/rm_debug_driver.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/include/drivers/rm_debug_driver.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,197 @@
     1.4 +// Copyright (c) 2004-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 +//
    1.18 +
    1.19 +
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalTechnology
    1.24 + @released
    1.25 +*/
    1.26 +
    1.27 +#ifndef __RM_DEBUG_DRIVER_H__
    1.28 +#define __RM_DEBUG_DRIVER_H__
    1.29 +
    1.30 +#include "d_rmd_stepping.h"
    1.31 +#include "d_rmd_breakpoints.h"
    1.32 +#include "d_driver_event_info.h"
    1.33 +
    1.34 +// From mmboot.h header
    1.35 +const TLinAddr	KDataSectionEnd			=0x40000000u;
    1.36 +const TLinAddr	KRomLinearBase			=0xF8000000u;
    1.37 +
    1.38 +
    1.39 +#define ROM_LINEAR_BASE KRomLinearBase
    1.40 +
    1.41 +// Result checking
    1.42 +#define ReturnIfError(x) { TInt y = x; if (KErrNone != y) return y; }
    1.43 +
    1.44 +//
    1.45 +// class DRM_DebugDriverFactory
    1.46 +//
    1.47 +class DRM_DebugDriverFactory : public DLogicalDevice
    1.48 +{
    1.49 +public:
    1.50 +
    1.51 +	DRM_DebugDriverFactory();
    1.52 +	virtual TInt Install();
    1.53 +	virtual void GetCaps(TDes8& aDes) const;
    1.54 +	virtual TInt Create(DLogicalChannelBase*& aChannel);
    1.55 +};
    1.56 +
    1.57 +class DRM_DebugEventHandler;
    1.58 +//
    1.59 +// DRM_DebugChannel
    1.60 +//
    1.61 +class DRM_DebugChannel : public DLogicalChannel
    1.62 +{
    1.63 +public:
    1.64 +
    1.65 +	DRM_DebugChannel(DLogicalDevice* aLogicalDevice);
    1.66 +	~DRM_DebugChannel();
    1.67 +
    1.68 +	virtual TInt DoCreate(TInt aUnit, const TDesC* anInfo, const TVersion& aVer);	
    1.69 +	virtual void HandleMsg(TMessageBase* aMsg);
    1.70 +	virtual TInt SendMsg(TMessageBase* aMsg);
    1.71 +	TInt SendRequest(TMessageBase* aMsg);
    1.72 +	
    1.73 +	//called from the event handler
    1.74 +	TBool RemoveProcess(TAny* a1, TAny* a2);
    1.75 +	TBool StartThread(TAny* a1, TAny* a2);
    1.76 +	TBool AddLibrary(TAny* a1, TAny* a2);
    1.77 +	TBool RemoveLibrary(TAny* a1, TAny* a2);
    1.78 +	TBool HandleEventKillThread(TAny* a1, TAny* a2);
    1.79 +	TBool HandleSwException(TAny* a1, TAny* a2);
    1.80 +	TBool HandleHwException(TAny* a1, TAny* a2);
    1.81 +	TBool HandleUserTrace(TAny* a1, TAny* a2);
    1.82 +	TBool HandleUnsupportedEvent(TAny* a1, TAny* a2) { return EFalse; }
    1.83 +	TBool HandleAddProcessEvent(TAny* a1, TAny* a2);
    1.84 +	TBool HandleRemoveProcessEvent(TAny* a1, TAny* a2);
    1.85 +	
    1.86 +	// Used to be able to signal events to the DSS
    1.87 +	DThread* ClientThread(void) {return iClientThread; };
    1.88 +	
    1.89 +protected:
    1.90 +	virtual void DoCancel(TInt aReqNo);
    1.91 +	virtual void DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
    1.92 +	virtual TInt DoControl(TInt aFunction, TAny *a1, TAny *a2);
    1.93 +	
    1.94 +private:
    1.95 +	TInt PreAsyncGetValue(Debug::TEventInfo* aValue, TRequestStatus* aStatus);
    1.96 +	TInt CreateDfcQ();
    1.97 +	void DestroyDfcQ();
    1.98 +	TBool HandleInvalidOpCodeException(TDriverEventInfo& aEventInfo, DThread* aCurrentThread);
    1.99 +
   1.100 +	TInt SetBreak(TSetBreakInfo* aBreakInfo);
   1.101 +	TInt StepRange(DThread* aThread, TRM_DebugStepInfo* aStepInfo);
   1.102 +	TInt ReadMemory(DThread* aThread, TRM_DebugMemoryInfo* aMemoryInfo);
   1.103 +	TInt WriteMemory(DThread* aThread, TRM_DebugMemoryInfo* aMemoryInfo);
   1.104 +	TInt ReadRegistersLegacy(DThread* aThread, TRM_DebugRegisterInfo* aRegisterInfo);
   1.105 +	TInt WriteRegistersLegacy(DThread* aThread, const TRM_DebugRegisterInfo* aRegisterInfo);
   1.106 +	TInt ReadRegisters(DThread* aThread, TRM_DebugRegisterInformation* aRegisterInfo) const;
   1.107 +	TInt WriteRegisters(DThread* aThread, TRM_DebugRegisterInformation* aRegisterInfo) const;
   1.108 +	TInt GetProcessInfo(TInt aIndex, TRM_DebugTaskInfo* aTaskInfo);
   1.109 +	TInt GetThreadInfo(TInt aIndex, TRM_DebugTaskInfo* aTaskInfo);
   1.110 +	TInt GetList(TListInformation* aListInformation) const;
   1.111 +	
   1.112 +	TInt Step(const TUint32 aThreadId, const TUint32 aNumSteps);
   1.113 +	TInt KillProcess(const TUint32 aProcessId, const TInt aReason);
   1.114 +
   1.115 +	//Crash Flash	
   1.116 +	TInt ReadCrashLog(TFlashInfo* aBuffer);
   1.117 +	TInt WriteCrashLog(TFlashInfo* aBuffer) const;
   1.118 +	TInt EraseCrashLog();
   1.119 +
   1.120 +	// Stop/go
   1.121 +	TInt DoSuspendThread(DThread *aThread);
   1.122 +	TInt DoResumeThread(DThread *aThread);
   1.123 +	TInt DoStepRange(DThread *aThread, const TUint32 aStartAddress, const TUint32 aStopAddress, TBool aStepInto, TBool aResumeOnceOutOfRange, const TUint32 aNumSteps, TBool aUserRequest = EFalse);
   1.124 +	TInt DoReadMemory(const DThread *aThread, const TUint32 aAddress, const TUint32 aLength, TDes8 &aData) const;
   1.125 +	TInt DoWriteMemory(DThread *aThread, const TUint32 aAddress, const TUint32 aLength, TDes8 &aData);
   1.126 +	TInt DoReadRegisters(DThread *aThread, const TInt16 aFirstRegister, const TInt16 aLastRegister, TDes8 &aValues);
   1.127 +	TInt DoReadRegisters(DThread *aThread, const TDesC8 &aRegisterIds, TDes8 &aRegisterValues, TDes8 &aRegisterFlags) const;
   1.128 +	TInt DoWriteRegisters(DThread *aThread, const TInt16 aFirstRegister, const TInt16 aLastRegister, TDesC8 &aValues);
   1.129 +	TInt DoWriteRegisters(DThread *aThread, const TDesC8 &aRegisterIds, TDesC8 &aRegisterValues, TDes8 &aRegisterFlags) const;
   1.130 +	TInt DoGetProcessInfo(const TInt aIndex, TRM_DebugTaskInfo *aInfo);
   1.131 +	TInt DoGetThreadInfo(const TInt aIndex, TRM_DebugTaskInfo *aInfo);
   1.132 +	TBool DoSecurityCheck();
   1.133 +
   1.134 +	TInt TryToReadMemory(const DThread *aThread, const TAny *aSrc, TAny *aDest, const TUint32 aLength) const;
   1.135 +	TInt TryToWriteMemory(const DThread *aThread, TAny *aDest, const TAny *aSrc, const TUint32 aLength);
   1.136 +	TInt32 ReadRegister(DThread *aThread, TInt aNum);
   1.137 +	TInt32 ReadDebugRegisterValue(DThread *aThread, const Debug::TRegisterInfo aDebugRegisterId, T4ByteRegisterValue &aValue) const;
   1.138 +	TInt32 ReadKernelRegisterValue(DThread *aThread, const TArmReg aKernelRegisterId, T4ByteRegisterValue &aValue) const;
   1.139 +	
   1.140 +	void NotifyEvent(const TDriverEventInfo& aEventInfo);
   1.141 +
   1.142 +	TInt GetTRegisterInfo(const TDesC8 &aRegisterIds, const TUint aIndex, Debug::TRegisterInfo &aValue) const;
   1.143 +	TInt GetDebugRegisterId(const TArmReg aKernelRegister, Debug::TRegisterInfo& aDebugRegister) const;
   1.144 +	TInt GetKernelRegisterId(const Debug::TRegisterInfo aDebugRegister, TArmReg& aKernelRegister) const;
   1.145 +	TBool GetFlagAtOffset(const TUint32 aFlags, const TArmReg aIndex) const;
   1.146 +
   1.147 +	TInt AllocAndReadDes(DThread *aThread, const TDesC8& aSrcDes, TPtr8& aDestDes, const TBool aReadFromClient=ETrue, const TUint aOffset=0) const;
   1.148 +
   1.149 +	TInt AttachProcess(TAny* a1, TAny* a2);
   1.150 +	TInt DetachProcess(TAny* a1, TAny* a2);
   1.151 +	TInt DetachAgent(TAny* a1, TAny* a2);
   1.152 +	TInt SetEventAction(TAny* a1, TAny* a2);
   1.153 +	TBool CheckSuspended(const DThread *aThread) const;
   1.154 +
   1.155 +	// Needed so moved functions can access iBreakpoint list and related functions
   1.156 +	friend class D_RMD_Breakpoints;
   1.157 +	// Needed so moved functions can access stepping functionality
   1.158 +	friend class DRMDStepping;
   1.159 +
   1.160 +	// helper function was previously in rm_debug_kerneldriver.cpp
   1.161 +	inline TInt Bitcount(TUint32 val)
   1.162 +		{
   1.163 +			TInt nbits;
   1.164 +
   1.165 +			for (nbits = 0; val != 0; nbits++)
   1.166 +			{
   1.167 +				val &= val - 1;		// delete rightmost 1-bit in val
   1.168 +			}
   1.169 +			
   1.170 +			return nbits;
   1.171 +		}
   1.172 +
   1.173 +	// Security critical - this returns whether the specified process is debuggable or not
   1.174 +	TInt IsDebuggable(const TUint32 aProcessId);
   1.175 +
   1.176 +private:
   1.177 +	DThread* iClientThread;
   1.178 +	DRM_DebugEventHandler* iEventHandler;
   1.179 +	
   1.180 +	TUint32 iExcludedROMAddressStart;
   1.181 +	TUint32 iExcludedROMAddressEnd;
   1.182 +	
   1.183 +	TUint32 iPageSize;
   1.184 +	
   1.185 +	RArray<Debug::TProcessInfo> iDebugProcessList; //processes that we are debugging
   1.186 +
   1.187 +	D_RMD_Breakpoints* iBreakManager;	// new D_RMD_Breakpoints
   1.188 +
   1.189 +	DRMDStepping* iStepper;				// new DRMDStepping
   1.190 +
   1.191 +	DSemaphore* iStepLock;				// Synchronisation for stepping code.
   1.192 +
   1.193 +	TDynamicDfcQue* iDfcQ;
   1.194 +
   1.195 +	TBool	iInitialisedCodeModifier;	// Ensures we control its lifetime
   1.196 +
   1.197 +	TClientDataRequest<Debug::TEventInfo>* iAsyncGetValueRequest;
   1.198 +};
   1.199 +
   1.200 +#endif //__RM_DEBUG_DRIVER_H__