|
|
@@ -10,7 +10,7 @@
|
|
10
|
10
|
|
|
11
|
11
|
#include <rtthread.h>
|
|
12
|
12
|
#include "coredump.h"
|
|
13
|
|
-#include "mcd_arch_interface.h"
|
|
|
13
|
+#include "arch/mcd_arch_interface.h"
|
|
14
|
14
|
|
|
15
|
15
|
#define PRINT_COREDUMP_INFO_STRING 1 // 打印字符串格式的coredump信息
|
|
16
|
16
|
|
|
|
@@ -23,15 +23,6 @@ typedef struct
|
|
23
|
23
|
rt_int32_t cur_idx;
|
|
24
|
24
|
} rtthread_ti_priv_t;
|
|
25
|
25
|
|
|
26
|
|
-/* Architecture-specific exception hook function */
|
|
27
|
|
-#ifdef PKG_USING_MCOREDUMP_ARCH_ARMV7M
|
|
28
|
|
- #define arch_hard_fault_exception_hook armv7m_hard_fault_exception_hook
|
|
29
|
|
-#elif defined(PKG_USING_MCOREDUMP_ARCH_ARMV8M)
|
|
30
|
|
- #define arch_hard_fault_exception_hook armv8m_hard_fault_exception_hook
|
|
31
|
|
-#else
|
|
32
|
|
- #error "MCoredump does not support this architecture"
|
|
33
|
|
-#endif
|
|
34
|
|
-
|
|
35
|
26
|
static rt_int32_t is_thread_object(rt_thread_t thread)
|
|
36
|
27
|
{
|
|
37
|
28
|
/* Check if the object is a thread (both static and dynamic) */
|
|
|
@@ -190,103 +181,10 @@ static int32_t rtthread_get_memarea(struct thread_info_ops *ops, int32_t idx,
|
|
190
|
181
|
return 0;
|
|
191
|
182
|
}
|
|
192
|
183
|
|
|
193
|
|
-void mcd_rtos_thread_ops(struct thread_info_ops *ops)
|
|
194
|
|
-{
|
|
195
|
|
- static rtthread_ti_priv_t priv;
|
|
196
|
|
- ops->get_threads_count = rtthread_thread_cnts;
|
|
197
|
|
- ops->get_current_thread_idx = rtthread_cur_index;
|
|
198
|
|
- ops->get_thread_regset = rtthread_thread_register;
|
|
199
|
|
- ops->get_memarea_count = rtthread_get_mem_cnts;
|
|
200
|
|
- ops->get_memarea = rtthread_get_memarea;
|
|
201
|
|
- ops->priv = &priv;
|
|
202
|
|
- priv.cur_idx = -1;
|
|
203
|
|
- priv.thr_cnts = -1;
|
|
204
|
|
-}
|
|
205
|
|
-
|
|
206
|
184
|
#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)
|
|
|
185
|
+static int mcd_print_coredump_info_string(struct thread_info_ops *ops)
|
|
286
|
186
|
{
|
|
287
|
|
- struct thread_info_ops ops;
|
|
288
|
|
- mcd_rtos_thread_ops(&ops);
|
|
289
|
|
- rt_int32_t current_idx = rtthread_cur_index(&ops);
|
|
|
187
|
+ rt_int32_t current_idx = rtthread_cur_index(ops);
|
|
290
|
188
|
rt_int32_t idx_l = 0;
|
|
291
|
189
|
struct rt_object_information *information;
|
|
292
|
190
|
struct rt_object *object;
|
|
|
@@ -296,6 +194,7 @@ static int _print_coredump_info_string(uint32_t cur_thread_regsiter)
|
|
296
|
194
|
|
|
297
|
195
|
information = rt_object_get_information(RT_Object_Class_Thread);
|
|
298
|
196
|
mcd_assert(information != RT_NULL);
|
|
|
197
|
+ mcd_print("\n\n");
|
|
299
|
198
|
|
|
300
|
199
|
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
|
|
301
|
200
|
{
|
|
|
@@ -316,16 +215,19 @@ static int _print_coredump_info_string(uint32_t cur_thread_regsiter)
|
|
316
|
215
|
memlen = thread->stack_size;
|
|
317
|
216
|
}
|
|
318
|
217
|
|
|
319
|
|
- DumpRegisters((void *)cur_thread_regsiter, thread->name);
|
|
|
218
|
+ print_registers((void *)get_cur_core_regset_address(), get_cur_fp_regset_address(), thread->name);
|
|
320
|
219
|
}
|
|
321
|
220
|
else
|
|
322
|
221
|
{
|
|
323
|
222
|
addr = (rt_uint32_t)thread->sp;
|
|
324
|
223
|
memlen = (rt_uint32_t)thread->stack_addr + thread->stack_size - (rt_uint32_t)thread->sp;
|
|
325
|
|
- DumpRegisters(thread->sp, thread->name);
|
|
|
224
|
+ core_regset_type core_regset;
|
|
|
225
|
+ fp_regset_type fp_regset;
|
|
|
226
|
+ collect_registers((uint32_t *)thread->sp, &core_regset, &fp_regset); // rtos栈寄存器格式转换成core_regset类型的
|
|
|
227
|
+ print_registers(&core_regset, &fp_regset, thread->name);
|
|
326
|
228
|
}
|
|
327
|
229
|
|
|
328
|
|
- DumpMem(addr, memlen);
|
|
|
230
|
+ print_mem(addr, memlen);
|
|
329
|
231
|
idx_l++;
|
|
330
|
232
|
}
|
|
331
|
233
|
}
|
|
|
@@ -334,12 +236,25 @@ static int _print_coredump_info_string(uint32_t cur_thread_regsiter)
|
|
334
|
236
|
}
|
|
335
|
237
|
#endif
|
|
336
|
238
|
|
|
337
|
|
-MCD_WEAK rt_err_t rtt_hard_fault_exception_hook(void *context)
|
|
|
239
|
+void mcd_rtos_thread_ops(struct thread_info_ops *ops)
|
|
338
|
240
|
{
|
|
339
|
|
- uint32_t cur_thread_regsiter = arch_hard_fault_exception_hook(context);
|
|
|
241
|
+ static rtthread_ti_priv_t priv;
|
|
|
242
|
+ ops->get_threads_count = rtthread_thread_cnts;
|
|
|
243
|
+ ops->get_current_thread_idx = rtthread_cur_index;
|
|
|
244
|
+ ops->get_thread_regset = rtthread_thread_register;
|
|
|
245
|
+ ops->get_memarea_count = rtthread_get_mem_cnts;
|
|
|
246
|
+ ops->get_memarea = rtthread_get_memarea;
|
|
340
|
247
|
#if PRINT_COREDUMP_INFO_STRING
|
|
341
|
|
- _print_coredump_info_string(cur_thread_regsiter);
|
|
|
248
|
+ ops->print_info_string = mcd_print_coredump_info_string;
|
|
342
|
249
|
#endif
|
|
|
250
|
+ ops->priv = &priv;
|
|
|
251
|
+ priv.cur_idx = -1;
|
|
|
252
|
+ priv.thr_cnts = -1;
|
|
|
253
|
+}
|
|
|
254
|
+
|
|
|
255
|
+MCD_WEAK rt_err_t rtt_hard_fault_exception_hook(void *context)
|
|
|
256
|
+{
|
|
|
257
|
+ arch_hard_fault_exception_hook(context);
|
|
343
|
258
|
return -RT_ERROR;
|
|
344
|
259
|
}
|
|
345
|
260
|
|
|
|
@@ -360,20 +275,11 @@ MCD_WEAK void rtt_assert_hook(const char *ex, const char *func, rt_size_t line)
|
|
360
|
275
|
|
|
361
|
276
|
static int mcd_coredump_init(void)
|
|
362
|
277
|
{
|
|
363
|
|
- static mcd_bool_t is_init = MCD_FALSE;
|
|
364
|
|
-
|
|
365
|
|
- if (is_init)
|
|
366
|
|
- {
|
|
367
|
|
- return 0;
|
|
368
|
|
- }
|
|
369
|
|
-
|
|
370
|
278
|
//mcd_print_memoryinfo();
|
|
371
|
|
-
|
|
372
|
279
|
rt_hw_exception_install(rtt_hard_fault_exception_hook);
|
|
373
|
|
-
|
|
374
|
|
- //rt_assert_set_hook(rtt_assert_hook);
|
|
375
|
|
-
|
|
376
|
|
- is_init = MCD_TRUE;
|
|
377
|
|
- return RT_EOK;
|
|
|
280
|
+#ifdef RT_DEBUG
|
|
|
281
|
+ rt_assert_set_hook(rtt_assert_hook);
|
|
|
282
|
+#endif
|
|
|
283
|
+ return 0;
|
|
378
|
284
|
}
|
|
379
|
285
|
INIT_DEVICE_EXPORT(mcd_coredump_init);
|