Browse Source

[add] 文件目录整理

rtthread_MCoreDump
huangyulong 2 months ago
parent
commit
4f6ec2e386

+ 13
- 22
EWARM/stm32_broad_mini.ewp View File

355
                     <state>$PROJ_DIR$/../Middlewares/rtthread/include</state>
355
                     <state>$PROJ_DIR$/../Middlewares/rtthread/include</state>
356
                     <state>$PROJ_DIR$/../Middlewares/rtthread/include/libc</state>
356
                     <state>$PROJ_DIR$/../Middlewares/rtthread/include/libc</state>
357
                     <state>$PROJ_DIR$/../Middlewares/rtthread/finsh</state>
357
                     <state>$PROJ_DIR$/../Middlewares/rtthread/finsh</state>
358
-                    <state>$PROJ_DIR$/../Middlewares/MCoreDump/src/arm</state>
359
-                    <state>$PROJ_DIR$/../Middlewares/MCoreDump/inc</state>
360
-                    <state>$PROJ_DIR$/../Middlewares/MCoreDump/arch</state>
361
-                    <state>$PROJ_DIR$/../Middlewares/MCoreDump/arch/armv7m</state>
358
+                    <state>$PROJ_DIR$/../Middlewares/MCoreDump</state>
362
                 </option>
359
                 </option>
363
                 <option>
360
                 <option>
364
                     <name>CCStdIncCheck</name>
361
                     <name>CCStdIncCheck</name>
1245
                     <name>$PROJ_DIR$\..\Middlewares\MCoreDump\arch\armv7m\armv7m.c</name>
1242
                     <name>$PROJ_DIR$\..\Middlewares\MCoreDump\arch\armv7m\armv7m.c</name>
1246
                 </file>
1243
                 </file>
1247
             </group>
1244
             </group>
1248
-            <group>
1249
-                <name>osal</name>
1250
-                <file>
1251
-                    <name>$PROJ_DIR$\..\Middlewares\MCoreDump\osal\rtthread.c</name>
1252
-                </file>
1253
-            </group>
1254
-            <group>
1255
-                <name>src</name>
1256
-                <file>
1257
-                    <name>$PROJ_DIR$\..\Middlewares\MCoreDump\src\coredump.c</name>
1258
-                </file>
1259
-                <file>
1260
-                    <name>$PROJ_DIR$\..\Middlewares\MCoreDump\src\faultdump.c</name>
1261
-                </file>
1262
-                <file>
1263
-                    <name>$PROJ_DIR$\..\Middlewares\MCoreDump\src\arm\mcd_arm.c</name>
1264
-                </file>
1265
-            </group>
1245
+            <file>
1246
+                <name>$PROJ_DIR$\..\Middlewares\MCoreDump\coredump.c</name>
1247
+            </file>
1248
+            <file>
1249
+                <name>$PROJ_DIR$\..\Middlewares\MCoreDump\faultdump.c</name>
1250
+            </file>
1251
+            <file>
1252
+                <name>$PROJ_DIR$\..\Middlewares\MCoreDump\arm\mcd_arm.c</name>
1253
+            </file>
1254
+            <file>
1255
+                <name>$PROJ_DIR$\..\Middlewares\MCoreDump\rtthread_port.c</name>
1256
+            </file>
1266
         </group>
1257
         </group>
1267
         <group>
1258
         <group>
1268
             <name>RTT</name>
1259
             <name>RTT</name>

+ 63
- 9
Middlewares/MCoreDump/arch/armv7m/armv7m.c View File

157
     struct thread_info_ops ops;
157
     struct thread_info_ops ops;
158
     mcd_rtos_thread_ops(&ops);
158
     mcd_rtos_thread_ops(&ops);
159
     mcd_gen_coredump(&ops);
159
     mcd_gen_coredump(&ops);
160
+
161
+    if (ops.print_info_string)
162
+        ops.print_info_string(&ops);
160
 }
163
 }
161
 
164
 
162
 // 只保存当前线程或非线程(主栈):更新当前寄存器到全局变量
