From 5b2e455d3b71bfb90754930d1f22d3e8ce98b927 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Mon, 10 Oct 2016 00:46:20 +0700 Subject: Unicode map framework. Allow unicode up to 0xFFFFF using separate mapping table --- build_keyboard.mk | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'build_keyboard.mk') diff --git a/build_keyboard.mk b/build_keyboard.mk index 03a69b1464..282adcb118 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -153,6 +153,11 @@ ifeq ($(strip $(UCIS_ENABLE)), yes) UNICODE_ENABLE = yes endif +ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) + OPT_DEFS += -DUNICODEMAP_ENABLE + UNICODE_ENABLE = yes +endif + ifeq ($(strip $(UNICODE_ENABLE)), yes) OPT_DEFS += -DUNICODE_ENABLE SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c -- cgit v1.2.3 From f519b94be7086852f2afe4ec248786b47968f7ff Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 6 Nov 2016 21:57:26 +0200 Subject: Add variable trace For debugging changes to variables, either normally or as a result of a memory corruption. --- build_keyboard.mk | 2 + quantum/variable_trace.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 quantum/variable_trace.c (limited to 'build_keyboard.mk') diff --git a/build_keyboard.mk b/build_keyboard.mk index 282adcb118..461b17cd77 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -180,6 +180,8 @@ ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) VAPTH += $(SERIAL_PATH) endif +SRC += $(QUANTUM_DIR)/variable_trace.c + # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/quantum/variable_trace.c b/quantum/variable_trace.c new file mode 100644 index 0000000000..dfa37bdef5 --- /dev/null +++ b/quantum/variable_trace.c @@ -0,0 +1,108 @@ +#include "variable_trace.h" +#include +#include + +#ifdef NO_PRINT +#error "You need undef NO_PRINT to use the variable trace feature" +#endif + +#ifndef CONSOLE_ENABLE +#error "The console needs to be enabled in the makefile to use the variable trace feature" +#endif + + +#define NUM_TRACED_VARIABLES 1 +#define MAX_TRACE_SIZE 4 + +typedef struct { + const char* name; + void* addr; + unsigned size; + const char* func; + int line; + uint8_t last_value[MAX_TRACE_SIZE]; + +} traced_variable_t; + +static traced_variable_t traced_variables[NUM_TRACED_VARIABLES]; + +void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line) { + verify_traced_variables(func, line); + if (size > MAX_TRACE_SIZE) { +#if defined(__AVR__) + xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size); +#else + xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size); +#endif + size = MAX_TRACE_SIZE; + } + int index = -1; + for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { + if (index == -1 && traced_variables[i].addr == NULL){ + index = i; + } + else if (strcmp_P(name, traced_variables[i].name)==0) { + index = i; + break; + } + } + + if (index == -1) { + xprintf("You can only trace %d variables at the same time\n", NUM_TRACED_VARIABLES); + return; + } + + traced_variable_t* t = &traced_variables[index]; + t->name = name; + t->addr = addr; + t->size = size; + t->func = func; + t->line = line; + memcpy(&t->last_value[0], addr, size); + +} + +void remove_traced_variable(const char* name, const char* func, int line) { + verify_traced_variables(func, line); + for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { + if (strcmp_P(name, traced_variables[i].name)==0) { + traced_variables[i].name = 0; + traced_variables[i].addr = NULL; + break; + } + } +} + +void verify_traced_variables(const char* func, int line) { + for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { + traced_variable_t* t = &traced_variables[i]; + if (t->addr != NULL && t->name != NULL) { + if (memcmp(t->last_value, t->addr, t->size)!=0){ +#if defined(__AVR__) + xprintf("Traced variable \"%S\" has been modified\n", t->name); + xprintf("Between %S:%d\n", t->func, t->line); + xprintf("And %S:%d\n", func, line); + +#else + xprintf("Traced variable \"%s\" has been modified\n", t->name); + xprintf("Between %s:%d\n", t->func, t->line); + xprintf("And %s:%d\n", func, line); +#endif + xprintf("Previous value "); + for (int j=0; jsize;j++) { + print_hex8(t->last_value[j]); + } + xprintf("\nNew value "); + uint8_t* addr = (uint8_t*)(t->addr); + for (int j=0; jsize;j++) { + print_hex8(addr[j]); + } + xprintf("\n"); + memcpy(t->last_value, addr, t->size); + } + } + + t->func = func; + t->line = line; + } +} -- cgit v1.2.3 From a377017c95b826d83ac7a46ef176d39a58294b44 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 6 Nov 2016 22:11:24 +0200 Subject: Add possibility to control variable trace from make --- build_keyboard.mk | 8 +++++++- quantum/variable_trace.c | 10 ++++++---- quantum/variable_trace.h | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 quantum/variable_trace.h (limited to 'build_keyboard.mk') diff --git a/build_keyboard.mk b/build_keyboard.mk index 461b17cd77..61aebf3935 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -180,7 +180,13 @@ ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) VAPTH += $(SERIAL_PATH) endif -SRC += $(QUANTUM_DIR)/variable_trace.c +ifneq ($(strip $(VARIABLE_TRACE)),) + SRC += $(QUANTUM_DIR)/variable_trace.c + OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE)) +ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),) + OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE)) +endif +endif # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/quantum/variable_trace.c b/quantum/variable_trace.c index dfa37bdef5..de580244c3 100644 --- a/quantum/variable_trace.c +++ b/quantum/variable_trace.c @@ -12,7 +12,9 @@ #define NUM_TRACED_VARIABLES 1 -#define MAX_TRACE_SIZE 4 +#ifndef MAX_VARIABLE_TRACE_SIZE + #define MAX_VARIABLE_TRACE_SIZE 4 +#endif typedef struct { const char* name; @@ -20,7 +22,7 @@ typedef struct { unsigned size; const char* func; int line; - uint8_t last_value[MAX_TRACE_SIZE]; + uint8_t last_value[MAX_VARIABLE_TRACE_SIZE]; } traced_variable_t; @@ -28,13 +30,13 @@ static traced_variable_t traced_variables[NUM_TRACED_VARIABLES]; void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line) { verify_traced_variables(func, line); - if (size > MAX_TRACE_SIZE) { + if (size > MAX_VARIABLE_TRACE_SIZE) { #if defined(__AVR__) xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size); #else xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size); #endif - size = MAX_TRACE_SIZE; + size = MAX_VARIABLE_TRACE_SIZE; } int index = -1; for (int i = 0; i < NUM_TRACED_VARIABLES; i++) { diff --git a/quantum/variable_trace.h b/quantum/variable_trace.h new file mode 100644 index 0000000000..9899816f6c --- /dev/null +++ b/quantum/variable_trace.h @@ -0,0 +1,25 @@ +#ifndef VARIABLE_TRACE_H +#define VARIABLE_TRACE_H + +#include "print.h" + +#ifdef NUM_TRACED_VARIABLES + +#define ADD_TRACED_VARIABLE(name, addr, size) \ + add_traced_variable(PSTR(name), (void*)addr, size, PSTR(__FILE__), __LINE__) +#define REMOVE_TRACED_VARIABLE(name) remove_traced_variable(PSTR(name), PSTR(__FILE__), __LINE__) +#define VERIFY_TRACED_VARIABLES() verify_traced_variables(PSTR(__FILE__), __LINE__) + +#else + +#define ADD_TRACED_VARIABLE(name, addr, size) +#define REMOVE_TRACED_VARIABLE(name) +#define VERIFY_TRACED_VARIABLES() + +#endif + +// Don't call directly, use the macros instead +void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line); +void remove_traced_variable(const char* name, const char* func, int line); +void verify_traced_variables(const char* func, int line); +#endif -- cgit v1.2.3