Scott Lahteine 7 лет назад
Родитель
Сommit
889fd5f71f

+ 14
- 17
Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp Просмотреть файл

75
 
75
 
76
 // Send String through UART
76
 // Send String through UART
77
 static void TX(const char* s) {
77
 static void TX(const char* s) {
78
-  while (*s) {
79
-    TX(*s++);
80
-  }
78
+  while (*s) TX(*s++);
81
 }
79
 }
82
 
80
 
83
 static void TXDigit(uint32_t d) {
81
 static void TXDigit(uint32_t d) {
89
 // Send Hex number thru UART
87
 // Send Hex number thru UART
90
 static void TXHex(uint32_t v) {
88
 static void TXHex(uint32_t v) {
91
   TX("0x");
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
     TXDigit((v >> 28) & 0xF);
91
     TXDigit((v >> 28) & 0xF);
94
-  }
95
 }
92
 }
96
 
93
 
97
 // Send Decimal number thru UART
94
 // Send Decimal number thru UART
125
   return true;
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
 #endif
134
 #endif
138
 
135
 
139
 /* Table of function pointers for passing to the unwinder */
136
 /* Table of function pointers for passing to the unwinder */
142
   UnwReadW,
139
   UnwReadW,
143
   UnwReadH,
140
   UnwReadH,
144
   UnwReadB
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 Просмотреть файл

30
 
30
 
31
 // Dump a backtrace entry
31
 // Dump a backtrace entry
32
 static bool UnwReportOut(void* ctx, const UnwReport* bte) {
32
 static bool UnwReportOut(void* ctx, const UnwReport* bte) {
33
-  int* p = (int*)ctx;
33
+  int *p = (int*)ctx;
34
 
34
 
35
   (*p)++;
35
   (*p)++;
36
 
36
 
37
   SERIAL_CHAR('#'); SERIAL_PRINT(*p,DEC); SERIAL_ECHOPGM(" : ");
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
   SERIAL_CHAR('+'); SERIAL_PRINT(bte->address - bte->function,DEC);
39
   SERIAL_CHAR('+'); SERIAL_PRINT(bte->address - bte->function,DEC);
40
   SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address,HEX); SERIAL_CHAR('\n');
40
   SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address,HEX); SERIAL_CHAR('\n');
41
   return true;
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
 #endif
53
 #endif
54
 
54
 
55
 /* Table of function pointers for passing to the unwinder */
55
 /* Table of function pointers for passing to the unwinder */
58
   UnwReadW,
58
   UnwReadW,
59
   UnwReadH,
59
   UnwReadH,
60
   UnwReadB
60
   UnwReadB
61
-#if defined(UNW_DEBUG)
62
- ,UnwPrintf
63
-#endif
61
+  #ifdef UNW_DEBUG
62
+   , UnwPrintf
63
+  #endif
64
 };
64
 };
65
 
65
 
66
 void backtrace(void) {
66
 void backtrace(void) {
92
   UnwindStart(&btf, &UnwCallbacks, &ctr);
92
   UnwindStart(&btf, &UnwCallbacks, &ctr);
93
 }
93
 }
94
 
94
 
95
-#else
95
+#else // !__arm__ && !__thumb__
96
 
96
 
97
 void backtrace(void) {}
97
 void backtrace(void) {}
98
 
98
 
99
 #endif
99
 #endif
100
-
101
-
102
-

+ 18
- 21
Marlin/src/backtrace/unwarm.cpp Просмотреть файл

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

+ 4
- 4
Marlin/src/backtrace/unwinder.h Просмотреть файл

146
    */
146
    */
147
   bool (*readB)(const uint32_t address, uint8_t  *val);
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
 } UnwindCallbacks;
153
 } UnwindCallbacks;
154
 
154
 
155
 /* A frame */
155
 /* A frame */

Загрузка…
Отмена
Сохранить