165
 // 只保存当前线程或非线程(主栈):更新当前寄存器到全局变量
173
 
176
 
174
     mcd_mini_dump_ops(&ops);
177
     mcd_mini_dump_ops(&ops);
175
     mcd_gen_coredump(&ops);
178
     mcd_gen_coredump(&ops);
179
+
180
+    if (ops.print_info_string)
181
+        ops.print_info_string(&ops);
176
 }
182
 }
177
 
183
 
178
 // 保存RTOS所有线程:更新当前寄存器到全局变量
184
 // 保存RTOS所有线程:更新当前寄存器到全局变量
189
 
195
 
190
     mcd_rtos_thread_ops(&ops);
196
     mcd_rtos_thread_ops(&ops);
191
     mcd_gen_coredump(&ops);
197
     mcd_gen_coredump(&ops);
198
+
199
+    if (ops.print_info_string)
200
+        ops.print_info_string(&ops);
192
 }
201
 }
193
 
202
 
194
 #endif
203
 #endif
195
 
204
 
205
+void print_registers_armv7m(core_regset_type *reg, fp_regset_type *fp_reg, char *thread)
206
+{
207
+    mcd_print("Registers@%s\n", thread);
208
+    mcd_print("R0: 0x%08x\n", reg->r0);
209
+    mcd_print("R1: 0x%08x\n", reg->r1);
210
+    mcd_print("R2: 0x%08x\n", reg->r2);
211
+    mcd_print("R3: 0x%08x\n", reg->r3);
212
+    mcd_print("R4: 0x%08x\n", reg->r4);
213
+    mcd_print("R5: 0x%08x\n", reg->r5);
214
+    mcd_print("R6: 0x%08x\n", reg->r6);
215
+    mcd_print("R7: 0x%08x\n", reg->r7);
216
+    mcd_print("R8: 0x%08x\n", reg->r8);
217
+    mcd_print("R9: 0x%08x\n", reg->r9);
218
+    mcd_print("R10: 0x%08x\n", reg->r10);
219
+    mcd_print("R11: 0x%08x\n", reg->r11);
220
+    mcd_print("R12: 0x%08x\n", reg->r12);
221
+    mcd_print("R13(SP): 0x%08x\n", reg->sp);
222
+    mcd_print("R14(LR): 0x%08x\n", reg->lr);
223
+    mcd_print("R15(PC): 0x%08x\n", reg->pc);
224
+    mcd_print("xPSR: 0x%08x\n", reg->xpsr);
225
+}
226
+
227
+void print_mem_armv7m(uint32_t addr, uint32_t len)
228
+{
229
+    uint32_t *paddr;
230
+    uint32_t i;
231
+
232
+    if (len == 0)
233
+        return;
234
+
235
+    paddr = (uint32_t *)addr;
236
+    mcd_print("mem@0x%08x,0x%08x\n", addr, len);
237
+
238
+    for (i = 0; i < len;)
239
+    {
240
+        mcd_print("0x%08x", *paddr);
241
+        paddr++;
242
+
243
+        i += 4;
244
+        if (i % 16 == 0)
245
+            mcd_print("\n");
246
+        else
247
+            mcd_print(" ");
248
+    }
249
+
250
+    mcd_print("\n");
251
+
252
+    if (len % 16 != 0)
253
+        mcd_print("\n");
254
+}
255
+
196
 /**
256
 /**
197
  * @brief Collect ARM Cortex-M4 registers from RT-Thread stack frame
257
  * @brief Collect ARM Cortex-M4 registers from RT-Thread stack frame
198
  *
258
  *
232
  * @param core_regset Pointer to structure for storing ARM core registers
292
  * @param core_regset Pointer to structure for storing ARM core registers
233
  * @param fp_regset Pointer to structure for storing FPU registers
293
  * @param fp_regset Pointer to structure for storing FPU registers
234
  */
294
  */
