feature:the feature of saving system exception information to the

storage medium is separated from the shell module.

Change-Id: Id56939001d70bb92d9cc02bd7c9f55ca8b61cf5b
This commit is contained in:
YOUR_NAME 2021-04-29 16:04:33 +08:00
parent 8592e04c78
commit d846035f3e
10 changed files with 79 additions and 90 deletions

View File

@ -165,6 +165,7 @@ config THUMB
default n default n
help help
Answer Y to build thumb version. This will make LiteOS smaller. Answer Y to build thumb version. This will make LiteOS smaller.
config PLATFORM_DVFS config PLATFORM_DVFS
bool "Enable Dvfs" bool "Enable Dvfs"
default n default n
@ -173,6 +174,12 @@ config PLATFORM_DVFS
Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for
low power consumption. low power consumption.
config SAVE_EXCINFO
bool "Enable Saving Exception Information"
default n
help
Answer Y to enable LiteOS support saving exception information to storage medium.
config DEBUG_VERSION config DEBUG_VERSION
bool "Enable a Debug Version" bool "Enable a Debug Version"
default n default n

View File

@ -34,7 +34,7 @@
#include "los_printf_pri.h" #include "los_printf_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
#include "los_hw_pri.h" #include "los_hw_pri.h"
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h" #include "los_excinfo_pri.h"
#endif #endif
#ifdef LOSCFG_EXC_INTERACTION #ifdef LOSCFG_EXC_INTERACTION
@ -576,7 +576,7 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
#endif #endif
#endif #endif
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
OsProcessExitCodeCoreDumpSet(runProcess); OsProcessExitCodeCoreDumpSet(runProcess);
#endif #endif
OsProcessExitCodeSignalSet(runProcess, SIGUSR2); OsProcessExitCodeSignalSet(runProcess, SIGUSR2);
@ -1086,6 +1086,22 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far)
} }
} }
#ifdef LOSCFG_SAVE_EXCINFO
STATIC VOID OsSysStateSave(UINT32 *intCount, UINT32 *lockCount)
{
*intCount = g_intCount[ArchCurrCpuid()];
*lockCount = OsPercpuGet()->taskLockCnt;
g_intCount[ArchCurrCpuid()] = 0;
OsPercpuGet()->taskLockCnt = 0;
}
STATIC VOID OsSysStateRestore(UINT32 intCount, UINT32 lockCount)
{
g_intCount[ArchCurrCpuid()] = intCount;
OsPercpuGet()->taskLockCnt = lockCount;
}
#endif
/* /*
* Description : EXC handler entry * Description : EXC handler entry
* Input : excType --- exc type * Input : excType --- exc type
@ -1093,6 +1109,11 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far)
*/ */
LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr)
{ {
#ifdef LOSCFG_SAVE_EXCINFO
UINT32 intCount;
UINT32 lockCount;
#endif
/* Task scheduling is not allowed during exception handling */ /* Task scheduling is not allowed during exception handling */
OsPercpuGet()->taskLockCnt++; OsPercpuGet()->taskLockCnt++;
@ -1106,18 +1127,18 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
OsAllCpuStatusOutput(); OsAllCpuStatusOutput();
#endif #endif
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
log_read_write_fn func = GetExcInfoRW(); log_read_write_fn func = GetExcInfoRW();
#endif #endif
if (g_excHook != NULL) { if (g_excHook != NULL) {
if (g_curNestCount[ArchCurrCpuid()] == 1) { if (g_curNestCount[ArchCurrCpuid()] == 1) {
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
if (func != NULL) { if (func != NULL) {
SetExcInfoIndex(0); SetExcInfoIndex(0);
g_intCount[ArchCurrCpuid()] = 0; OsSysStateSave(&intCount, &lockCount);
OsRecordExcInfoTime(); OsRecordExcInfoTime();
g_intCount[ArchCurrCpuid()] = 1; OsSysStateRestore(intCount, lockCount);
} }
#endif #endif
g_excHook(excType, excBufAddr, far, fsr); g_excHook(excType, excBufAddr, far, fsr);
@ -1125,12 +1146,12 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
OsCallStackInfo(); OsCallStackInfo();
} }
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
if (func != NULL) { if (func != NULL) {
PrintExcInfo("Be sure flash space bigger than GetExcInfoIndex():0x%x\n", GetExcInfoIndex()); PrintExcInfo("Be sure flash space bigger than GetExcInfoIndex():0x%x\n", GetExcInfoIndex());
g_intCount[ArchCurrCpuid()] = 0; OsSysStateSave(&intCount, &lockCount);
func(GetRecordAddr(), GetRecordSpace(), 0, GetExcInfoBuf()); func(GetRecordAddr(), GetRecordSpace(), 0, GetExcInfoBuf());
g_intCount[ArchCurrCpuid()] = 1; OsSysStateRestore(intCount, lockCount);
} }
#endif #endif
} }

View File

@ -31,7 +31,7 @@
#include "stdlib.h" #include "stdlib.h"
#include "los_memory_pri.h" #include "los_memory_pri.h"
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h" #include "los_excinfo_pri.h"
#endif #endif
#ifdef LOSCFG_SHELL #ifdef LOSCFG_SHELL
@ -64,7 +64,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr)
while (dataLen) { while (dataLen) {
if (IS_ALIGNED(count, sizeof(CHAR *))) { if (IS_ALIGNED(count, sizeof(CHAR *))) {
PRINTK("\n 0x%lx :", alignAddr); PRINTK("\n 0x%lx :", alignAddr);
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
WriteExcInfoToBuf("\n 0x%lx :", alignAddr); WriteExcInfoToBuf("\n 0x%lx :", alignAddr);
#endif #endif
} }
@ -73,7 +73,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr)
#else #else
PRINTK("%0+8lx ", *alignAddr); PRINTK("%0+8lx ", *alignAddr);
#endif #endif
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
#ifdef __LP64__ #ifdef __LP64__
WriteExcInfoToBuf("0x%0+16x ", *alignAddr); WriteExcInfoToBuf("0x%0+16x ", *alignAddr);
#else #else
@ -85,7 +85,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr)
count++; count++;
} }
PRINTK("\n"); PRINTK("\n");
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
WriteExcInfoToBuf("\n"); WriteExcInfoToBuf("\n");
#endif #endif
@ -101,14 +101,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[])
if (LOS_MemIntegrityCheck(m_aucSysMem1) == LOS_OK) { if (LOS_MemIntegrityCheck(m_aucSysMem1) == LOS_OK) {
PRINTK("system memcheck over, all passed!\n"); PRINTK("system memcheck over, all passed!\n");
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
WriteExcInfoToBuf("system memcheck over, all passed!\n"); WriteExcInfoToBuf("system memcheck over, all passed!\n");
#endif #endif
} }
#ifdef LOSCFG_EXC_INTERACTION #ifdef LOSCFG_EXC_INTERACTION
if (LOS_MemIntegrityCheck(m_aucSysMem0) == LOS_OK) { if (LOS_MemIntegrityCheck(m_aucSysMem0) == LOS_OK) {
PRINTK("exc interaction memcheck over, all passed!\n"); PRINTK("exc interaction memcheck over, all passed!\n");
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
WriteExcInfoToBuf("exc interaction memcheck over, all passed!\n"); WriteExcInfoToBuf("exc interaction memcheck over, all passed!\n");
#endif #endif
} }

