1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/d_exc/minkda.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,319 @@
1.4 +// Copyright (c) 2002-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 +// e32utils\d_exc\minkda.h
1.18 +// API exposed by example of kernel-side debug agent.
1.19 +//
1.20 +//
1.21 +
1.22 +#ifndef __MINKDA_H__
1.23 +#define __MINKDA_H__
1.24 +
1.25 +_LIT(KKdaLddName, "MINKDA");
1.26 +
1.27 +inline TVersion KKdaLddVersion() { return TVersion(1, 0, 1); }
1.28 +
1.29 +
1.30 +#if defined(__MARM__)
1.31 +
1.32 +/**
1.33 + ARM user registers.
1.34 + Size must be multiple of 4 bytes.
1.35 + */
1.36 +
1.37 +class TDbgRegSet
1.38 + {
1.39 +public:
1.40 + enum { KRegCount = 16 };
1.41 + TUint32 iRn[KRegCount];
1.42 + TUint32 iCpsr;
1.43 + };
1.44 +
1.45 +
1.46 +/**
1.47 + ARM-specific exception-related data.
1.48 + Size must be multiple of 4 bytes.
1.49 + */
1.50 +
1.51 +class TDbgCpuExcInfo
1.52 + {
1.53 +public:
1.54 + enum TExcCode
1.55 + {
1.56 + EPrefetchAbort=0,
1.57 + EDataAbort=1,
1.58 + EUndefinedOpcode=2,
1.59 + };
1.60 +public:
1.61 + TExcCode iExcCode;
1.62 + /** Point to instruction which caused exception */
1.63 + TUint32 iFaultPc;
1.64 + /**
1.65 + Address which caused exception (System Control Coprocessor Fault
1.66 + Address Register)
1.67 + */
1.68 + TUint32 iFaultAddress;
1.69 + /** System Control Coprocessor Fault Status Register */
1.70 + TUint32 iFaultStatus;
1.71 + /** R13 supervisor mode banked register */
1.72 + TUint32 iR13Svc;
1.73 + /** R14 supervisor mode banked register */
1.74 + TUint32 iR14Svc;
1.75 + /** SPSR supervisor mode banked register */
1.76 + TUint32 iSpsrSvc;
1.77 + };
1.78 +
1.79 +#else
1.80 +
1.81 +class TDbgRegSet
1.82 + {
1.83 + };
1.84 +
1.85 +class TDbgCpuExcInfo
1.86 + {
1.87 + };
1.88 +
1.89 +#endif
1.90 +
1.91 +
1.92 +/**
1.93 + Exception or panic information block.
1.94 + Size must be multiple of 4 bytes.
1.95 + */
1.96 +
1.97 +class TDbgCrashInfo
1.98 + {
1.99 +public:
1.100 + enum TType { EException, EPanic };
1.101 +public:
1.102 + TType iType;
1.103 + /** ID of thread which crashed */
1.104 + TUint iTid;
1.105 + /** CPU-specific information (exception only) */
1.106 + TDbgCpuExcInfo iCpu;
1.107 + };
1.108 +
1.109 +
1.110 +/**
1.111 + Thread information block.
1.112 + Size must be multiple of 4 bytes.
1.113 + */
1.114 +
1.115 +class TDbgThreadInfo
1.116 + {
1.117 +public:
1.118 + TFullName iFullName;
1.119 + /** ID of owning process */
1.120 + TUint iPid;
1.121 + /** user stack base address */
1.122 + TLinAddr iStackBase;
1.123 + /** user stack size */
1.124 + TInt iStackSize;
1.125 + TExitCategoryName iExitCategory;
1.126 + TInt iExitReason;
1.127 + /** User context */
1.128 + TDbgRegSet iCpu;
1.129 + };
1.130 +
1.131 +
1.132 +/**
1.133 + Code Segment Information Block
1.134 + Size must be multiple of 4 bytes.
1.135 + */
1.136 +
1.137 +class TDbgCodeSegInfo
1.138 + {
1.139 +public:
1.140 + TPath iPath;
1.141 + TUint32 iCodeBase;
1.142 + TUint32 iCodeSize;
1.143 + };
1.144 +
1.145 +
1.146 +/**
1.147 + API exposed by minimal kernel debug agent.
1.148 +
1.149 + This API is provided as an example only. There are no guarantees of
1.150 + binary/source compatibility.
1.151 + */
1.152 +
1.153 +class RMinKda : public RBusLogicalChannel
1.154 + {
1.155 +public:
1.156 + enum TControl
1.157 + {
1.158 + ETrap,
1.159 + ECancelTrap,
1.160 + EKillCrashedThread,
1.161 + EGetThreadInfo,
1.162 + EReadMem,
1.163 + EGetCodeSegs,
1.164 + EGetCodeSegInfo,
1.165 + };
1.166 + // Size of following structs must be multiple of 4 bytes.
1.167 + struct TCodeSnapshotParams
1.168 + {
1.169 + TUint iPid;
1.170 + TAny** iHandles;
1.171 + TInt* iCountPtr;
1.172 + };
1.173 + struct TCodeInfoParams
1.174 + {
1.175 + TUint iPid;
1.176 + TAny* iHandle;
1.177 + TDes8* iPathPtr;
1.178 + TUint32 iCodeBase;
1.179 + TUint32 iCodeSize;
1.180 + };
1.181 + struct TReadMemParams
1.182 + {
1.183 + TUint iTid;
1.184 + TLinAddr iAddr;
1.185 + TDes8* iDes;
1.186 + };
1.187 + struct TDbgInfoParams
1.188 + {
1.189 + TBuf8<KMaxFullName> iFullName;
1.190 + TUint iPid;
1.191 + TLinAddr iStackBase;
1.192 + TInt iStackSize;
1.193 + TBuf8<KMaxExitCategoryName> iExitCategory;
1.194 + TInt iExitReason;
1.195 + TDbgRegSet iCpu;
1.196 + };
1.197 +public:
1.198 +#ifndef __KERNEL_MODE__
1.199 + inline TInt Open();
1.200 + inline void Trap(TRequestStatus& aStatus, TDbgCrashInfo& aInfo);
1.201 + inline void CancelTrap();
1.202 + inline void KillCrashedThread();
1.203 + inline TInt GetThreadInfo(TUint aTid, TDbgThreadInfo& aInfo);
1.204 + inline TInt ReadMem(TUint aTid, TLinAddr aSrc, TDes8& aDest);
1.205 + inline TInt GetCodeSegs(TUint aPid, TAny** aHandleArray, TInt& aHandleCount);
1.206 + inline TInt GetCodeSegInfo(TAny* aHandle, TUint aPid, TDbgCodeSegInfo& aInfo);
1.207 +#endif
1.208 + };
1.209 +
1.210 +
1.211 +#ifndef __KERNEL_MODE__
1.212 +
1.213 +inline TInt RMinKda::Open()
1.214 + {
1.215 + return DoCreate(KKdaLddName, KKdaLddVersion(), KNullUnit, NULL, NULL, EOwnerThread);
1.216 + }
1.217 +
1.218 +/**
1.219 + Ask to be notified of the next panic or exception occurence.
1.220 +
1.221 + The crashed thread will remain suspended until KillCrashedThread() is
1.222 + called allowing more information to be gathered (e.g. stack content).
1.223 +
1.224 + If more threads panic or take an exception, they will be suspended
1.225 + too until the first one is killed.
1.226 +
1.227 + @param aStatus Request to complete when panic/exception occurs
1.228 + @param aInfo Filled when request completes
1.229 + */
1.230 +
1.231 +inline void RMinKda::Trap(TRequestStatus& aStatus, TDbgCrashInfo& aInfo)
1.232 + {
1.233 + DoControl(ETrap, &aStatus, &aInfo);
1.234 + }
1.235 +
1.236 +/** Cancel previous call to Trap() */
1.237 +
1.238 +inline void RMinKda::CancelTrap()
1.239 + {
1.240 + DoControl(ECancelTrap, NULL, NULL);
1.241 + }
1.242 +
1.243 +/**
1.244 + Kill the thread which crashed causing the Trap() request to complete.
1.245 + */
1.246 +
1.247 +inline void RMinKda::KillCrashedThread()
1.248 + {
1.249 + DoControl(EKillCrashedThread, NULL, NULL);
1.250 + }
1.251 +
1.252 +
1.253 +/**
1.254 + Return information about thread identified by its ID.
1.255 + */
1.256 +
1.257 +inline TInt RMinKda::GetThreadInfo(TUint aTid, TDbgThreadInfo& aInfo)
1.258 + {
1.259 + TDbgInfoParams params;
1.260 + TInt r=DoControl(EGetThreadInfo, (TAny*)aTid, ¶ms);
1.261 + if (r==KErrNone)
1.262 + {
1.263 + aInfo.iFullName.Copy(params.iFullName);
1.264 + aInfo.iPid = params.iPid;
1.265 + aInfo.iStackBase = params.iStackBase;
1.266 + aInfo.iStackSize = params.iStackSize;
1.267 + aInfo.iExitCategory.Copy(params.iExitCategory);
1.268 + aInfo.iExitReason = params.iExitReason;
1.269 + aInfo.iCpu = params.iCpu;
1.270 + }
1.271 + return r;
1.272 + }
1.273 +
1.274 +/**
1.275 + Read memory from designated thread address space.
1.276 +
1.277 + @param aTid Thread id
1.278 + @param aSrc Source address
1.279 + @param aDest Destination descriptor. Number of bytes to read is
1.280 + aDes.MaxSize().
1.281 +
1.282 + @return standard error code
1.283 + */
1.284 +
1.285 +inline TInt RMinKda::ReadMem(TUint aTid, TLinAddr aSrc, TDes8& aDest)
1.286 + {
1.287 + TReadMemParams params;
1.288 + params.iTid = aTid;
1.289 + params.iAddr = aSrc;
1.290 + params.iDes = &aDest;
1.291 + return DoControl(EReadMem, ¶ms, NULL);
1.292 + }
1.293 +
1.294 +inline TInt RMinKda::GetCodeSegs(TUint aPid, TAny** aHandleArray, TInt& aHandleCount)
1.295 + {
1.296 + TCodeSnapshotParams params;
1.297 + params.iPid = aPid;
1.298 + params.iHandles = aHandleArray;
1.299 + params.iCountPtr = &aHandleCount;
1.300 + return DoControl(EGetCodeSegs, ¶ms, NULL);
1.301 + }
1.302 +
1.303 +inline TInt RMinKda::GetCodeSegInfo(TAny* aHandle, TUint aPid, TDbgCodeSegInfo& aInfo)
1.304 + {
1.305 + TBuf8<KMaxPath> path;
1.306 + TCodeInfoParams params;
1.307 + params.iPid = aPid;
1.308 + params.iHandle = aHandle;
1.309 + params.iPathPtr = &path;
1.310 + TInt r = DoControl(EGetCodeSegInfo, ¶ms, NULL);
1.311 + if (r == KErrNone)
1.312 + {
1.313 + aInfo.iCodeBase = params.iCodeBase;
1.314 + aInfo.iCodeSize = params.iCodeSize;
1.315 + aInfo.iPath.Copy(path);
1.316 + }
1.317 + return r;
1.318 + }
1.319 +
1.320 +#endif
1.321 +
1.322 +#endif