Browse Source

[add] PRINT_COREDUMP_ELF 0 // 直接打印elf格式

rtthread_MCoreDump
huangyulong 2 months ago
parent
commit
1b53ae7e2d
2 changed files with 29 additions and 11 deletions
  1. 11
    0
      Middlewares/MCoreDump/coredump.c
  2. 18
    11
      Middlewares/MCoreDump/rtthread_port.c

+ 11
- 0
Middlewares/MCoreDump/coredump.c View File

199
 
199
 
200
 static void fill_one_threads_regset(core_regset_type *core_regset, fp_regset_type *fp_regset)
200
 static void fill_one_threads_regset(core_regset_type *core_regset, fp_regset_type *fp_regset)
201
 {
201
 {
202
+    if (NULL == m_ctx.writeout_func)
203
+        return;
204
+
202
     fill_note_prstatus(&m_ctx.tmp.prstatus, core_regset);
205
     fill_note_prstatus(&m_ctx.tmp.prstatus, core_regset);
203
     m_ctx.writeout_func((uint8_t *)&m_ctx.tmp.prstatus, sizeof(elf_note_prstatus_t));
206
     m_ctx.writeout_func((uint8_t *)&m_ctx.tmp.prstatus, sizeof(elf_note_prstatus_t));
204
 
207
 
218
 // 生成.elf格式
221
 // 生成.elf格式
219
 void mcd_gen_coredump(struct thread_info_ops *ops)
222
 void mcd_gen_coredump(struct thread_info_ops *ops)
220
 {
223
 {
224
+    if (NULL == ops || NULL == ops->get_memarea_count || NULL == ops->get_memarea
225
+        || NULL == ops->get_thread_regset || NULL == m_ctx.writeout_func)
226
+        return;
227
+
221
     int note_size;
228
     int note_size;
222
     uint32_t addr, memlen;
229
     uint32_t addr, memlen;
223
 
230
 
265
 
272
 
266
 int32_t mcd_corefile_size(struct thread_info_ops *ops)
273
 int32_t mcd_corefile_size(struct thread_info_ops *ops)
267
 {
274
 {
275
+    if (NULL == ops || NULL == ops->get_memarea_count || NULL == ops->get_memarea)
276
+        return 0;
277
+
268
     int elf_size = 0;
278
     int elf_size = 0;
269
     int segment_count;
279
     int segment_count;
270
     uint32_t addr, memlen;
280
     uint32_t addr, memlen;
337
 
347
 
338
 void mcd_mini_dump_ops(struct thread_info_ops *ops)
348
 void mcd_mini_dump_ops(struct thread_info_ops *ops)
339
 {
349
 {
350
+    memset(ops, 0, sizeof(struct thread_info_ops));
340
     ops->get_threads_count = minidump_thr_cnts;
351
     ops->get_threads_count = minidump_thr_cnts;
341
     ops->get_current_thread_idx = minidump_cur_idx;
352
     ops->get_current_thread_idx = minidump_cur_idx;
342
     ops->get_thread_regset = minidump_thr_rset;
353
     ops->get_thread_regset = minidump_thr_rset;

+ 18
- 11
Middlewares/MCoreDump/rtthread_port.c View File

13
 #include "arch/mcd_arch_interface.h"
13
 #include "arch/mcd_arch_interface.h"
14
 #include "addr2line/addr2line.h"
14
 #include "addr2line/addr2line.h"
15
 
15
 
16
+#define PRINT_COREDUMP_ELF 0 // 直接打印elf格式
16
 #define PRINT_COREDUMP_INFO_STRING 1 // 打印字符串格式的coredump信息
17
 #define PRINT_COREDUMP_INFO_STRING 1 // 打印字符串格式的coredump信息
17
 #define STACK_CORE_REG_SIZE (17 * 4) // 16个自动+手动压栈寄存器 + exe_return
18
 #define STACK_CORE_REG_SIZE (17 * 4) // 16个自动+手动压栈寄存器 + exe_return
18
 #define STACK_FPU_REG_SIZE (17 * 4) // 17个自动压栈的浮点寄存器
19
 #define STACK_FPU_REG_SIZE (17 * 4) // 17个自动压栈的浮点寄存器
19
 
20
 
21
+static rt_int32_t is_thread_object(rt_thread_t thread)
22
+{
23
+    /* Check if the object is a thread (both static and dynamic) */
24
+    return ((thread->type & ~RT_Object_Class_Static) == RT_Object_Class_Thread);
25
+}
26
+
27
+#if PRINT_COREDUMP_ELF
20
 /*
28
 /*
21
  * RT-Thread OS abstraction layer implementation for MCoreDump
29
  * RT-Thread OS abstraction layer implementation for MCoreDump
22
  */
30
  */
26
     rt_int32_t cur_idx;
34
     rt_int32_t cur_idx;
27
 } rtthread_ti_priv_t;
35
 } rtthread_ti_priv_t;
28
 
36
 
29
-static rt_int32_t is_thread_object(rt_thread_t thread)
30
-{
31
-    /* Check if the object is a thread (both static and dynamic) */
32
-    return ((thread->type & ~RT_Object_Class_Static) == RT_Object_Class_Thread);
33
-}
34
-
35
 static int32_t rtthread_thread_cnts(struct thread_info_ops *ops)
37
 static int32_t rtthread_thread_cnts(struct thread_info_ops *ops)
36
 {
38
 {
37
     rtthread_ti_priv_t *priv = (rtthread_ti_priv_t *)ops->priv;
39
     rtthread_ti_priv_t *priv = (rtthread_ti_priv_t *)ops->priv;
196
     }
198
     }
197
     return 0;
199
     return 0;
198
 }
200
 }
201
+#endif
199
 
202
 
200
 #if PRINT_COREDUMP_INFO_STRING
203
 #if PRINT_COREDUMP_INFO_STRING
201
 static int mcd_print_coredump_info_string(struct thread_info_ops *ops)
204
 static int mcd_print_coredump_info_string(struct thread_info_ops *ops)
202
 {
205
 {
203
-    rt_int32_t current_idx = rtthread_cur_index(ops);
206
+    rt_thread_t current_thread = rt_thread_self();
204
     rt_int32_t idx_l = 0;
207
     rt_int32_t idx_l = 0;
205
     struct rt_object_information *information;
208
     struct rt_object_information *information;
206
     struct rt_object *object;
209
     struct rt_object *object;
220
         if (is_thread_object(thread))
223
         if (is_thread_object(thread))
221
         {
224
         {
222
             /* If this is the current thread, use current stack pointer */
225
             /* If this is the current thread, use current stack pointer */
223
-            if (idx_l == current_idx)
226
+            if (thread == current_thread)
224
             {
227
             {
225
                 uint32_t fpu_flag = 0;
228
                 uint32_t fpu_flag = 0;
226
                 addr = (rt_uint32_t)get_cur_core_regset_address()->sp;      // 异常中填充
229
                 addr = (rt_uint32_t)get_cur_core_regset_address()->sp;      // 异常中填充
273
 
276
 
274
 void mcd_rtos_thread_ops(struct thread_info_ops *ops)
277
 void mcd_rtos_thread_ops(struct thread_info_ops *ops)
275
 {
278
 {
279
+    memset(ops, 0, sizeof(struct thread_info_ops));
280
+#if PRINT_COREDUMP_ELF
276
     static rtthread_ti_priv_t priv;
281
     static rtthread_ti_priv_t priv;
277
     ops->get_threads_count = rtthread_thread_cnts;
282
     ops->get_threads_count = rtthread_thread_cnts;
278
     ops->get_current_thread_idx = rtthread_cur_index;
283
     ops->get_current_thread_idx = rtthread_cur_index;
279
     ops->get_thread_regset = rtthread_thread_register;
284
     ops->get_thread_regset = rtthread_thread_register;
280
     ops->get_memarea_count = rtthread_get_mem_cnts;
285
     ops->get_memarea_count = rtthread_get_mem_cnts;
281
     ops->get_memarea = rtthread_get_memarea;
286
     ops->get_memarea = rtthread_get_memarea;
282
-#if PRINT_COREDUMP_INFO_STRING
283
-    ops->print_info_string = mcd_print_coredump_info_string;
284
-#endif
285
     ops->priv = &priv;
287
     ops->priv = &priv;
286
     priv.cur_idx = -1;
288
     priv.cur_idx = -1;
287
     priv.thr_cnts = -1;
289
     priv.thr_cnts = -1;
290
+#endif
291
+#if PRINT_COREDUMP_INFO_STRING
292
+    ops->print_info_string = mcd_print_coredump_info_string;
293
+#endif
294
+
288
 }
295
 }
289
 
296
 
290
 MCD_WEAK rt_err_t rtt_hard_fault_exception_hook(void *context)
297
 MCD_WEAK rt_err_t rtt_hard_fault_exception_hook(void *context)

Loading…
Cancel
Save