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