aboutsummaryrefslogtreecommitdiff
path: root/quantum/variable_trace.c
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/variable_trace.c
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'quantum/variable_trace.c')
-rw-r--r--quantum/variable_trace.c77
1 files changed, 37 insertions, 40 deletions
diff --git a/quantum/variable_trace.c b/quantum/variable_trace.c
index 713747cfc..00562bc92 100644
--- a/quantum/variable_trace.c
+++ b/quantum/variable_trace.c
@@ -19,26 +19,25 @@
19#include <string.h> 19#include <string.h>
20 20
21#ifdef NO_PRINT 21#ifdef NO_PRINT
22#error "You need undef NO_PRINT to use the variable trace feature" 22# error "You need undef NO_PRINT to use the variable trace feature"
23#endif 23#endif
24 24
25#ifndef CONSOLE_ENABLE 25#ifndef CONSOLE_ENABLE
26#error "The console needs to be enabled in the makefile to use the variable trace feature" 26# error "The console needs to be enabled in the makefile to use the variable trace feature"
27#endif 27#endif
28 28
29
30#define NUM_TRACED_VARIABLES 1 29#define NUM_TRACED_VARIABLES 1
31#ifndef MAX_VARIABLE_TRACE_SIZE 30#ifndef MAX_VARIABLE_TRACE_SIZE
32 #define MAX_VARIABLE_TRACE_SIZE 4 31# define MAX_VARIABLE_TRACE_SIZE 4
33#endif 32#endif
34 33
35typedef struct { 34typedef struct {
36 const char* name; 35 const char* name;
37 void* addr; 36 void* addr;
38 unsigned size; 37 unsigned size;
39 const char* func; 38 const char* func;
40 int line; 39 int line;
41 uint8_t last_value[MAX_VARIABLE_TRACE_SIZE]; 40 uint8_t last_value[MAX_VARIABLE_TRACE_SIZE];
42 41
43} traced_variable_t; 42} traced_variable_t;
44 43
@@ -48,18 +47,17 @@ void add_traced_variable(const char* name, void* addr, unsigned size, const char
48 verify_traced_variables(func, line); 47 verify_traced_variables(func, line);
49 if (size > MAX_VARIABLE_TRACE_SIZE) { 48 if (size > MAX_VARIABLE_TRACE_SIZE) {
50#if defined(__AVR__) 49#if defined(__AVR__)
51 xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size); 50 xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size);
52#else 51#else
53 xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size); 52 xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size);
54#endif 53#endif
55 size = MAX_VARIABLE_TRACE_SIZE; 54 size = MAX_VARIABLE_TRACE_SIZE;
56 } 55 }
57 int index = -1; 56 int index = -1;
58 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { 57 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
59 if (index == -1 && traced_variables[i].addr == NULL){ 58 if (index == -1 && traced_variables[i].addr == NULL) {
60 index = i; 59 index = i;
61 } 60 } else if (strcmp_P(name, traced_variables[i].name) == 0) {
62 else if (strcmp_P(name, traced_variables[i].name)==0) {
63 index = i; 61 index = i;
64 break; 62 break;
65 } 63 }
@@ -71,19 +69,18 @@ void add_traced_variable(const char* name, void* addr, unsigned size, const char
71 } 69 }
72 70
73 traced_variable_t* t = &traced_variables[index]; 71 traced_variable_t* t = &traced_variables[index];
74 t->name = name; 72 t->name = name;
75 t->addr = addr; 73 t->addr = addr;
76 t->size = size; 74 t->size = size;
77 t->func = func; 75 t->func = func;
78 t->line = line; 76 t->line = line;
79 memcpy(&t->last_value[0], addr, size); 77 memcpy(&t->last_value[0], addr, size);
80
81} 78}
82 79
83void remove_traced_variable(const char* name, const char* func, int line) { 80void remove_traced_variable(const char* name, const char* func, int line) {
84 verify_traced_variables(func, line); 81 verify_traced_variables(func, line);
85 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { 82 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
86 if (strcmp_P(name, traced_variables[i].name)==0) { 83 if (strcmp_P(name, traced_variables[i].name) == 0) {
87 traced_variables[i].name = 0; 84 traced_variables[i].name = 0;
88 traced_variables[i].addr = NULL; 85 traced_variables[i].addr = NULL;
89 break; 86 break;
@@ -95,29 +92,29 @@ void verify_traced_variables(const char* func, int line) {
95 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { 92 for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
96 traced_variable_t* t = &traced_variables[i]; 93 traced_variable_t* t = &traced_variables[i];
97 if (t->addr != NULL && t->name != NULL) { 94 if (t->addr != NULL && t->name != NULL) {
98 if (memcmp(t->last_value, t->addr, t->size)!=0){ 95 if (memcmp(t->last_value, t->addr, t->size) != 0) {
99#if defined(__AVR__) 96#if defined(__AVR__)
100 xprintf("Traced variable \"%S\" has been modified\n", t->name); 97 xprintf("Traced variable \"%S\" has been modified\n", t->name);
101 xprintf("Between %S:%d\n", t->func, t->line); 98 xprintf("Between %S:%d\n", t->func, t->line);
102 xprintf("And %S:%d\n", func, line); 99 xprintf("And %S:%d\n", func, line);
103 100
104#else 101#else
105 xprintf("Traced variable \"%s\" has been modified\n", t->name); 102 xprintf("Traced variable \"%s\" has been modified\n", t->name);
106 xprintf("Between %s:%d\n", t->func, t->line); 103 xprintf("Between %s:%d\n", t->func, t->line);
107 xprintf("And %s:%d\n", func, line); 104 xprintf("And %s:%d\n", func, line);
108#endif 105#endif
109 xprintf("Previous value "); 106 xprintf("Previous value ");
110 for (int j=0; j<t->size;j++) { 107 for (int j = 0; j < t->size; j++) {
111 print_hex8(t->last_value[j]); 108 print_hex8(t->last_value[j]);
112 } 109 }
113 xprintf("\nNew value "); 110 xprintf("\nNew value ");
114 uint8_t* addr = (uint8_t*)(t->addr); 111 uint8_t* addr = (uint8_t*)(t->addr);
115 for (int j=0; j<t->size;j++) { 112 for (int j = 0; j < t->size; j++) {
116 print_hex8(addr[j]); 113 print_hex8(addr[j]);
117 } 114 }
118 xprintf("\n"); 115 xprintf("\n");
119 memcpy(t->last_value, addr, t->size); 116 memcpy(t->last_value, addr, t->size);
120 } 117 }
121 } 118 }
122 119
123 t->func = func; 120 t->func = func;