更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
Exception handling
Exception handling 的协作图:

结构体

struct  ExcInfo
 

类型定义

typedef VOID(* EXC_PROC_FUNC) (UINT32, ExcContext *, UINT32, UINT32)
 Define an exception handling function hook. 更多...
 

函数

STATIC INLINE UINTPTR Get_Fp (VOID)
 Kernel FP Register address obtain function. 更多...
 
UINT32 LOS_ExcRegHook (EXC_PROC_FUNC excHook)
 Register an exception handling hook. 更多...
 
NORETURN VOID LOS_Panic (const CHAR *fmt,...)
 Kernel panic function. 更多...
 
VOID LOS_RecordLR (UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCount)
 record LR function. 更多...
 
VOID OsBackTrace (VOID)
 Kernel backtrace function. 更多...
 
VOID OsTaskBackTrace (UINT32 taskID)
 Kernel task backtrace function. 更多...
 

详细描述

类型定义说明

◆ EXC_PROC_FUNC

typedef VOID(* EXC_PROC_FUNC) (UINT32, ExcContext *, UINT32, UINT32)

Define an exception handling function hook.

Description:
This API is used to define the exception handling function hook based on the type of the exception handling function and record exceptions.
注意
None.
参数
None.
返回值
None.
Dependency:
los_exc.h: the header file that contains the API declaration.
参见
None.

在文件 los_exc.h153 行定义.

函数说明

◆ Get_Fp()

STATIC INLINE UINTPTR Get_Fp ( VOID  )

Kernel FP Register address obtain function.

Description:
The API is used to obtain the FP Register address.
注意
None.
参数
None.
返回值
UINTPTRThe FP Register address.
Dependency:
los_exc.h: the header file that contains the API declaration.
参见
None.

在文件 los_exc.h123 行定义.

124{
125 UINTPTR regFp;
126
127#ifdef LOSCFG_ARCH_ARM_AARCH64
128 __asm__ __volatile__("mov %0, X29" : "=r"(regFp));
129#else
130 __asm__ __volatile__("mov %0, fp" : "=r"(regFp));
131#endif
132
133 return regFp;
134}
unsigned long UINTPTR
Definition: los_typedef.h:68
这是这个函数的调用关系图:

◆ LOS_ExcRegHook()

UINT32 LOS_ExcRegHook ( EXC_PROC_FUNC  excHook)

Register an exception handling hook.

Description:
This API is used to register an exception handling hook.
注意
If the hook is registered for multiple times, the hook registered at the last time is effective.
The hook can be registered as NULL, indicating that the hook registration is canceled.
参数
excHook[IN] Type EXC_PROC_FUNC: hook function.
返回值
#LOS_OKThe exception handling hook is successfully registered.
Dependency:
los_exc.h: the header file that contains the API declaration.
参见
None.

Register an exception handling hook.

在文件 los_exc.c498 行定义.

499{
500 UINT32 intSave;
501
502 intSave = LOS_IntLock();
503 g_excHook = excHook;
504 LOS_IntRestore(intSave);
505
506 return LOS_OK;
507}
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
Restore interrupts. | 恢复到使用LOS_IntLock关闭所有中断之前的状态
Definition: los_hwi.h:337
STATIC INLINE UINT32 LOS_IntLock(VOID)
Disable all interrupts. | 关闭当前处理器所有中断响应
Definition: los_hwi.h:286
STATIC EXC_PROC_FUNC g_excHook
全局异常处理钩子
Definition: los_exc.c:130
unsigned int UINT32
Definition: los_typedef.h:57
函数调用图:

◆ LOS_Panic()

NORETURN VOID LOS_Panic ( const CHAR fmt,
  ... 
)

Kernel panic function.

Description:
Stack function that prints kernel panics.
注意
After this function is called and stack information is printed, the system will fail to respond.
The input parameter can be NULL.
参数
fmt[IN] Type CHAR* : variadic argument.
返回值
#None.
Dependency:
los_exc.h: the header file that contains the API declaration.
参见
None.
这是这个函数的调用关系图:

◆ LOS_RecordLR()

VOID LOS_RecordLR ( UINTPTR LR,
UINT32  LRSize,
UINT32  recordCount,
UINT32  jumpCount 
)

record LR function.

Description:
注意
参数
LR[IN] Type UINTPTR * LR buffer.
recordCount[IN] Type UINT32 record LR lay number.
jumpCount[IN] Type UINT32 ignore LR lay number.
返回值
#None.
Dependency:
los_exc.h: the header file that contains the API declaration.
参见
None.

在文件 los_exc.c1353 行定义.

