Procházet zdrojové kódy

Backtrace minor cleanup

Scott Lahteine před 6 roky
rodič
revize
889fd5f71f

+ 14
- 17
Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp Zobrazit soubor

@@ -75,9 +75,7 @@ static void TX(char c) {
75 75
 
76 76
 // Send String through UART
77 77
 static void TX(const char* s) {
78
-  while (*s) {
79
-    TX(*s++);
80
-  }
78
+  while (*s) TX(*s++);
81 79
 }
82 80
 
83 81
 static void TXDigit(uint32_t d) {
@@ -89,9 +87,8 @@ static void TXDigit(uint32_t d) {
89 87
 // Send Hex number thru UART
90 88
 static void TXHex(uint32_t v) {
91 89
   TX("0x");
92
-  for (int i=0; i<8; i++, v <<= 4) {
90
+  for (uint8_t i = 0; i < 8; i++, v <<= 4)
93 91
     TXDigit((v >> 28) & 0xF);
94
-  }
95 92
 }
96 93
 
97 94
 // Send Decimal number thru UART
@@ -125,15 +122,15 @@ static bool UnwReportOut(void* ctx, const UnwReport* bte) {
125 122
   return true;
126 123
 }
127 124
 
128
-#if defined(UNW_DEBUG)
129
-void UnwPrintf(const char* format, ...) {
130
-  char dest[256];
131
-  va_list argptr;
132
-  va_start(argptr, format);
133
-  vsprintf(dest, format, argptr);
134
-  va_end(argptr);
135
-  TX(&dest[0]);
136
-}
125
+#ifdef UNW_DEBUG
126
+  void UnwPrintf(const char* format, ...) {
127
+    char dest[256];
128
+    va_list argptr;
129
+    va_start(argptr, format);
130
+    vsprintf(dest, format, argptr);
131
+    va_end(argptr);
132
+    TX(&dest[0]);
133
+  }
137 134
 #endif
138 135
 
139 136
 /* Table of function pointers for passing to the unwinder */
@@ -142,9 +139,9 @@ static const UnwindCallbacks UnwCallbacks = {
142 139
   UnwReadW,
143 140
   UnwReadH,
144 141
   UnwReadB
145
-#if defined(UNW_DEBUG)
146
- ,UnwPrintf
147
-#endif
142
+  #if defined(UNW_DEBUG)
143
+   ,UnwPrintf
144
+  #endif
148 145
 };
149 146
 
150 147
 /**

+ 15
- 18
Marlin/src/backtrace/backtrace.cpp Zobrazit soubor

@@ -30,26 +30,26 @@
30 30
 
31 31
 // Dump a backtrace entry
32 32
 static bool UnwReportOut(void* ctx, const UnwReport* bte) {
33
-  int* p = (int*)ctx;
33
+  int *p = (int*)ctx;
34 34
 
35 35
   (*p)++;
36 36
 
37 37
   SERIAL_CHAR('#'); SERIAL_PRINT(*p,DEC); SERIAL_ECHOPGM(" : ");
38
-  SERIAL_ECHOPGM(bte->name?bte->name:"unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function,HEX);
38
+  SERIAL_ECHOPGM(bte->name ? bte->name : "unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function, HEX);
39 39
   SERIAL_CHAR('+'); SERIAL_PRINT(bte->address - bte->function,DEC);
40 40
   SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address,HEX); SERIAL_CHAR('\n');
41 41
   return true;
42 42
 }
43 43
 
44
-#if defined(UNW_DEBUG)
45
-void UnwPrintf(const char* format, ...) {
46
-  char dest[256];
47
-  va_list argptr;
48
-  va_start(argptr, format);
49
-  vsprintf(dest, format, argptr);
50
-  va_end(argptr);
51
-  TX(&dest[0]);
52
-}
44
+#ifdef UNW_DEBUG
45
+  void UnwPrintf(const char* format, ...) {
46
+    char dest[256];
47
+    va_list argptr;
48
+    va_start(argptr, format);
49
+    vsprintf(dest, format, argptr);
50
+    va_end(argptr);
51
+    TX(&dest[0]);
52
+  }
53 53
 #endif
54 54
 
55 55
 /* Table of function pointers for passing to the unwinder */
@@ -58,9 +58,9 @@ static const UnwindCallbacks UnwCallbacks = {
58 58
   UnwReadW,
59 59
   UnwReadH,
60 60
   UnwReadB
61
-#if defined(UNW_DEBUG)
62
- ,UnwPrintf
63
-#endif
61
+  #ifdef UNW_DEBUG
62
+   , UnwPrintf
63
+  #endif
64 64
 };
65 65
 
66 66
 void backtrace(void) {
@@ -92,11 +92,8 @@ void backtrace(void) {
92 92
   UnwindStart(&btf, &UnwCallbacks, &ctr);
93 93
 }
94 94
 
95
-#else
95
+#else // !__arm__ && !__thumb__
96 96
 
97 97
 void backtrace(void) {}
98 98
 
99 99
 #endif
100
-
101
-
102
-

+ 18
- 21
Marlin/src/backtrace/unwarm.cpp Zobrazit soubor

@@ -25,7 +25,8 @@
25 25
 
26 26
 #if defined(UNW_DEBUG)
27 27
 
28
-/** Printf wrapper.
28
+/**
29
+ * Printf wrapper.
29 30
  * This is used such that alternative outputs for any output can be selected
30 31
  * by modification of this wrapper function.
31 32
  */
@@ -37,10 +38,10 @@ void UnwPrintf(const char *format, ...) {
37 38
 }
38 39
 #endif
39 40
 
40
-/** Invalidate all general purpose registers.
41
+/**
42
+ * Invalidate all general purpose registers.
41 43
  */
42 44
 void UnwInvalidateRegisterFile(RegData *regFile) {
43
-
44 45
   uint8_t t = 0;
45 46
   do {
46 47
     regFile[t].o = REG_VAL_INVALID;
@@ -49,7 +50,8 @@ void UnwInvalidateRegisterFile(RegData *regFile) {
49 50
 }
50 51
 
51 52
 
52
-/** Initialise the data used for unwinding.
53
+/**
54
+ * Initialise the data used for unwinding.
53 55
  */
54 56
 void UnwInitState(UnwState * const state,     /**< Pointer to structure to fill. */
55 57
                   const UnwindCallbacks *cb,  /**< Callbacks. */
@@ -77,12 +79,12 @@ void UnwInitState(UnwState * const state,     /**< Pointer to structure to fill.
77 79
 
78 80
 // Detect if function names are available
79 81
 static int __attribute__ ((noinline)) has_function_names(void) {
80
-
81 82
   uint32_t flag_word = ((uint32_t*)(((uint32_t)(&has_function_names)) & (-4))) [-1];
82 83
   return ((flag_word & 0xff000000) == 0xff000000) ? 1 : 0;
83 84
 }
84 85
 
85
-/** Call the report function to indicate some return address.
86
+/**
87
+ * Call the report function to indicate some return address.
86 88
  * This returns the value of the report function, which if true
87 89
  * indicates that unwinding may continue.
88 90
  */
@@ -108,11 +110,9 @@ bool UnwReportRetAddr(UnwState * const state, uint32_t addr) {
108 110
     while(state->cb->readW(pf-4,&v)) {
109 111
 
110 112
       // Check if name descriptor is valid
111
-      if ((v & 0xffffff00) == 0xff000000 &&
112
-          (v & 0xff) > 1) {
113
-
113
+      if ((v & 0xFFFFFF00) == 0xFF000000 && (v & 0xFF) > 1) {
114 114
         // Assume the name was found!
115
-        entry.name = ((const char*)pf) - 4 - (v & 0xff);
115
+        entry.name = ((const char*)pf) - 4 - (v & 0xFF);
116 116
         entry.function = pf;
117 117
         break;
118 118
       }
@@ -129,7 +129,8 @@ bool UnwReportRetAddr(UnwState * const state, uint32_t addr) {
129 129
 }
130 130
 
131 131
 
132
-/** Write some register to memory.
132
+/**
133
+ * Write some register to memory.
133 134
  * This will store some register and meta data onto the virtual stack.
134 135
  * The address for the write
135 136
  * \param state [in/out]  The unwinding state.
@@ -141,7 +142,8 @@ bool UnwMemWriteRegister(UnwState * const state, const uint32_t addr, const RegD
141 142
   return UnwMemHashWrite(&state->memData, addr, reg->v, M_IsOriginValid(reg->o));
142 143
 }
143 144
 
144
-/** Read a register from memory.
145
+/**
146
+ * Read a register from memory.
145 147
  * This will read a register from memory, and setup the meta data.
146 148
  * If the register has been previously written to memory using
147 149
  * 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
156 158
  *         false is the data could not be read.
157 159
  */
158 160
 bool UnwMemReadRegister(UnwState * const state, const uint32_t addr, RegData * const reg) {
159
-
160 161
   bool tracked;
161 162
 
162
-  /* Check if the value can be found in the hash */
163
-  if(UnwMemHashRead(&state->memData, addr, &reg->v, &tracked)) {
163
+  // Check if the value can be found in the hash
164
+  if (UnwMemHashRead(&state->memData, addr, &reg->v, &tracked)) {
164 165
     reg->o = tracked ? REG_VAL_FROM_MEMORY : REG_VAL_INVALID;
165 166
     return true;
166 167
   }
167
-  /* Not in the hash, so read from real memory */
168
-  else if(state->cb->readW(addr, &reg->v)) {
168
+  else if (state->cb->readW(addr, &reg->v)) {   // Not in the hash, so read from real memory
169 169
     reg->o = REG_VAL_FROM_MEMORY;
170 170
     return true;
171 171
   }
172
-  /* Not in the hash, and failed to read from memory */
173
-  else {
174
-    return false;
175
-  }
172
+  else return false;                            // Not in the hash, and failed to read from memory
176 173
 }
177 174
 #endif
178 175
 

+ 4
- 4
Marlin/src/backtrace/unwinder.h Zobrazit soubor

@@ -146,10 +146,10 @@ typedef struct {
146 146
    */
147 147
   bool (*readB)(const uint32_t address, uint8_t  *val);
148 148
 
149
-#if defined(UNW_DEBUG)
150
-  /** Print a formatted line for debug. */
151
-  void (*printf)(const char *format, ...);
152
-#endif
149
+  #ifdef UNW_DEBUG
150
+    /** Print a formatted line for debug. */
151
+    void (*printf)(const char *format, ...);
152
+  #endif
153 153
 } UnwindCallbacks;
154 154
 
155 155
 /* A frame */

Loading…
Zrušit
Uložit