1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/drivers/debug/rmdebug/rm_debug_eventhandler.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,165 @@
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 +// Kernel Event handler for Run Mode Debug.
1.18 +//
1.19 +
1.20 +#include <e32def.h>
1.21 +#include <e32def_private.h>
1.22 +#include <e32cmn.h>
1.23 +#include <e32cmn_private.h>
1.24 +#include <kernel/arm/arm.h>
1.25 +#include <kernel/kernel.h>
1.26 +#include <kernel/kern_priv.h>
1.27 +#include <nk_trace.h>
1.28 +
1.29 +#include <rm_debug_api.h>
1.30 +#include "debug_logging.h"
1.31 +#include "d_process_tracker.h"
1.32 +#include "d_rmd_stepping.h"
1.33 +#include "rm_debug_kerneldriver.h"
1.34 +#include "rm_debug_driver.h"
1.35 +#include "rm_debug_eventhandler.h"
1.36 +
1.37 +
1.38 +DRM_DebugEventHandler::DRM_DebugEventHandler()
1.39 + : DKernelEventHandler(EventHandler, this)
1.40 +{
1.41 + LOG_MSG("DRM_DebugEventHandler::DRM_DebugEventHandler()");
1.42 +
1.43 + for(TInt i=0; i<EEventLimit; i++)
1.44 + {
1.45 + iEventHandlers[i] = &DRM_DebugChannel::HandleUnsupportedEvent;
1.46 + }
1.47 + iEventHandlers[EEventUserTrace] = &DRM_DebugChannel::HandleUserTrace;
1.48 + iEventHandlers[EEventRemoveLibrary] = &DRM_DebugChannel::RemoveLibrary;
1.49 + iEventHandlers[EEventAddLibrary] = &DRM_DebugChannel::AddLibrary;
1.50 + iEventHandlers[EEventRemoveProcess] = &DRM_DebugChannel::RemoveProcess;
1.51 + iEventHandlers[EEventStartThread] = &DRM_DebugChannel::StartThread;
1.52 + iEventHandlers[EEventSwExc] = &DRM_DebugChannel::HandleSwException;
1.53 + iEventHandlers[EEventHwExc] = &DRM_DebugChannel::HandleHwException;
1.54 + iEventHandlers[EEventKillThread] = &DRM_DebugChannel::HandleEventKillThread;
1.55 + iEventHandlers[EEventAddProcess] = &DRM_DebugChannel::HandleAddProcessEvent;
1.56 + iEventHandlers[EEventRemoveProcess] = &DRM_DebugChannel::HandleRemoveProcessEvent;
1.57 +}
1.58 +
1.59 +TInt DRM_DebugEventHandler::Create(DLogicalDevice* aDevice, DLogicalChannel* aChannel, DThread* aClient)
1.60 +{
1.61 + LOG_MSG("DRM_DebugEventHandler::Create()");
1.62 +
1.63 + TInt err;
1.64 + err = aDevice->Open();
1.65 + if (err != KErrNone)
1.66 + return err;
1.67 + iDevice = aDevice;
1.68 +
1.69 + iChannel = (DRM_DebugChannel*)aChannel; //Don't add ref the channel, since channel closes the event handler before it ever gets destroyed.
1.70 +
1.71 + err = aClient->Open();
1.72 + if (err != KErrNone)
1.73 + return err;
1.74 + iClientThread = aClient;
1.75 +
1.76 + // Use a semaphore to protect our data structures from concurrent access.
1.77 + err = Kern::SemaphoreCreate(iLock, _L("RM_DebugEventHandlerLock"), 1 /* Initial count */);
1.78 + if (err != KErrNone)
1.79 + return err;
1.80 +
1.81 +
1.82 + return Add();
1.83 +}
1.84 +
1.85 +
1.86 +DRM_DebugEventHandler::~DRM_DebugEventHandler()
1.87 +{
1.88 + LOG_MSG("DRM_DebugEventHandler::~DRM_DebugEventHandler()");
1.89 +
1.90 + if (iLock)
1.91 + iLock->Close(NULL);
1.92 +
1.93 + if (iDevice)
1.94 + iDevice->Close(NULL);
1.95 +
1.96 + if (iClientThread)
1.97 + Kern::SafeClose((DObject*&)iClientThread, NULL);
1.98 +
1.99 +}
1.100 +
1.101 +
1.102 +TInt DRM_DebugEventHandler::Start()
1.103 +{
1.104 + LOG_MSG("DRM_DebugEventHandler::Start()");
1.105 +
1.106 + iTracking = ETrue;
1.107 +
1.108 + return KErrNone;
1.109 +}
1.110 +
1.111 +
1.112 +TInt DRM_DebugEventHandler::Stop()
1.113 +{
1.114 + LOG_MSG("DRM_DebugEventHandler::Stop()");
1.115 +
1.116 + iTracking = EFalse;
1.117 +
1.118 + return KErrNone;
1.119 +}
1.120 +
1.121 +
1.122 +TUint DRM_DebugEventHandler::EventHandler(TKernelEvent aType, TAny* a1, TAny* a2, TAny* aThis)
1.123 +{
1.124 + return ((DRM_DebugEventHandler*)aThis)->HandleEvent(aType, a1, a2);
1.125 +}
1.126 +
1.127 +
1.128 +
1.129 +TUint DRM_DebugEventHandler::HandleEvent(TKernelEvent aType, TAny* a1, TAny* a2)
1.130 + {
1.131 + if((!iTracking) || (aType > (TUint32)EEventLimit))
1.132 + {
1.133 + return ERunNext;
1.134 + }
1.135 + return HandleSpecificEvent(aType,a1,a2) ? EExcHandled : ERunNext;
1.136 + }
1.137 +
1.138 +TBool DRM_DebugEventHandler::HandleSpecificEvent(TKernelEvent aType, TAny* a1, TAny* a2)
1.139 + {
1.140 + TBool ret = EFalse;
1.141 +
1.142 + NKern::ThreadEnterCS();
1.143 + Kern::SemaphoreWait(*iLock);
1.144 +
1.145 + if (iChannel)
1.146 + {
1.147 + ret = (iChannel->*(iEventHandlers[aType]))(a1, a2);
1.148 + }
1.149 +
1.150 + Kern::SemaphoreSignal(*iLock);
1.151 + NKern::ThreadLeaveCS();
1.152 +
1.153 + switch(aType)
1.154 + {
1.155 + case EEventHwExc:
1.156 + case EEventKillThread:
1.157 + {
1.158 + LOG_MSG2("DRM_DebugEventHandler::HandleEvent() -> FSWait(), kernel event type: %d", (TUint32)aType);
1.159 + TheDProcessTracker.FSWait();
1.160 + LOG_MSG("DRM_DebugEventHandler::HandleEvent() <- FSWait()");
1.161 + break;
1.162 + }
1.163 + default:
1.164 + break;
1.165 + }
1.166 + return ret;
1.167 + }
1.168 +