13d8536b4Sopenharmony_ci/* 23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 33d8536b4Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 43d8536b4Sopenharmony_ci * 53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met: 73d8536b4Sopenharmony_ci * 83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 93d8536b4Sopenharmony_ci * conditions and the following disclaimer. 103d8536b4Sopenharmony_ci * 113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 123d8536b4Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 133d8536b4Sopenharmony_ci * provided with the distribution. 143d8536b4Sopenharmony_ci * 153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 163d8536b4Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 173d8536b4Sopenharmony_ci * permission. 183d8536b4Sopenharmony_ci * 193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 303d8536b4Sopenharmony_ci */ 313d8536b4Sopenharmony_ci 323d8536b4Sopenharmony_ci#ifndef _LOS_BACKTRACE_H 333d8536b4Sopenharmony_ci#define _LOS_BACKTRACE_H 343d8536b4Sopenharmony_ci 353d8536b4Sopenharmony_ci#include "los_config.h" 363d8536b4Sopenharmony_ci#include "los_arch_interrupt.h" 373d8536b4Sopenharmony_ci 383d8536b4Sopenharmony_ci#ifdef __cplusplus 393d8536b4Sopenharmony_ci#if __cplusplus 403d8536b4Sopenharmony_ciextern "C" { 413d8536b4Sopenharmony_ci#endif /* __cplusplus */ 423d8536b4Sopenharmony_ci#endif /* __cplusplus */ 433d8536b4Sopenharmony_ci 443d8536b4Sopenharmony_ci#define BACKTRACE_MAX_DEPTH LOSCFG_BACKTRACE_DEPTH 453d8536b4Sopenharmony_ci 463d8536b4Sopenharmony_ci#if (LOSCFG_BACKTRACE_TYPE != 0) 473d8536b4Sopenharmony_ci#if (LOSCFG_BACKTRACE_TYPE == 1) 483d8536b4Sopenharmony_ci/* The default name of the code section and CSTACK section are given below, 493d8536b4Sopenharmony_ci and the user can adjust it according to the linker script file. */ 503d8536b4Sopenharmony_ci#if defined(__ICCARM__) 513d8536b4Sopenharmony_ci/* The default code section name is .text */ 523d8536b4Sopenharmony_ci#define CODE_SECTION_NAME ".text" 533d8536b4Sopenharmony_ci/* The default C stack section name is CSTACK */ 543d8536b4Sopenharmony_ci#define CSTACK_SECTION_NAME "CSTACK" 553d8536b4Sopenharmony_ci#pragma section = CODE_SECTION_NAME 563d8536b4Sopenharmony_ci#pragma section = CSTACK_SECTION_NAME 573d8536b4Sopenharmony_ci 583d8536b4Sopenharmony_ci/* Default only one code section. In fact, there may be more than one. 593d8536b4Sopenharmony_ci You can define more than one and redefine the OsStackDataIsCodeAddr function 603d8536b4Sopenharmony_ci to support searching in multiple code sections */ 613d8536b4Sopenharmony_ci#define CODE_START_ADDR ((UINTPTR)__section_begin(CODE_SECTION_NAME)) 623d8536b4Sopenharmony_ci#define CODE_END_ADDR ((UINTPTR)__section_end(CODE_SECTION_NAME)) 633d8536b4Sopenharmony_ci#define CSTACK_START_ADDR ((UINTPTR)__section_begin(CSTACK_SECTION_NAME)) 643d8536b4Sopenharmony_ci#define CSTACK_END_ADDR ((UINTPTR)__section_end(CSTACK_SECTION_NAME)) 653d8536b4Sopenharmony_ci#elif defined(__CC_ARM) || defined(__CLANG_ARM) 663d8536b4Sopenharmony_ci/* The default code section name is ER_IROM1 */ 673d8536b4Sopenharmony_ci#define CODE_SECTION_NAME ER_IROM1 683d8536b4Sopenharmony_ci/* The default C stack section name is STACK */ 693d8536b4Sopenharmony_ci#define CSTACK_SECTION_NAME STACK 703d8536b4Sopenharmony_ci 713d8536b4Sopenharmony_ci#define SECTION_START(_name_) _name_##$$Base 723d8536b4Sopenharmony_ci#define SECTION_END(_name_) _name_##$$Limit 733d8536b4Sopenharmony_ci#define CSTACK_SECTION_START(_name_) SECTION_START(_name_) 743d8536b4Sopenharmony_ci#define CSTACK_SECTION_END(_name_) SECTION_END(_name_) 753d8536b4Sopenharmony_ci 763d8536b4Sopenharmony_ci#define IMAGE_SECTION_START(_name_) Image$$##_name_##$$Base 773d8536b4Sopenharmony_ci#define IMAGE_SECTION_END(_name_) Image$$##_name_##$$Limit 783d8536b4Sopenharmony_ci#define CODE_SECTION_START(_name_) IMAGE_SECTION_START(_name_) 793d8536b4Sopenharmony_ci#define CODE_SECTION_END(_name_) IMAGE_SECTION_END(_name_) 803d8536b4Sopenharmony_ci 813d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_START(CSTACK_SECTION_NAME); 823d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_END(CSTACK_SECTION_NAME); 833d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_START(CODE_SECTION_NAME); 843d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_END(CODE_SECTION_NAME); 853d8536b4Sopenharmony_ci 863d8536b4Sopenharmony_ci/* Default only one code section. In fact, there may be more than one. 873d8536b4Sopenharmony_ci You can define more than one and redefine the OsStackDataIsCodeAddr function 883d8536b4Sopenharmony_ci to support searching in multiple code sections */ 893d8536b4Sopenharmony_ci#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START(CODE_SECTION_NAME)) 903d8536b4Sopenharmony_ci#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END(CODE_SECTION_NAME)) 913d8536b4Sopenharmony_ci#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START(CSTACK_SECTION_NAME)) 923d8536b4Sopenharmony_ci#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END(CSTACK_SECTION_NAME)) 933d8536b4Sopenharmony_ci#elif defined(__GNUC__) 943d8536b4Sopenharmony_ci/* The default code section start address */ 953d8536b4Sopenharmony_ci#define CODE_SECTION_START _stext 963d8536b4Sopenharmony_ci/* The default code section end address */ 973d8536b4Sopenharmony_ci#define CODE_SECTION_END _etext 983d8536b4Sopenharmony_ci/* The default C stack section start address */ 993d8536b4Sopenharmony_ci#define CSTACK_SECTION_START _sstack 1003d8536b4Sopenharmony_ci/* The default C stack section end address */ 1013d8536b4Sopenharmony_ci#define CSTACK_SECTION_END _estack 1023d8536b4Sopenharmony_ci 1033d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_START; 1043d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_END; 1053d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_START; 1063d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_END; 1073d8536b4Sopenharmony_ci 1083d8536b4Sopenharmony_ci/* Default only one code section. In fact, there may be more than one. 1093d8536b4Sopenharmony_ci You can define more than one and redefine the OsStackDataIsCodeAddr function 1103d8536b4Sopenharmony_ci to support searching in multiple code sections */ 1113d8536b4Sopenharmony_ci#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START) 1123d8536b4Sopenharmony_ci#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END) 1133d8536b4Sopenharmony_ci#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START) 1143d8536b4Sopenharmony_ci#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END) 1153d8536b4Sopenharmony_ci#else 1163d8536b4Sopenharmony_ci#error Unknown compiler. 1173d8536b4Sopenharmony_ci#endif 1183d8536b4Sopenharmony_ci#elif (LOSCFG_BACKTRACE_TYPE == 2) || (LOSCFG_BACKTRACE_TYPE == 3) 1193d8536b4Sopenharmony_ci#if defined(__GNUC__) 1203d8536b4Sopenharmony_ci/* The default code section start address */ 1213d8536b4Sopenharmony_ci#define CODE_SECTION_START __text_start 1223d8536b4Sopenharmony_ci/* The default code section end address */ 1233d8536b4Sopenharmony_ci#define CODE_SECTION_END __text_end 1243d8536b4Sopenharmony_ci/* The default C stack section start address */ 1253d8536b4Sopenharmony_ci#define CSTACK_SECTION_START __except_stack_top 1263d8536b4Sopenharmony_ci/* The default C stack section end address */ 1273d8536b4Sopenharmony_ci#define CSTACK_SECTION_END __start_and_irq_stack_top 1283d8536b4Sopenharmony_ci 1293d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_START; 1303d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_END; 1313d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_START; 1323d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_END; 1333d8536b4Sopenharmony_ci 1343d8536b4Sopenharmony_ci#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START) 1353d8536b4Sopenharmony_ci#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END) 1363d8536b4Sopenharmony_ci#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START) 1373d8536b4Sopenharmony_ci#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END) 1383d8536b4Sopenharmony_ci#else 1393d8536b4Sopenharmony_ci#error Unknown compiler. 1403d8536b4Sopenharmony_ci#endif 1413d8536b4Sopenharmony_ci#elif (LOSCFG_BACKTRACE_TYPE == 4) 1423d8536b4Sopenharmony_ci/* The default code section start address */ 1433d8536b4Sopenharmony_ci#define CODE_SECTION_START __text_start 1443d8536b4Sopenharmony_ci/* The default code section end address */ 1453d8536b4Sopenharmony_ci#define CODE_SECTION_END __text_end 1463d8536b4Sopenharmony_ci/* The default C stack section start address */ 1473d8536b4Sopenharmony_ci#define CSTACK_SECTION_START __init_stack_s 1483d8536b4Sopenharmony_ci/* The default C stack section end address */ 1493d8536b4Sopenharmony_ci#define CSTACK_SECTION_END __init_stack_e 1503d8536b4Sopenharmony_ci 1513d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_START; 1523d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_END; 1533d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_START; 1543d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_END; 1553d8536b4Sopenharmony_ci 1563d8536b4Sopenharmony_ci#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START) 1573d8536b4Sopenharmony_ci#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END) 1583d8536b4Sopenharmony_ci#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START) 1593d8536b4Sopenharmony_ci#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END) 1603d8536b4Sopenharmony_ci 1613d8536b4Sopenharmony_ci#define VIR_TEXT_ADDR_MASK 0x80000000 1623d8536b4Sopenharmony_ci#define TEXT_ADDR_MASK 0x40000000 1633d8536b4Sopenharmony_ci#define RA_OFFSET 16 1643d8536b4Sopenharmony_ci#define SP_OFFSET 12 1653d8536b4Sopenharmony_ci#define WINDOW_INCREMENT_SHIFT 2 1663d8536b4Sopenharmony_ci 1673d8536b4Sopenharmony_ciUINT32 HalBackTraceGet(UINTPTR sp, UINT32 retAddr, UINTPTR *callChain, UINT32 maxDepth, UINT32 jumpCount); 1683d8536b4Sopenharmony_ci#elif (LOSCFG_BACKTRACE_TYPE == 5) 1693d8536b4Sopenharmony_ci/* The default code section start address */ 1703d8536b4Sopenharmony_ci#define CODE_SECTION_START __text_start 1713d8536b4Sopenharmony_ci/* The default code section end address */ 1723d8536b4Sopenharmony_ci#define CODE_SECTION_END __text_end 1733d8536b4Sopenharmony_ci/* The default C stack section start address */ 1743d8536b4Sopenharmony_ci#define CSTACK_SECTION_START __init_stack_s 1753d8536b4Sopenharmony_ci/* The default C stack section end address */ 1763d8536b4Sopenharmony_ci#define CSTACK_SECTION_END __ram_end 1773d8536b4Sopenharmony_ci 1783d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_START; 1793d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_END; 1803d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_START; 1813d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_END; 1823d8536b4Sopenharmony_ci 1833d8536b4Sopenharmony_ci#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START) 1843d8536b4Sopenharmony_ci#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END) 1853d8536b4Sopenharmony_ci#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START) 1863d8536b4Sopenharmony_ci#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END) 1873d8536b4Sopenharmony_ci 1883d8536b4Sopenharmony_ci#define ALGIN_CODE 2 1893d8536b4Sopenharmony_ci#define STACK_OFFSET 4 1903d8536b4Sopenharmony_ci#elif (LOSCFG_BACKTRACE_TYPE == 6) 1913d8536b4Sopenharmony_ciextern CHAR *__svc_stack; 1923d8536b4Sopenharmony_ciextern CHAR *__svc_stack_top; 1933d8536b4Sopenharmony_ci/* The default code section start address */ 1943d8536b4Sopenharmony_ci#define CODE_SECTION_START __text_start 1953d8536b4Sopenharmony_ci/* The default code section end address */ 1963d8536b4Sopenharmony_ci#define CODE_SECTION_END __text_end 1973d8536b4Sopenharmony_ci/* The default C stack section start address */ 1983d8536b4Sopenharmony_ci#define CSTACK_SECTION_START __svc_stack 1993d8536b4Sopenharmony_ci/* The default C stack section end address */ 2003d8536b4Sopenharmony_ci#define CSTACK_SECTION_END __svc_stack_top 2013d8536b4Sopenharmony_ci 2023d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_START; 2033d8536b4Sopenharmony_ciextern CHAR *CODE_SECTION_END; 2043d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_START; 2053d8536b4Sopenharmony_ciextern CHAR *CSTACK_SECTION_END; 2063d8536b4Sopenharmony_ci 2073d8536b4Sopenharmony_ci/* Default only one code section. In fact, there may be more than one. 2083d8536b4Sopenharmony_ci You can define more than one and redefine the OsStackDataIsCodeAddr function 2093d8536b4Sopenharmony_ci to support searching in multiple code sections */ 2103d8536b4Sopenharmony_ci#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START) 2113d8536b4Sopenharmony_ci#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END) 2123d8536b4Sopenharmony_ci#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START) 2133d8536b4Sopenharmony_ci#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END) 2143d8536b4Sopenharmony_ci 2153d8536b4Sopenharmony_ci#endif 2163d8536b4Sopenharmony_ci 2173d8536b4Sopenharmony_ci/* This function is currently used to register the memory leak check hook, 2183d8536b4Sopenharmony_ci other uses do not need to be called temporarily. */ 2193d8536b4Sopenharmony_ciVOID OsBackTraceInit(VOID); 2203d8536b4Sopenharmony_ci 2213d8536b4Sopenharmony_ci/* This function is used to print the function call stack. */ 2223d8536b4Sopenharmony_ciVOID LOS_BackTrace(VOID); 2233d8536b4Sopenharmony_ci 2243d8536b4Sopenharmony_ci/* This function is used to record the function call stack. */ 2253d8536b4Sopenharmony_ciVOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP); 2263d8536b4Sopenharmony_ci#endif 2273d8536b4Sopenharmony_ci 2283d8536b4Sopenharmony_ci#ifdef __cplusplus 2293d8536b4Sopenharmony_ci#if __cplusplus 2303d8536b4Sopenharmony_ci} 2313d8536b4Sopenharmony_ci#endif /* __cplusplus */ 2323d8536b4Sopenharmony_ci#endif /* __cplusplus */ 2333d8536b4Sopenharmony_ci#endif 2343d8536b4Sopenharmony_ci 235