295
+// 通过sp指针得到寄存器信息
235
 void collect_registers_armv7m(uint32_t *stack_top, core_regset_type *core_regset, fp_regset_type *fp_regset)
296
 void collect_registers_armv7m(uint32_t *stack_top, core_regset_type *core_regset, fp_regset_type *fp_regset)
236
 {
297
 {
237
     /*
298
     /*
371
 //  stack_ptr += 1; // 如开启fpuflag
432
 //  stack_ptr += 1; // 如开启fpuflag
372
 #endif
433
 #endif
373
 
434
 
374
-    //extern void DumpCore(void *sp);
375
-    //DumpCore(stack_ptr);
376
-
377
     /*
435
     /*
378
      * Now stack_ptr points to where collect_registers_armv7m expects:
436
      * Now stack_ptr points to where collect_registers_armv7m expects:
379
      * - With FPU: points to FPU flag (first field to be read)
437
      * - With FPU: points to FPU flag (first field to be read)
380
      * - Without FPU: points to r4 (first register to be read)
438
      * - Without FPU: points to r4 (first register to be read)
381
      */
439
      */
382
-    collect_registers_armv7m(stack_ptr,
383
-                             get_cur_core_regset_address(),
384
-                             get_cur_fp_regset_address());
385
-
440
+    collect_registers_armv7m(stack_ptr, get_cur_core_regset_address(), get_cur_fp_regset_address());
386
     /* Generate coredump using memory mode */
441
     /* Generate coredump using memory mode */
387
     mcd_faultdump(MCD_OUTPUT_FAULT_SERIAL);
442
     mcd_faultdump(MCD_OUTPUT_FAULT_SERIAL);
388
-
389
-    return (int)stack_ptr;
443
+    return 0;
390
 }
444
 }

+ 26
- 18
Middlewares/MCoreDump/arch/mcd_arch_interface.h View File

15
 
15
 
16
 /**
16
 /**
17
  * @brief Architecture-specific hard fault exception handler
17
  * @brief Architecture-specific hard fault exception handler
18
- * 
18
+ *
19
  * This function should be implemented by each supported architecture
19
  * This function should be implemented by each supported architecture
20
  * to handle the architecture-specific stack frame processing.
20
  * to handle the architecture-specific stack frame processing.
21
- * 
21
+ *
22
  * @param context Pointer to exception context (architecture-specific format)
22
  * @param context Pointer to exception context (architecture-specific format)
23
  * @return int Always returns -1 to indicate fault condition
23
  * @return int Always returns -1 to indicate fault condition
24
  */
24
  */
27
 
27
 
28
 /**
28
 /**
29
  * @brief Architecture-specific register collection function
29
  * @brief Architecture-specific register collection function
30
- * 
30
+ *
31
  * This function extracts register values from the architecture-specific
31
  * This function extracts register values from the architecture-specific
32
  * stack frame format and stores them in the standard register sets.
32
  * stack frame format and stores them in the standard register sets.
33
- * 
33
+ *
34
  * @param stack_top Pointer to the stack frame
34
  * @param stack_top Pointer to the stack frame
35
- * @param core_regset Pointer to store ARM core registers  
35
+ * @param core_regset Pointer to store ARM core registers
36
  * @param fp_regset Pointer to store FPU registers
36
  * @param fp_regset Pointer to store FPU registers
37
  */
37
  */
38
-void collect_registers_armv7m(uint32_t *stack_top,
39
-                             core_regset_type *core_regset,
40
-                             fp_regset_type *fp_regset);
38
+void collect_registers_armv7m(uint32_t *stack_top, core_regset_type *core_regset, fp_regset_type *fp_regset);
39
+
40
+// 打印寄存器
41
+void print_registers_armv7m(core_regset_type *reg, fp_regset_type *fp_reg, char *thread);
42
+// 打印一段内存
43
+void print_mem_armv7m(uint32_t addr, uint32_t len);
41
 
44
 
42
 /* Generic interface macro for architecture-agnostic code */
45
 /* Generic interface macro for architecture-agnostic code */
