!201 系统异常信息保存到存储介质中的功能从shell依赖中剥离

Merge pull request !201 from zhangfanfan2/master
This commit is contained in:
openharmony_ci 2021-05-06 20:44:32 +08:00 committed by Gitee
commit be4d8e74cc
10 changed files with 79 additions and 90 deletions

View File

@ -165,6 +165,7 @@ config THUMB
default n
help
Answer Y to build thumb version. This will make LiteOS smaller.
config PLATFORM_DVFS
bool "Enable Dvfs"
default n
@ -173,6 +174,12 @@ config PLATFORM_DVFS
Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for
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
bool "Enable a Debug Version"
default n

View File

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

View File

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

View File

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

View File

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

View File

@ -34,9 +34,11 @@
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#endif
#ifdef LOSCFG_SHELL
#include "shcmd.h"
#endif
#ifdef LOSCFG_SHELL_EXCINFO
#ifdef LOSCFG_SAVE_EXCINFO
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 UINT32 g_excInfoIndex = 0xFFFFFFFF; /* the index of the buffer for storing the exception information */
@ -164,5 +166,32 @@ VOID OsRecordExcInfoTime(VOID)
#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

View File

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

View File

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

View File

@ -22,11 +22,4 @@ config SHELL_DMESG
help
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

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