View File

@ -43,7 +43,7 @@
#ifdef LOSCFG_KERNEL_CPUP #ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h" #include "los_cpup_pri.h"
#endif #endif
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h" #include "los_excinfo_pri.h"
#endif #endif
#include "los_process_pri.h" #include "los_process_pri.h"

View File

@ -398,7 +398,7 @@ extern UINT32 __heap_end;
#endif #endif
/****************************** exception information configuration ******************************/ /****************************** exception information configuration ******************************/
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
/** /**
* @ingroup los_config * @ingroup los_config
* the size of space for recording exception information * the size of space for recording exception information

View File

@ -34,9 +34,11 @@
#ifdef LOSCFG_FS_VFS #ifdef LOSCFG_FS_VFS
#include "fs/fs.h" #include "fs/fs.h"
#endif #endif
#ifdef LOSCFG_SHELL
#include "shcmd.h"
#endif
#ifdef LOSCFG_SAVE_EXCINFO
#ifdef LOSCFG_SHELL_EXCINFO
STATIC log_read_write_fn g_excInfoRW = NULL; /* the hook of read-writing exception information */ STATIC log_read_write_fn g_excInfoRW = NULL; /* the hook of read-writing exception information */
STATIC CHAR *g_excInfoBuf = NULL; /* pointer to the buffer for storing the exception information */ STATIC CHAR *g_excInfoBuf = NULL; /* pointer to the buffer for storing the exception information */
STATIC UINT32 g_excInfoIndex = 0xFFFFFFFF; /* the index of the buffer for storing the exception information */ STATIC UINT32 g_excInfoIndex = 0xFFFFFFFF; /* the index of the buffer for storing the exception information */
@ -164,5 +166,32 @@ VOID OsRecordExcInfoTime(VOID)
#endif #endif
} }
#ifdef LOSCFG_SHELL
INT32 OsShellCmdReadExcInfo(INT32 argc, CHAR **argv)
{
UINT32 recordSpace = GetRecordSpace();
(VOID)argc;
(VOID)argv;
CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1);
if (buf == NULL) {
return LOS_NOK;
}
(void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1);
log_read_write_fn hook = GetExcInfoRW();
if (hook != NULL) {
hook(GetRecordAddr(), recordSpace, 1, buf);
}
PRINTK("%s\n", buf);
(VOID)LOS_MemFree((void *)OS_SYS_MEM_ADDR, buf);
buf = NULL;
return LOS_OK;
}
SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc)OsShellCmdReadExcInfo);
#endif
#endif #endif