43
-#define collect_registers collect_registers_armv7m
44
-#endif
46
+    #define collect_registers collect_registers_armv7m
47
+    #define print_registers print_registers_armv7m
48
+    #define print_mem print_mem_armv7m
49
+    #define arch_hard_fault_exception_hook armv7m_hard_fault_exception_hook
45
 
50
 
46
-#ifdef PKG_USING_MCOREDUMP_ARCH_ARMV8M
51
+#elif defined(PKG_USING_MCOREDUMP_ARCH_ARMV8M)
47
 int armv8m_hard_fault_exception_hook(void *context);
52
 int armv8m_hard_fault_exception_hook(void *context);
48
 
53
 
49
 /**
54
 /**
50
  * @brief Architecture-specific register collection function
55
  * @brief Architecture-specific register collection function
51
- * 
56
+ *
52
  * This function extracts register values from the architecture-specific
57
  * This function extracts register values from the architecture-specific
53
  * stack frame format and stores them in the standard register sets.
58
  * stack frame format and stores them in the standard register sets.
54
- * 
59
+ *
55
  * @param stack_top Pointer to the stack frame
60
  * @param stack_top Pointer to the stack frame
56
- * @param core_regset Pointer to store ARM core registers  
61
+ * @param core_regset Pointer to store ARM core registers
57
  * @param fp_regset Pointer to store FPU registers
62
  * @param fp_regset Pointer to store FPU registers
58
  */
63
  */
59
-void collect_registers_armv8m(uint32_t *stack_top,
60
-                             core_regset_type *core_regset,
61
-                             fp_regset_type *fp_regset);
64
+void collect_registers_armv8m(uint32_t *stack_top, core_regset_type *core_regset, fp_regset_type *fp_regset);
62
 
65
 
63
 /* Generic interface macro for architecture-agnostic code */
66
 /* Generic interface macro for architecture-agnostic code */
64
-#define collect_registers collect_registers_armv8m
67
+    #define collect_registers collect_registers_armv8m
68
+    #define print_registers
69
+    #define print_mem
70
+    #define arch_hard_fault_exception_hook armv8m_hard_fault_exception_hook
71
+#else
72
+    #error "MCoredump does not support this architecture"
65
 #endif
73
 #endif
66
 
74
 
67
 #endif /* __MCD_ARCH_INTERFACE_H__ */
75
 #endif /* __MCD_ARCH_INTERFACE_H__ */

Middlewares/MCoreDump/src/arm/mcd_arm.c → Middlewares/MCoreDump/arm/mcd_arm.c View File


Middlewares/MCoreDump/src/arm/mcd_arm_define.h → Middlewares/MCoreDump/arm/mcd_arm_define.h View File

11
 #ifndef __MCD_ARM_DEFINE_H__
11
 #ifndef __MCD_ARM_DEFINE_H__
12
 #define __MCD_ARM_DEFINE_H__
12
 #define __MCD_ARM_DEFINE_H__
13
 
13
 
14
-#include "registers.h"
14
+#include "arch/armv7m/registers.h"
15
 
15
 
16
 /* ARM Architecture Detection */
16
 /* ARM Architecture Detection */
17
 #if defined(__aarch64__) || defined(_M_ARM64)
17
 #if defined(__aarch64__) || defined(_M_ARM64)

Middlewares/MCoreDump/src/coredump.c → Middlewares/MCoreDump/coredump.c View File

11
 #include <string.h>
11
 #include <string.h>
12
 #include "coredump.h"
12
 #include "coredump.h"
13
 #include "mcd_elf_define.h"
13
 #include "mcd_elf_define.h"
14
-#include "mcd_arm_define.h"
14
+#include "arm\mcd_arm_define.h"
15
 
15
 
16
 typedef uint16_t elf_half;
16
 typedef uint16_t elf_half;
17
 typedef uint32_t elf_word;
17
 typedef uint32_t elf_word;
192
     memset(&m_ctx, 0, sizeof(mcd_instance_t));
192
     memset(&m_ctx, 0, sizeof(mcd_instance_t));
193
     m_ctx.stack_size = 1536;
193
     m_ctx.stack_size = 1536;
194
     m_ctx.writeout_func = func;
194
     m_ctx.writeout_func = func;
195
-    
195
+
196
     /* Automatically detect FPU support based on compiler definitions */
196
     /* Automatically detect FPU support based on compiler definitions */
197
     m_ctx.with_fp = MCD_FPU_SUPPORT;
197
     m_ctx.with_fp = MCD_FPU_SUPPORT;
198
 }
198
 }
215
     *addr &= CORE_MEM_LINE_MASK;
215
     *addr &= CORE_MEM_LINE_MASK;
216
 }
216
 }
217
 
217
 
218
-// Éú³É.elfÎļþ
218
+// 生�.elf格�
219
 void mcd_gen_coredump(struct thread_info_ops *ops)
219
 void mcd_gen_coredump(struct thread_info_ops *ops)
220
 {
220
 {
221
     int note_size;
221
     int note_size;

Middlewares/MCoreDump/inc/coredump.h → Middlewares/MCoreDump/coredump.h View File

12
 #define __COREDUMP_H__
12
 #define __COREDUMP_H__
13
 
13
 
14
 #include "mcd_cfg.h"
14
 #include "mcd_cfg.h"
15
-#include "mcd_arm_define.h"
15
+#include "arm/mcd_arm_define.h"
16
 
16
 
17
 /**
17
 /**
18
  * @brief Function pointer type for coredump data output
18
  * @brief Function pointer type for coredump data output
83
     int32_t (*get_memarea)(struct thread_info_ops *, int32_t,
83
     int32_t (*get_memarea)(struct thread_info_ops *, int32_t,
84
                            uint32_t *, uint32_t *);
84
                            uint32_t *, uint32_t *);
85
 
85
 
86
+    // 打印字符串形式的coredump信息
87
+    int (*print_info_string)(struct thread_info_ops *);
88
+
86
     /** Private data for RTOS-specific implementations */
89
     /** Private data for RTOS-specific implementations */
87
     void *priv;
90
     void *priv;
88
 };
91
 };

+ 0
- 69
Middlewares/MCoreDump/example/mcd_example.c View File

1
-/*
2
- * Copyright (c) 2025, RT-Thread Development Team
3
- *
4
- * SPDX-License-Identifier: Apache-2.0
5
- *
6
- * Change Logs:
7
- * Date           Author       Notes
8
- * 2025-08-16     Rbb666       first version
9
- */
10
-
11
-#include <math.h>
12
-#include <stdlib.h>
13
-#include <string.h>
14
-#include "coredump.h"
15
-
16
-typedef void (*fault_func)(float);
17
-
18
-static int mcd_test(int argc, char **argv)
19
-{
20
-    int x, y;
21
-    const char * sx = "84597";
22
-    const char * sy = "35268";
23
-
24
-    float a, b, c;
25
-    const char * fsa = "1.1322";
26
-    const char * fsb = "45.2547";
27
-    const char * fsc = "7854.2";
28
-
29
-    if (argc < 2)
30
-    {
31
-        rt_kprintf("Please input 'mcd_test <COREDUMP|ASSERT|FAULT>' \n");
32
-        return 0;
33
-    }
34
-
35
-    if (!strcmp(argv[1], "COREDUMP"))
36
-    {
37
-        mcd_faultdump(MCD_OUTPUT_SERIAL);
38
-        return 0;
39
-    }
40
-    else if (!strcmp(argv[1], "ASSERT"))
41
-    {
42
-        a = atof(&fsa[0]);
43
-        b = atof(&fsb[0]);
44
-        c = atof(&fsc[0]);
45
-
46
-        x = atoi(&sx[0]);
47
-        y = atoi(&sy[0]);
48
-
49
-        mcd_assert(x * a == y * b * c);
50
-        return 0;
51
-    }
52
-    else if (!strcmp(argv[1], "FAULT"))
53
-    {
54
-        fault_func func = (fault_func)0xFFFF0000;
55
-        
56
-        a = atof(&fsa[0]);
57
-        b = atof(&fsb[0]);
58
-        c = atof(&fsc[0]);
59
-
60
-        x = atoi(&sx[0]);
61
-        y = atoi(&sy[0]);
62
-
63
-        func(x * a + y * b * c);
64
-        return 0;
65
-    }
66
-    
67
-    return 0;
68
-}
69
-MCD_CMD_EXPORT(mcd_test, mCoreDump test: mcd_test <COREDUMP|FLOAT|ASSERT|FAULT>);

Middlewares/MCoreDump/src/faultdump.c → Middlewares/MCoreDump/faultdump.c View File


Middlewares/MCoreDump/inc/mcd_cfg.h → Middlewares/MCoreDump/mcd_cfg.h View File


Middlewares/MCoreDump/inc/mcd_elf_define.h → Middlewares/MCoreDump/mcd_elf_define.h View File


Middlewares/MCoreDump/osal/rtthread.c → Middlewares/MCoreDump/rtthread_port.c View File

10
 
10
 
11
 #include <rtthread.h>
11
 #include <rtthread.h>
12
 #include "coredump.h"
12
 #include "coredump.h"
13
-#include "mcd_arch_interface.h"
13
+#include "arch/mcd_arch_interface.h"
14
 
14
 
15
 #define PRINT_COREDUMP_INFO_STRING 1 // 打印字符串格式的coredump信息
15
 #define PRINT_COREDUMP_INFO_STRING 1 // 打印字符串格式的coredump信息
16
 
16
 
23
     rt_int32_t cur_idx;
23
     rt_int32_t cur_idx;
24
 } rtthread_ti_priv_t;
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
 static rt_int32_t is_thread_object(rt_thread_t thread)
26
 static rt_int32_t is_thread_object(rt_thread_t thread)
36
 {
27
 {
37
     /* Check if the object is a thread (both static and dynamic) */
28
     /* Check if the object is a thread (both static and dynamic) */
190
     return 0;
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
 #if PRINT_COREDUMP_INFO_STRING
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
     rt_int32_t idx_l = 0;
188
     rt_int32_t idx_l = 0;
291
     struct rt_object_information *information;
189
     struct rt_object_information *information;
292
     struct rt_object *object;
190
     struct rt_object *object;
296
 
194
 
297
     information = rt_object_get_information(RT_Object_Class_Thread);
195
     information = rt_object_get_information(RT_Object_Class_Thread);
298
     mcd_assert(information != RT_NULL);
196
     mcd_assert(information != RT_NULL);
197
+    mcd_print("\n\n");
299
 
198
 
300
     for (node = information->object_list.next; node != &(information->object_list); node = node->next)
199
     for (node = information->object_list.next; node != &(information->object_list); node = node->next)
301
     {
200
     {
316
                     memlen = thread->stack_size;
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
             else
220
             else
322
             {
221
             {
323
                 addr = (rt_uint32_t)thread->sp;
222
                 addr = (rt_uint32_t)thread->sp;
324
                 memlen = (rt_uint32_t)thread->stack_addr + thread->stack_size - (rt_uint32_t)thread->sp;
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
             idx_l++;
231
             idx_l++;
330
         }
232
         }
331
     }
233
     }
334
 }
236
 }
335
 #endif
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
 #if PRINT_COREDUMP_INFO_STRING
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
 #endif
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
     return -RT_ERROR;
258
     return -RT_ERROR;
344
 }
259
 }
345
 
260
 
360
 
275
 
361
 static int mcd_coredump_init(void)
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
     //mcd_print_memoryinfo();
278
     //mcd_print_memoryinfo();
371
-
372
     rt_hw_exception_install(rtt_hard_fault_exception_hook);
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
 INIT_DEVICE_EXPORT(mcd_coredump_init);
285
 INIT_DEVICE_EXPORT(mcd_coredump_init);

Loading…
Cancel
Save