1354{
1355 UINT32 count = 0;
1356 UINT32 index = 0;
1357 UINT32 stackStart, stackEnd;
1358 LosTaskCB *taskCB = NULL;
1359 UINTPTR framePtr, tmpFramePtr, linkReg;
1360
1361 if (LR == NULL) {
1362 return;
1363 }
1364 /* if LR array is not enough,just record LRSize. */
1365 if (LRSize < recordCount) {
1366 recordCount = LRSize;
1367 }
1368
1369 taskCB = OsCurrTaskGet();
1370 stackStart = taskCB->topOfStack;
1371 stackEnd = stackStart + taskCB->stackSize;
1372
1373 framePtr = Get_Fp();
1374 while ((framePtr > stackStart) && (framePtr < stackEnd) && IS_ALIGNED(framePtr, sizeof(CHAR *))) {
1375 tmpFramePtr = framePtr;
1376#ifdef LOSCFG_COMPILER_CLANG_LLVM
1377 linkReg = *(UINTPTR *)(tmpFramePtr + sizeof(UINTPTR));
1378#else
1379 linkReg = *(UINTPTR *)framePtr;
1380#endif
1381 if (index >= jumpCount) {
1382 LR[count++] = linkReg;
1383 if (count == recordCount) {
1384 break;
1385 }
1386 }
1387 index++;
1388#ifdef LOSCFG_COMPILER_CLANG_LLVM
1389 framePtr = *(UINTPTR *)framePtr;
1390#else
1391 framePtr = *(UINTPTR *)(tmpFramePtr - sizeof(UINTPTR));
1392#endif
1393 }
1394
1395 /* if linkReg is not enough,clean up the last of the effective LR as the end. */
1396 if (count < recordCount) {
1397 LR[count] = 0;
1398 }
1399}
STATIC INLINE UINTPTR Get_Fp(VOID)
Kernel FP Register address obtain function.
Definition: los_exc.h:123
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
char CHAR
Definition: los_typedef.h:63
UINT32 stackSize
UINTPTR topOfStack
函数调用图:
这是这个函数的调用关系图:

◆ OsBackTrace()

VOID OsBackTrace ( VOID  )

Kernel backtrace function.

Description:
Backtrace function that prints task call stack information traced from the running task.
注意
None.
参数
None.
返回值
#None.
Dependency:
los_exc.h: the header file that contains the API declaration.
参见
None.

在文件 los_exc.c1025 行定义.

1026{
1027 UINT32 regFP = Get_Fp();
1028 LosTaskCB *runTask = OsCurrTaskGet();
1029 PrintExcInfo("OsBackTrace fp = 0x%x\n", regFP);
1030 PrintExcInfo("runTask->taskName = %s\n", runTask->taskName);
1031 PrintExcInfo("runTask->taskID = %u\n", runTask->taskID);
1032 BackTrace(regFP);
1033}
VOID BackTrace(UINT32 regFP)
打印调用栈信息
Definition: los_exc.c:930
VOID PrintExcInfo(const CHAR *fmt,...)
打印异常信息
Definition: los_printf.c:263
UINT32 taskID
CHAR taskName[OS_TCB_NAME_LEN]
函数调用图:
这是这个函数的调用关系图:

◆ OsTaskBackTrace()

VOID OsTaskBackTrace ( UINT32  taskID)

Kernel task backtrace function.

Description:
Backtrace function that prints task call stack information traced from the input task.
注意
  • The input taskID should be valid.
参数
taskID[IN] Type UINT32 Task ID.
返回值
#None.
Dependency:
los_exc.h: the header file that contains the API declaration.
参见
None.

在文件 los_exc.c1007 行定义.

1008{
1009 LosTaskCB *taskCB = NULL;
1010
1011 if (OS_TID_CHECK_INVALID(taskID)) {
1012 PRINT_ERR("\r\nTask ID is invalid!\n");
1013 return;
1014 }
1015 taskCB = OS_TCB_FROM_TID(taskID);
1016 if (OsTaskIsUnused(taskCB) || (taskCB->taskEntry == NULL)) {
1017 PRINT_ERR("\r\nThe task is not created!\n");
1018 return;
1019 }
1020 PRINTK("TaskName = %s\n", taskCB->taskName);
1021 PRINTK("TaskID = 0x%x\n", taskCB->taskID);
1022 BackTrace(((TaskContext *)(taskCB->stackPointer))->R11); /* R11 : FP */
1023}
STATIC INLINE BOOL OsTaskIsUnused(const LosTaskCB *taskCB)
任务是否在使用
Definition: los_task_pri.h:255
TSK_ENTRY_FUNC taskEntry
VOID * stackPointer
函数调用图: