sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Purpose: Implementation of static functions for use by debug driver classes sl@0: // sl@0: sl@0: #include "debug_logging.h" sl@0: #include "debug_utils.h" sl@0: sl@0: /** sl@0: * Given a thread ID, return a handle to the corresponding DThread. If the returned sl@0: * pointer is non-NULL, it is the responsibility of the caller to close the handle. sl@0: * sl@0: * @post if a non-NULL value is returned then a handle to the thread has been sl@0: * opened on the callers behalf sl@0: * @param aThreadId ID of the thread to return a handle for sl@0: * @return a DThread* to the appropriate thread, or NULL if a handle could not be sl@0: * opened to the specified thread sl@0: */ sl@0: DThread* DebugUtils::OpenThreadHandle(const TUint64 aThreadId) sl@0: { sl@0: LOG_MSG("DebugUtils::OpenThreadHandle()"); sl@0: sl@0: NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex sl@0: DObjectCon& threads = *Kern::Containers()[EThread]; // Get containing holding threads sl@0: threads.Wait(); // Obtain the container mutex so the list does get changed under us sl@0: sl@0: DThread* thread = Kern::ThreadFromId(aThreadId); sl@0: sl@0: // Open a handle to the thread so that it doesn't exit while we are processing sl@0: if (thread) sl@0: { sl@0: // if opening a handle fails then set thread to NULL sl@0: if(KErrNone != thread->Open()) sl@0: { sl@0: LOG_MSG2("\tCould not open handle to thread %d", (TUint32)aThreadId); sl@0: thread = NULL; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: LOG_MSG2("\tThread with ID %d is NULL", (TUint32)aThreadId); sl@0: } sl@0: sl@0: threads.Signal(); // Release the container mutex sl@0: NKern::ThreadLeaveCS(); // End of critical section sl@0: sl@0: return thread; sl@0: } sl@0: sl@0: /** sl@0: * Given a process ID, return a handle to the corresponding DProcess. If the returned sl@0: * pointer is non-NULL, it is the responsibility of the caller to close the handle. sl@0: * sl@0: * @post if a non-NULL value is returned then a handle to the process has been sl@0: * opened on the callers behalf sl@0: * @param aProcessId ID of the process to return a handle for sl@0: * @return a DProcess* to the appropriate process, or NULL if a handle could not be sl@0: * opened to the specified process sl@0: */ sl@0: DProcess* DebugUtils::OpenProcessHandle(const TUint64 aProcessId) sl@0: { sl@0: // Commenting out this message as it gets printed out every time a RDebug::Printf statement is caught by the driver, sl@0: // which makes looking at the serial cable output irritating. Replaced it with LOG_MSG statements below to indicate if sl@0: // something amiss happened. By default then this function prints nothing out. sl@0: //LOG_MSG("DebugUtils::OpenProcessHandle()"); sl@0: sl@0: NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex sl@0: DObjectCon& processes = *Kern::Containers()[EProcess]; // Get containing holding threads sl@0: processes.Wait(); // Obtain the container mutex so the list does get changed under us sl@0: sl@0: DProcess* process = Kern::ProcessFromId(aProcessId); sl@0: sl@0: // Open a handle to the process so that it doesn't exit while we are processing sl@0: if (process) sl@0: { sl@0: // if opening a handle fails then set process to NULL sl@0: if(KErrNone != process->Open()) sl@0: { sl@0: LOG_MSG2("DebugUtils::OpenProcessHandle(): Could not open handle for 0x%016lx", aProcessId); sl@0: process = NULL; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: LOG_MSG2("DebugUtils::OpenProcessHandle(): Could not find process for 0x%016lx", aProcessId); sl@0: } sl@0: sl@0: processes.Signal(); // Release the container mutex sl@0: NKern::ThreadLeaveCS(); // End of critical section sl@0: sl@0: return process; sl@0: } sl@0: