Developer World
Spresense SDK Library v3.2.0-ebc0364
AssertInfo.h
1/****************************************************************************
2 * modules/include/memutils/message/AssertInfo.h
3 *
4 * Copyright 2018 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36#ifndef ASSERT_INFO_H_INCLUDED
37#define ASSERT_INFO_H_INCLUDED
38
39#ifdef _ITRON4
40/* The value of SAVESZ is determined by the definition of
41 * _KERNEL_FLOATING_POINT_ in kernel_id.h
42 * Therefore, kernel_id.h needs to be included before mips.h and mips_regs.h
43 */
44
45#include "kernel.h"
46#ifdef MCB4357
47/* In the MCB 4357_1.01 version of SailOS, since SAVESZ is undefined,
48 * SAVESIZE of the same meaning.
49 * Refer to the value of kernel/cortex-mx/stack.c and define here.
50 */
51
52#if (defined(__TARGET_FPU_VFP) || defined(__ARMVFP__))
53#define SAVESZ (196)
54#else
55#define SAVESZ (64)
56#endif
57#endif /* MCB4357 */
58#endif /* _ITRON4 */
59
60#define SAVESZ (196)
61
62
63#include "memutils/common_utils/common_types.h"
64//#include "dmp_id.h"
65
66#ifndef EVA
67#define DBG_P(...) printf("Assertion information: " __VA_ARGS__)
68#else
69#define DBG_P(...)
70#endif
71
72/* If the DMP_ASSERT_INFO entry is undefined in dmp_layout.conf,
73 * it is defined as a null statement.
74 */
75
76#ifndef DMP_ASSERT_INFO_NUM
77#define DMP_ASSERT_INFO_SEQ_LOG(p)
78#endif
79
80/* By this ID, switch display method of LogAnalyzer. */
81
82enum AssertLogId {
83 AssertIdLocation = 0,
84 AssertIdException = 1,
85 AssertIdOsIllegal = 2,
86 AssertIdOsStackIllegal = 3,
87 AssertIdFence = 4,
88 AssertIdBadParam = 5,
89 AssertIdTypeUnmatch = 6,
90 AssertIdSizeError = 7,
91 AssertIdBadMsgQueState = 8,
92 AssertIdMemSegLeak = 9,
93 AssertIdOther = 10,
94}; /* enum AssertLogId */
95
96/*****************************************************************
97 * Base class of assert information
98 *****************************************************************/
100 uint8_t m_log_id;
101 uint8_t m_task_id;
102 uint16_t m_body_size; /* Subsequent data length. */
103public:
104 AssertInfoBase(AssertLogId log_id, uint16_t log_size) :
105 m_log_id(log_id),
106// m_task_id(DMP_GET_TASK_ID),
107 m_task_id(0),
108 m_body_size(log_size - sizeof(*this)) {}
109}; /* struct AssertInfoBase */
110
111/*****************************************************************
112 * Class recording the assert position
113 *****************************************************************/
115 uint32_t m_line;
116 uint32_t m_ret_addr;
117 char m_filename[128];
118public:
119 AssertLocationLog(const char* filename, int line, void* ret_addr) :
120 AssertInfoBase(AssertIdLocation, sizeof(*this)),
121 m_line(line),
122 m_ret_addr(reinterpret_cast<uint32_t>(ret_addr)),
123 m_filename()
124 {
125 size_t n = strlen(filename);
126 if (n < sizeof(m_filename)) {
127 strcpy(m_filename, filename);
128 } else {
129 strcpy(m_filename, filename + n - sizeof(m_filename) + 1);
130 }
131 DBG_P("TaskID=%d, file=%s, line=%ld, return addr=%08lx\n", m_task_id, m_filename, m_line, m_ret_addr);
132 DMP_ASSERT_INFO_SEQ_LOG(*this);
133 }
134}; /* struct AssertLocationLog */
135
136#ifdef _ITRON4
137const uint32_t RegSaveSize = SAVESZ; /* arm=64, mips=160 or 296, cortex=64 or 196 */
138#else /* #ifdef _ITRON4 */
139#ifdef FPU_REG_STORE
140const uint32_t RegSaveSize = 284; /* (31 + 4 + 36) * 4; */
141#else /* #ifdef FPU_REG_STORE */
142const uint32_t RegSaveSize = 140; /* (31 + 4) * 4 */
143#endif /* #ifdef FPU_REG_STORE */
144#endif /* #ifdef _ITRON4 */
145
146/*****************************************************************
147 * Class that stores exception information
148 *****************************************************************/
150 uint32_t m_cause;
151 uint32_t m_epc;
152 uint32_t m_sr;
153 uint32_t m_bad_vaddr;
154 uint32_t m_user_sp;
155 uint8_t m_uStk[256];
156 uint8_t m_kStk[RegSaveSize];
157public:
158 AssertExceptionLog(uint32_t cause, uint32_t epc, uint32_t sr, uint32_t bad_vaddr,
159 const uint32_t* uStk = NULL, const uint32_t* kStk = NULL) :
160 AssertInfoBase(AssertIdException, sizeof(*this)),
161 m_cause(cause),
162 m_epc(epc),
163 m_sr(sr),
164 m_bad_vaddr(bad_vaddr),
165 m_user_sp(reinterpret_cast<uint32_t>(uStk))
166 {
167 if (uStk) {
168 memcpy(m_uStk, uStk, sizeof(m_uStk));
169 } else {
170 /* If the stack frame address is not specified,
171 * reduce the effective size.
172 */
173
174 m_body_size -= sizeof(m_uStk);
175 }
176 if (kStk) {
177 memcpy(m_kStk, kStk, sizeof(m_kStk));
178 } else {
179 m_body_size -= sizeof(m_kStk);
180 }
181 DBG_P("TaskID=%d, Cause=%08lx, EPC=%08lx, SR=%08lx\n", m_task_id, m_cause, m_epc, m_sr);
182 DMP_ASSERT_INFO_SEQ_LOG(*this);
183 }
184}; /* struct AssertExceptionLog */
185
186/*****************************************************************
187 * Class for storing fence check error parameters and fence contents
188 *****************************************************************/
190 uint32_t* m_addr;
191 uint32_t m_data[16]; /* Stack/Heap Fence is 16bytes.
192 * Pool Fence is 64bytes.
193 */
194public:
195 explicit AssertFenceLog(uint32_t* addr) :
196 AssertInfoBase(AssertIdFence, sizeof(*this)),
197 m_addr(addr)
198 {
199 for (size_t i = 0; i < COUNT_OF(m_data); i++) {
200 m_data[i] = addr[i];
201 }
202 DBG_P("BadAddr=%p, Data=%08lx, %08lx, %08lx, %08lx\n", m_addr, m_data[0], m_data[1], m_data[2], m_data[3]);
203 DMP_ASSERT_INFO_SEQ_LOG(*this);
204 }
205}; /* struct AssertFenceLog */
206
207/*****************************************************************
208 * Class for storing parameters when asserting
209 *****************************************************************/
211 uint32_t m_param[4];
212public:
213 AssertParamLog(AssertLogId id, uint32_t p0, uint32_t p1 = 0, uint32_t p2 = 0, uint32_t p3 = 0) :
214 AssertInfoBase(id, sizeof(*this))
215 {
216 m_param[0] = p0; m_param[1] = p1; m_param[2] = p2; m_param[3] = p3;
217 DBG_P("TaskID=%d, AssertID=%u, param=%08lx, %08lx, %08lx, %08lx\n", m_task_id, id, p0, p1, p2, p3);
218 DMP_ASSERT_INFO_SEQ_LOG(*this);
219 }
220}; /* struct AssertParamLog */
221
222#undef DBG_P
223
224#endif /* ASSERT_INFO_H_INCLUDED */
Definition: AssertInfo.h:149
Definition: AssertInfo.h:189
Definition: AssertInfo.h:99
Definition: AssertInfo.h:114
Definition: AssertInfo.h:210