View File

@ -40,7 +40,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
extern VOID SetExcInfoRW(log_read_write_fn func); extern VOID SetExcInfoRW(log_read_write_fn func);
extern log_read_write_fn GetExcInfoRW(VOID); extern log_read_write_fn GetExcInfoRW(VOID);
extern VOID SetExcInfoBuf(CHAR *buf); extern VOID SetExcInfoBuf(CHAR *buf);

View File

@ -42,7 +42,7 @@
#ifdef LOSCFG_SHELL_DMESG #ifdef LOSCFG_SHELL_DMESG
#include "dmesg_pri.h" #include "dmesg_pri.h"
#endif #endif
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h" #include "los_excinfo_pri.h"
#endif #endif
#include "los_exc_pri.h" #include "los_exc_pri.h"
@ -250,7 +250,7 @@ VOID PrintExcInfo(const CHAR *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
/* uart output without print-spinlock */ /* uart output without print-spinlock */
OsVprintf(fmt, ap, EXC_OUTPUT); OsVprintf(fmt, ap, EXC_OUTPUT);
#ifdef LOSCFG_SHELL_EXCINFO #ifdef LOSCFG_SAVE_EXCINFO
WriteExcBufVa(fmt, ap); WriteExcBufVa(fmt, ap);
#endif #endif
va_end(ap); va_end(ap);

View File

@ -22,11 +22,4 @@ config SHELL_DMESG
help help
Answer Y to enable LiteOS support shell dmesg. Answer Y to enable LiteOS support shell dmesg.
config SHELL_EXCINFO
bool "Enable Shell excInfo"
default n
depends on DEBUG_VERSION && SHELL
help
Answer Y to enable LiteOS support shell excInfo.
endmenu endmenu

View File

@ -1,61 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "shcmd.h"
#include "los_memory.h"
#ifdef LOSCFG_SHELL_EXCINFO
#include "los_excinfo_pri.h"
INT32 osShellCmdReadExcInfo(INT32 argc, CHAR **argv)
{
UINT32 recordSpace = GetRecordSpace();
(VOID)argc;
(VOID)argv;
CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1);
if (buf == NULL) {
return LOS_NOK;
}
(void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1);
log_read_write_fn hook = GetExcInfoRW();
if (hook != NULL) {
hook(GetRecordAddr(), recordSpace, 1, buf);
}
PRINTK("%s\n", buf);
(VOID)LOS_MemFree((void *)OS_SYS_MEM_ADDR, buf);
buf = NULL;
return LOS_OK;
}
SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc)osShellCmdReadExcInfo);
#endif