|
|
@@ -12,6 +12,8 @@
|
|
12
|
12
|
#include "coredump.h"
|
|
13
|
13
|
#include "mcd_arch_interface.h"
|
|
14
|
14
|
|
|
|
15
|
+#define PRINT_COREDUMP_INFO_STRING 1 // 打印字符串格式的coredump信息
|
|
|
16
|
+
|
|
15
|
17
|
/*
|
|
16
|
18
|
* RT-Thread OS abstraction layer implementation for MCoreDump
|
|
17
|
19
|
*/
|
|
|
@@ -127,8 +129,10 @@ static void rtthread_thread_register(struct thread_info_ops *ops, int32_t idx,
|
|
127
|
129
|
/* Debug: Dynamic thread for comparison */
|
|
128
|
130
|
collect_registers((uint32_t *)thread->sp, core_regset, fp_regset);
|
|
129
|
131
|
}
|
|
|
132
|
+
|
|
130
|
133
|
return;
|
|
131
|
134
|
}
|
|
|
135
|
+
|
|
132
|
136
|
idx_l++;
|
|
133
|
137
|
}
|
|
134
|
138
|
}
|
|
|
@@ -179,6 +183,7 @@ static int32_t rtthread_get_memarea(struct thread_info_ops *ops, int32_t idx,
|
|
179
|
183
|
}
|
|
180
|
184
|
return 0;
|
|
181
|
185
|
}
|
|
|
186
|
+
|
|
182
|
187
|
idx_l++;
|
|
183
|
188
|
}
|
|
184
|
189
|
}
|
|
|
@@ -198,9 +203,143 @@ void mcd_rtos_thread_ops(struct thread_info_ops *ops)
|
|
198
|
203
|
priv.thr_cnts = -1;
|
|
199
|
204
|
}
|
|
200
|
205
|
|
|
|
206
|
+#if PRINT_COREDUMP_INFO_STRING
|
|
|
207
|
+static void DumpRegisters(struct stack_frame *sp, char *thread)
|
|
|
208
|
+{
|
|
|
209
|
+#if USE_FPU
|
|
|
210
|
+ if (sp->flag) /* 使用FPU */
|
|
|
211
|
+ {
|
|
|
212
|
+ struct stack_frame_fpu *sp_fpu = (struct stack_frame_fpu *)sp;
|
|
|
213
|
+ mcd_print("Registers@%s\n", thread);
|
|
|
214
|
+ mcd_print("R0: 0x%08x\n", sp_fpu->exception_stack_frame.r0);
|
|
|
215
|
+ mcd_print("R1: 0x%08x\n", sp_fpu->exception_stack_frame.r1);
|
|
|
216
|
+ mcd_print("R2: 0x%08x\n", sp_fpu->exception_stack_frame.r2);
|
|
|
217
|
+ mcd_print("R3: 0x%08x\n", sp_fpu->exception_stack_frame.r3);
|
|
|
218
|
+ mcd_print("R4: 0x%08x\n", sp_fpu->r4);
|
|
|
219
|
+ mcd_print("R5: 0x%08x\n", sp_fpu->r5);
|
|
|
220
|
+ mcd_print("R6: 0x%08x\n", sp_fpu->r6);
|
|
|
221
|
+ mcd_print("R7: 0x%08x\n", sp_fpu->r7);
|
|
|
222
|
+ mcd_print("R8: 0x%08x\n", sp_fpu->r8);
|
|
|
223
|
+ mcd_print("R9: 0x%08x\n", sp_fpu->r9);
|
|
|
224
|
+ mcd_print("R10: 0x%08x\n", sp_fpu->r10);
|
|
|
225
|
+ mcd_print("R11: 0x%08x\n", sp_fpu->r11);
|
|
|
226
|
+ mcd_print("R12: 0x%08x\n", sp_fpu->exception_stack_frame.r12);
|
|
|
227
|
+ mcd_print("R13(sp_fpu): 0x%08x\n", (uint32_t)sp_fpu + sizeof(*sp_fpu));
|
|
|
228
|
+ mcd_print("R14(LR): 0x%08x\n", sp_fpu->exception_stack_frame.lr);
|
|
|
229
|
+ mcd_print("R15(PC): 0x%08x\n", sp_fpu->exception_stack_frame.pc);
|
|
|
230
|
+ mcd_print("xPSR: 0x%08x\n", sp_fpu->exception_stack_frame.psr);
|
|
|
231
|
+ }
|
|
|
232
|
+ else
|
|
|
233
|
+#endif
|
|
|
234
|
+ {
|
|
|
235
|
+ mcd_print("Registers@%s\n", thread);
|
|
|
236
|
+ mcd_print("R0: 0x%08x\n", sp->exception_stack_frame.r0);
|
|
|
237
|
+ mcd_print("R1: 0x%08x\n", sp->exception_stack_frame.r1);
|
|
|
238
|
+ mcd_print("R2: 0x%08x\n", sp->exception_stack_frame.r2);
|
|
|
239
|
+ mcd_print("R3: 0x%08x\n", sp->exception_stack_frame.r3);
|
|
|
240
|
+ mcd_print("R4: 0x%08x\n", sp->r4);
|
|
|
241
|
+ mcd_print("R5: 0x%08x\n", sp->r5);
|
|
|
242
|
+ mcd_print("R6: 0x%08x\n", sp->r6);
|
|
|
243
|
+ mcd_print("R7: 0x%08x\n", sp->r7);
|
|
|
244
|
+ mcd_print("R8: 0x%08x\n", sp->r8);
|
|
|
245
|
+ mcd_print("R9: 0x%08x\n", sp->r9);
|
|
|
246
|
+ mcd_print("R10: 0x%08x\n", sp->r10);
|
|
|
247
|
+ mcd_print("R11: 0x%08x\n", sp->r11);
|
|
|
248
|
+ mcd_print("R12: 0x%08x\n", sp->exception_stack_frame.r12);
|
|
|
249
|
+ mcd_print("R13(SP): 0x%08x\n", (uint32_t)sp + sizeof(*sp));
|
|
|
250
|
+ mcd_print("R14(LR): 0x%08x\n", sp->exception_stack_frame.lr);
|
|
|
251
|
+ mcd_print("R15(PC): 0x%08x\n", sp->exception_stack_frame.pc);
|
|
|
252
|
+ mcd_print("xPSR: 0x%08x\n", sp->exception_stack_frame.psr);
|
|
|
253
|
+ }
|
|
|
254
|
+}
|
|
|
255
|
+
|
|
|
256
|
+static void DumpMem(uint32_t addr, uint32_t len)
|
|
|
257
|
+{
|
|
|
258
|
+ uint32_t *paddr;
|
|
|
259
|
+ uint32_t i;
|
|
|
260
|
+
|
|
|
261
|
+ if (len == 0)
|
|
|
262
|
+ return;
|
|
|
263
|
+
|
|
|
264
|
+ paddr = (uint32_t *)addr;
|
|
|
265
|
+ mcd_print("mem@0x%08x,0x%08x\n", addr, len);
|
|
|
266
|
+
|
|
|
267
|
+ for (i = 0; i < len;)
|
|
|
268
|
+ {
|
|
|
269
|
+ mcd_print("0x%08x", *paddr);
|
|
|
270
|
+ paddr++;
|
|
|
271
|
+
|
|
|
272
|
+ i += 4;
|
|
|
273
|
+ if (i % 16 == 0)
|
|
|
274
|
+ mcd_print("\n");
|
|
|
275
|
+ else
|
|
|
276
|
+ mcd_print(" ");
|
|
|
277
|
+ }
|
|
|
278
|
+
|
|
|
279
|
+ mcd_print("\n");
|
|
|
280
|
+
|
|
|
281
|
+ if (len % 16 != 0)
|
|
|
282
|
+ mcd_print("\n");
|
|
|
283
|
+}
|
|
|
284
|
+
|
|
|
285
|
+static int _print_coredump_info_string(uint32_t cur_thread_regsiter)
|
|
|
286
|
+{
|
|
|
287
|
+ struct thread_info_ops ops;
|
|
|
288
|
+ mcd_rtos_thread_ops(&ops);
|
|
|
289
|
+ rt_int32_t current_idx = rtthread_cur_index(&ops);
|
|
|
290
|
+ rt_int32_t idx_l = 0;
|
|
|
291
|
+ struct rt_object_information *information;
|
|
|
292
|
+ struct rt_object *object;
|
|
|
293
|
+ struct rt_list_node *node;
|
|
|
294
|
+ uint32_t addr;
|
|
|
295
|
+ uint32_t memlen;
|
|
|
296
|
+
|
|
|
297
|
+ information = rt_object_get_information(RT_Object_Class_Thread);
|
|
|
298
|
+ mcd_assert(information != RT_NULL);
|
|
|
299
|
+
|
|
|
300
|
+ for (node = information->object_list.next; node != &(information->object_list); node = node->next)
|
|
|
301
|
+ {
|
|
|
302
|
+ object = rt_list_entry(node, struct rt_object, list);
|
|
|
303
|
+ rt_thread_t thread = (rt_thread_t)object;
|
|
|
304
|
+
|
|
|
305
|
+ if (is_thread_object(thread))
|
|
|
306
|
+ {
|
|
|
307
|
+ /* If this is the current thread, use current stack pointer */
|
|
|
308
|
+ if (idx_l == current_idx)
|
|
|
309
|
+ {
|
|
|
310
|
+ addr = (rt_uint32_t)get_cur_core_regset_address()->sp; // 异常中填充
|
|
|
311
|
+ memlen = (rt_uint32_t)thread->stack_addr + thread->stack_size - (rt_uint32_t)thread->sp;
|
|
|
312
|
+
|
|
|
313
|
+ if (memlen > thread->stack_size)
|
|
|
314
|
+ {
|
|
|
315
|
+ mcd_println("The stack may overflow!!!");
|
|
|
316
|
+ memlen = thread->stack_size;
|
|
|
317
|
+ }
|
|
|
318
|
+
|
|
|
319
|
+ DumpRegisters((void *)cur_thread_regsiter, thread->name);
|
|
|
320
|
+ }
|
|
|
321
|
+ else
|
|
|
322
|
+ {
|
|
|
323
|
+ addr = (rt_uint32_t)thread->sp;
|
|
|
324
|
+ memlen = (rt_uint32_t)thread->stack_addr + thread->stack_size - (rt_uint32_t)thread->sp;
|
|
|
325
|
+ DumpRegisters(thread->sp, thread->name);
|
|
|
326
|
+ }
|
|
|
327
|
+
|
|
|
328
|
+ DumpMem(addr, memlen);
|
|
|
329
|
+ idx_l++;
|
|
|
330
|
+ }
|
|
|
331
|
+ }
|
|
|
332
|
+
|
|
|
333
|
+ return 0;
|
|
|
334
|
+}
|
|
|
335
|
+#endif
|
|
|
336
|
+
|
|
201
|
337
|
MCD_WEAK rt_err_t rtt_hard_fault_exception_hook(void *context)
|
|
202
|
338
|
{
|
|
203
|
|
- arch_hard_fault_exception_hook(context);
|
|
|
339
|
+ uint32_t cur_thread_regsiter = arch_hard_fault_exception_hook(context);
|
|
|
340
|
+#if PRINT_COREDUMP_INFO_STRING
|
|
|
341
|
+ _print_coredump_info_string(cur_thread_regsiter);
|
|
|
342
|
+#endif
|
|
204
|
343
|
return -RT_ERROR;
|
|
205
|
344
|
}
|
|
206
|
345
|
|