diff --git a/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp b/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp index 849ee89f94..f6ee7363aa 100644 --- a/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp +++ b/Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp @@ -75,9 +75,7 @@ static void TX(char c) { // Send String through UART static void TX(const char* s) { - while (*s) { - TX(*s++); - } + while (*s) TX(*s++); } static void TXDigit(uint32_t d) { @@ -89,9 +87,8 @@ static void TXDigit(uint32_t d) { // Send Hex number thru UART static void TXHex(uint32_t v) { TX("0x"); - for (int i=0; i<8; i++, v <<= 4) { + for (uint8_t i = 0; i < 8; i++, v <<= 4) TXDigit((v >> 28) & 0xF); - } } // Send Decimal number thru UART @@ -125,15 +122,15 @@ static bool UnwReportOut(void* ctx, const UnwReport* bte) { return true; } -#if defined(UNW_DEBUG) -void UnwPrintf(const char* format, ...) { - char dest[256]; - va_list argptr; - va_start(argptr, format); - vsprintf(dest, format, argptr); - va_end(argptr); - TX(&dest[0]); -} +#ifdef UNW_DEBUG + void UnwPrintf(const char* format, ...) { + char dest[256]; + va_list argptr; + va_start(argptr, format); + vsprintf(dest, format, argptr); + va_end(argptr); + TX(&dest[0]); + } #endif /* Table of function pointers for passing to the unwinder */ @@ -142,9 +139,9 @@ static const UnwindCallbacks UnwCallbacks = { UnwReadW, UnwReadH, UnwReadB -#if defined(UNW_DEBUG) - ,UnwPrintf -#endif + #if defined(UNW_DEBUG) + ,UnwPrintf + #endif }; /** diff --git a/Marlin/src/backtrace/backtrace.cpp b/Marlin/src/backtrace/backtrace.cpp index fab68416a6..737626744c 100644 --- a/Marlin/src/backtrace/backtrace.cpp +++ b/Marlin/src/backtrace/backtrace.cpp @@ -30,26 +30,26 @@ // Dump a backtrace entry static bool UnwReportOut(void* ctx, const UnwReport* bte) { - int* p = (int*)ctx; + int *p = (int*)ctx; (*p)++; SERIAL_CHAR('#'); SERIAL_PRINT(*p,DEC); SERIAL_ECHOPGM(" : "); - SERIAL_ECHOPGM(bte->name?bte->name:"unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function,HEX); + SERIAL_ECHOPGM(bte->name ? bte->name : "unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function, HEX); SERIAL_CHAR('+'); SERIAL_PRINT(bte->address - bte->function,DEC); SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address,HEX); SERIAL_CHAR('\n'); return true; } -#if defined(UNW_DEBUG) -void UnwPrintf(const char* format, ...) { - char dest[256]; - va_list argptr; - va_start(argptr, format); - vsprintf(dest, format, argptr); - va_end(argptr); - TX(&dest[0]); -} +#ifdef UNW_DEBUG + void UnwPrintf(const char* format, ...) { + char dest[256]; + va_list argptr; + va_start(argptr, format); + vsprintf(dest, format, argptr); + va_end(argptr); + TX(&dest[0]); + } #endif /* Table of function pointers for passing to the unwinder */ @@ -58,9 +58,9 @@ static const UnwindCallbacks UnwCallbacks = { UnwReadW, UnwReadH, UnwReadB -#if defined(UNW_DEBUG) - ,UnwPrintf -#endif + #ifdef UNW_DEBUG + , UnwPrintf + #endif }; void backtrace(void) { @@ -92,11 +92,8 @@ void backtrace(void) { UnwindStart(&btf, &UnwCallbacks, &ctr); } -#else +#else // !__arm__ && !__thumb__ void backtrace(void) {} #endif - - - diff --git a/Marlin/src/backtrace/unwarm.cpp b/Marlin/src/backtrace/unwarm.cpp index 1229e7a731..ff04614f9c 100644 --- a/Marlin/src/backtrace/unwarm.cpp +++ b/Marlin/src/backtrace/unwarm.cpp @@ -25,7 +25,8 @@ #if defined(UNW_DEBUG) -/** Printf wrapper. +/** + * Printf wrapper. * This is used such that alternative outputs for any output can be selected * by modification of this wrapper function. */ @@ -37,10 +38,10 @@ void UnwPrintf(const char *format, ...) { } #endif -/** Invalidate all general purpose registers. +/** + * Invalidate all general purpose registers. */ void UnwInvalidateRegisterFile(RegData *regFile) { - uint8_t t = 0; do { regFile[t].o = REG_VAL_INVALID; @@ -49,7 +50,8 @@ void UnwInvalidateRegisterFile(RegData *regFile) { } -/** Initialise the data used for unwinding. +/** + * Initialise the data used for unwinding. */ void UnwInitState(UnwState * const state, /**< Pointer to structure to fill. */ const UnwindCallbacks *cb, /**< Callbacks. */ @@ -77,12 +79,12 @@ void UnwInitState(UnwState * const state, /**< Pointer to structure to fill. // Detect if function names are available static int __attribute__ ((noinline)) has_function_names(void) { - uint32_t flag_word = ((uint32_t*)(((uint32_t)(&has_function_names)) & (-4))) [-1]; return ((flag_word & 0xff000000) == 0xff000000) ? 1 : 0; } -/** Call the report function to indicate some return address. +/** + * Call the report function to indicate some return address. * This returns the value of the report function, which if true * indicates that unwinding may continue. */ @@ -108,11 +110,9 @@ bool UnwReportRetAddr(UnwState * const state, uint32_t addr) { while(state->cb->readW(pf-4,&v)) { // Check if name descriptor is valid - if ((v & 0xffffff00) == 0xff000000 && - (v & 0xff) > 1) { - + if ((v & 0xFFFFFF00) == 0xFF000000 && (v & 0xFF) > 1) { // Assume the name was found! - entry.name = ((const char*)pf) - 4 - (v & 0xff); + entry.name = ((const char*)pf) - 4 - (v & 0xFF); entry.function = pf; break; } @@ -129,7 +129,8 @@ bool UnwReportRetAddr(UnwState * const state, uint32_t addr) { } -/** Write some register to memory. +/** + * Write some register to memory. * This will store some register and meta data onto the virtual stack. * The address for the write * \param state [in/out] The unwinding state. @@ -141,7 +142,8 @@ bool UnwMemWriteRegister(UnwState * const state, const uint32_t addr, const RegD return UnwMemHashWrite(&state->memData, addr, reg->v, M_IsOriginValid(reg->o)); } -/** Read a register from memory. +/** + * Read a register from memory. * This will read a register from memory, and setup the meta data. * If the register has been previously written to memory using * UnwMemWriteRegister, the local hash will be used to return the @@ -156,23 +158,18 @@ bool UnwMemWriteRegister(UnwState * const state, const uint32_t addr, const RegD * false is the data could not be read. */ bool UnwMemReadRegister(UnwState * const state, const uint32_t addr, RegData * const reg) { - bool tracked; - /* Check if the value can be found in the hash */ - if(UnwMemHashRead(&state->memData, addr, ®->v, &tracked)) { + // Check if the value can be found in the hash + if (UnwMemHashRead(&state->memData, addr, ®->v, &tracked)) { reg->o = tracked ? REG_VAL_FROM_MEMORY : REG_VAL_INVALID; return true; } - /* Not in the hash, so read from real memory */ - else if(state->cb->readW(addr, ®->v)) { + else if (state->cb->readW(addr, ®->v)) { // Not in the hash, so read from real memory reg->o = REG_VAL_FROM_MEMORY; return true; } - /* Not in the hash, and failed to read from memory */ - else { - return false; - } + else return false; // Not in the hash, and failed to read from memory } #endif diff --git a/Marlin/src/backtrace/unwinder.h b/Marlin/src/backtrace/unwinder.h index 683a29e336..29132d0b5b 100644 --- a/Marlin/src/backtrace/unwinder.h +++ b/Marlin/src/backtrace/unwinder.h @@ -146,10 +146,10 @@ typedef struct { */ bool (*readB)(const uint32_t address, uint8_t *val); -#if defined(UNW_DEBUG) - /** Print a formatted line for debug. */ - void (*printf)(const char *format, ...); -#endif + #ifdef UNW_DEBUG + /** Print a formatted line for debug. */ + void (*printf)(const char *format, ...); + #endif } UnwindCallbacks; /* A frame */