1 /*
2 * Percepio Trace Recorder for Tracealyzer v4.8.1
3 * Copyright 2023 Percepio AB
4 * www.percepio.com
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * The implementation for errors.
9 */
10
11 #include <trcRecorder.h>
12
13 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
14
15 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
16
17 #if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
18
19 #if (defined(TRC_CFG_TEST_MODE) && (TRC_CFG_TEST_MODE) == 1)
20
21 extern inline TraceBaseType_t prvTraceAssertCheckCondition(TraceBaseType_t condition);
22
23 #endif
24
25 #define TRC_ASSERT_STATE_INDEX_LINE_NUMBER 0u
26
27 static TraceAssertData_t* pxAssertData TRC_CFG_RECORDER_DATA_ATTRIBUTE;
28
xTraceAssertInitialize(TraceAssertData_t * pxBuffer)29 traceResult xTraceAssertInitialize(TraceAssertData_t *pxBuffer)
30 {
31 TRC_ASSERT(pxBuffer != (void*)0);
32
33 pxAssertData = pxBuffer;
34 pxAssertData->xEntry = 0;
35
36 xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_ASSERT);
37
38 return TRC_SUCCESS;
39 }
40
41 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
prvTraceAssertCreate(const char * szFilePath,TraceUnsignedBaseType_t uxLineNumber)42 void prvTraceAssertCreate(const char* szFilePath, TraceUnsignedBaseType_t uxLineNumber)
43 {
44 TraceBaseType_t i, xLength;
45 TraceUnsignedBaseType_t uxEntryLineNumber = 0xFFFFFFFFUL;
46 static TraceUnsignedBaseType_t uxRecursionGuard = 0u;
47
48 if (uxRecursionGuard == 0u)
49 {
50 /* Recursion can only get here once */
51 uxRecursionGuard = 1u;
52
53 if (xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ASSERT) == 0U)
54 {
55 return;
56 }
57
58 if (pxAssertData->xEntry == 0)
59 {
60 if (xTraceEntryCreate(&pxAssertData->xEntry) == TRC_FAIL)
61 {
62 return;
63 }
64 }
65
66 (void)xTraceEntryGetState(pxAssertData->xEntry, TRC_ASSERT_STATE_INDEX_LINE_NUMBER, &uxEntryLineNumber);
67
68 /* We only save the first ASSERT information */
69 if (uxEntryLineNumber == 0u)
70 {
71 /* Find length */
72 for (i = 0; (szFilePath[i] != (char)0) && (i < 128); i++) {} /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/ /*cstat !MISRAC2004-17.4_b We need to access every character in the string*/
73
74 xLength = i;
75
76 /* Find last slash or backslash */
77 for (i = xLength - 1; (i >= 0) && ((szFilePath[i] != '\\') && (szFilePath[i] != '/')); i--) {} /*cstat !MISRAC2004-17.4_b We need to access every character in the string*/
78
79 /* We treat the entry as an object and set it's name and state */
80 (void)xTraceObjectSetName((TraceObjectHandle_t)pxAssertData->xEntry, &szFilePath[i + 1]); /*cstat !MISRAC2004-17.4_b We need to access a specific character in the string*/
81 (void)xTraceObjectSetState((TraceObjectHandle_t)pxAssertData->xEntry, uxLineNumber);
82
83 (void)xTraceError(TRC_ERROR_ASSERT);
84 }
85 }
86
87 (void)xTraceDiagnosticsIncrease(TRC_DIAGNOSTICS_ASSERTS_TRIGGERED);
88 }
89
xTraceAssertGet(TraceStringHandle_t * pxFileNameStringHandle,TraceUnsignedBaseType_t * puxLineNumber)90 traceResult xTraceAssertGet(TraceStringHandle_t *pxFileNameStringHandle, TraceUnsignedBaseType_t *puxLineNumber)
91 {
92 TRC_ASSERT(pxFileNameStringHandle != (void*)0);
93
94 TRC_ASSERT(puxLineNumber != (void*)0);
95
96 if (xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ASSERT) == 0U)
97 {
98 return TRC_FAIL;
99 }
100
101 *puxLineNumber = 0u;
102 (void)xTraceEntryGetState(pxAssertData->xEntry, TRC_ASSERT_STATE_INDEX_LINE_NUMBER, puxLineNumber);
103
104 if (*puxLineNumber == 0u)
105 {
106 return TRC_FAIL;
107 }
108
109 /* The string handle can be set to the entry handle */
110 *pxFileNameStringHandle = (TraceStringHandle_t)pxAssertData->xEntry;
111
112 return TRC_SUCCESS;
113 }
114
115 #endif /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
116
117 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
118
119 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
120