0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Purpose: Implementation of static functions for use by debug driver classes
|
|
15 |
//
|
|
16 |
|
|
17 |
#include "debug_logging.h"
|
|
18 |
#include "debug_utils.h"
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Given a thread ID, return a handle to the corresponding DThread. If the returned
|
|
22 |
* pointer is non-NULL, it is the responsibility of the caller to close the handle.
|
|
23 |
*
|
|
24 |
* @post if a non-NULL value is returned then a handle to the thread has been
|
|
25 |
* opened on the callers behalf
|
|
26 |
* @param aThreadId ID of the thread to return a handle for
|
|
27 |
* @return a DThread* to the appropriate thread, or NULL if a handle could not be
|
|
28 |
* opened to the specified thread
|
|
29 |
*/
|
|
30 |
DThread* DebugUtils::OpenThreadHandle(const TUint64 aThreadId)
|
|
31 |
{
|
|
32 |
LOG_MSG("DebugUtils::OpenThreadHandle()");
|
|
33 |
|
|
34 |
NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex
|
|
35 |
DObjectCon& threads = *Kern::Containers()[EThread]; // Get containing holding threads
|
|
36 |
threads.Wait(); // Obtain the container mutex so the list does get changed under us
|
|
37 |
|
|
38 |
DThread* thread = Kern::ThreadFromId(aThreadId);
|
|
39 |
|
|
40 |
// Open a handle to the thread so that it doesn't exit while we are processing
|
|
41 |
if (thread)
|
|
42 |
{
|
|
43 |
// if opening a handle fails then set thread to NULL
|
|
44 |
if(KErrNone != thread->Open())
|
|
45 |
{
|
|
46 |
LOG_MSG2("\tCould not open handle to thread %d", (TUint32)aThreadId);
|
|
47 |
thread = NULL;
|
|
48 |
}
|
|
49 |
}
|
|
50 |
else
|
|
51 |
{
|
|
52 |
LOG_MSG2("\tThread with ID %d is NULL", (TUint32)aThreadId);
|
|
53 |
}
|
|
54 |
|
|
55 |
threads.Signal(); // Release the container mutex
|
|
56 |
NKern::ThreadLeaveCS(); // End of critical section
|
|
57 |
|
|
58 |
return thread;
|
|
59 |
}
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Given a process ID, return a handle to the corresponding DProcess. If the returned
|
|
63 |
* pointer is non-NULL, it is the responsibility of the caller to close the handle.
|
|
64 |
*
|
|
65 |
* @post if a non-NULL value is returned then a handle to the process has been
|
|
66 |
* opened on the callers behalf
|
|
67 |
* @param aProcessId ID of the process to return a handle for
|
|
68 |
* @return a DProcess* to the appropriate process, or NULL if a handle could not be
|
|
69 |
* opened to the specified process
|
|
70 |
*/
|
|
71 |
DProcess* DebugUtils::OpenProcessHandle(const TUint64 aProcessId)
|
|
72 |
{
|
|
73 |
// Commenting out this message as it gets printed out every time a RDebug::Printf statement is caught by the driver,
|
|
74 |
// which makes looking at the serial cable output irritating. Replaced it with LOG_MSG statements below to indicate if
|
|
75 |
// something amiss happened. By default then this function prints nothing out.
|
|
76 |
//LOG_MSG("DebugUtils::OpenProcessHandle()");
|
|
77 |
|
|
78 |
NKern::ThreadEnterCS(); // Prevent us from dying or suspending whilst holding a DMutex
|
|
79 |
DObjectCon& processes = *Kern::Containers()[EProcess]; // Get containing holding threads
|
|
80 |
processes.Wait(); // Obtain the container mutex so the list does get changed under us
|
|
81 |
|
|
82 |
DProcess* process = Kern::ProcessFromId(aProcessId);
|
|
83 |
|
|
84 |
// Open a handle to the process so that it doesn't exit while we are processing
|
|
85 |
if (process)
|
|
86 |
{
|
|
87 |
// if opening a handle fails then set process to NULL
|
|
88 |
if(KErrNone != process->Open())
|
|
89 |
{
|
|
90 |
LOG_MSG2("DebugUtils::OpenProcessHandle(): Could not open handle for 0x%016lx", aProcessId);
|
|
91 |
process = NULL;
|
|
92 |
}
|
|
93 |
}
|
|
94 |
else
|
|
95 |
{
|
|
96 |
LOG_MSG2("DebugUtils::OpenProcessHandle(): Could not find process for 0x%016lx", aProcessId);
|
|
97 |
}
|
|
98 |
|
|
99 |
processes.Signal(); // Release the container mutex
|
|
100 |
NKern::ThreadLeaveCS(); // End of critical section
|
|
101 |
|
|
102 |
return process;
|
|
103 |
}
|
|
104 |
|