1 /*
2 * Percepio Trace Recorder for Tracealyzer v4.6.6
3 * Copyright 2021 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 0
26
27 typedef struct TraceAssertInfo
28 {
29 TraceEntryHandle_t xEntry;
30 } TraceAssertInfo_t;
31
32 static TraceAssertInfo_t* pxAssertInfo;
33
xTraceAssertInitialize(TraceAssertBuffer_t * pxBuffer)34 traceResult xTraceAssertInitialize(TraceAssertBuffer_t *pxBuffer)
35 {
36 TRC_ASSERT_EQUAL_SIZE(TraceAssertBuffer_t, TraceAssertInfo_t);
37
38 TRC_ASSERT(pxBuffer != 0);
39
40 pxAssertInfo = (TraceAssertInfo_t*)pxBuffer;
41 pxAssertInfo->xEntry = 0;
42
43 xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_ASSERT);
44
45 return TRC_SUCCESS;
46 }
47
prvTraceAssertCreate(const char * szFilePath,TraceUnsignedBaseType_t uxLineNumber)48 void prvTraceAssertCreate(const char* szFilePath, TraceUnsignedBaseType_t uxLineNumber)
49 {
50 TraceBaseType_t i, xLength;
51 TraceUnsignedBaseType_t uxEntryLineNumber = 0xFFFFFFFF;
52 static TraceUnsignedBaseType_t uxRecursionGuard = 0;
53
54 if (uxRecursionGuard == 0)
55 {
56 /* Recursion can only get here once */
57 uxRecursionGuard = 1;
58
59 if (!xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ASSERT))
60 {
61 return;
62 }
63
64 if (pxAssertInfo->xEntry == 0)
65 {
66 if (xTraceEntryCreate(&pxAssertInfo->xEntry) == TRC_FAIL)
67 {
68 return;
69 }
70 }
71
72 xTraceEntryGetState(pxAssertInfo->xEntry, TRC_ASSERT_STATE_INDEX_LINE_NUMBER, &uxEntryLineNumber);
73
74 /* We only save the first ASSERT information */
75 if (uxEntryLineNumber == 0)
76 {
77 /* Find length */
78 for (i = 0; (szFilePath[i] != 0) && (i < 128); i++) {}
79
80 xLength = i;
81
82 /* Find last slash or backslash */
83 for (i = xLength - 1; (i >= 0) && ((szFilePath[i] != '\\') && (szFilePath[i] != '/')); i--) {}
84
85 /* We treat the entry as an object and set it's name and state */
86 xTraceObjectSetName((TraceObjectHandle_t)pxAssertInfo->xEntry, &szFilePath[i + 1]);
87 xTraceObjectSetState((TraceObjectHandle_t)pxAssertInfo->xEntry, uxLineNumber);
88
89 xTraceError(TRC_ERROR_ASSERT);
90 }
91 }
92
93 xTraceDiagnosticsIncrease(TRC_DIAGNOSTICS_ASSERTS_TRIGGERED);
94 }
95
xTraceAssertGet(TraceStringHandle_t * pxFileNameStringHandle,TraceUnsignedBaseType_t * puxLineNumber)96 traceResult xTraceAssertGet(TraceStringHandle_t *pxFileNameStringHandle, TraceUnsignedBaseType_t *puxLineNumber)
97 {
98 TRC_ASSERT(pxFileNameStringHandle != 0);
99
100 TRC_ASSERT(puxLineNumber != 0);
101
102 if (!xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ASSERT))
103 {
104 return TRC_FAIL;
105 }
106
107 *puxLineNumber = 0;
108 xTraceEntryGetState(pxAssertInfo->xEntry, TRC_ASSERT_STATE_INDEX_LINE_NUMBER, puxLineNumber);
109
110 if (*puxLineNumber == 0)
111 {
112 return TRC_FAIL;
113 }
114
115 /* The string handle can be set to the entry handle */
116 *pxFileNameStringHandle = (TraceStringHandle_t)pxAssertInfo->xEntry;
117
118 return TRC_SUCCESS;
119 }
120
121 #endif /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
122
123 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
124
125 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
126