ソースを参照

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

rtthread_MCoreDump
huangyulong 2ヶ月前
コミット
1b53ae7e2d
2個のファイルの変更29行の追加11行の削除
  1. 11
    0
      Middlewares/MCoreDump/coredump.c
  2. 18
    11
      Middlewares/MCoreDump/rtthread_port.c

+ 11
- 0
Middlewares/MCoreDump/coredump.c ファイルの表示

@@ -199,6 +199,9 @@ void mcd_init(mcd_writeout_func_t func)
199 199
 
200 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 205
     fill_note_prstatus(&m_ctx.tmp.prstatus, core_regset);
203 206
     m_ctx.writeout_func((uint8_t *)&m_ctx.tmp.prstatus, sizeof(elf_note_prstatus_t));
204 207
 
@@ -218,6 +221,10 @@ static void addr_align(uint32_t *addr, uint32_t *memlen)
218 221
 // 生成.elf格式
219 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 228
     int note_size;
222 229
     uint32_t addr, memlen;
223 230
 
@@ -265,6 +272,9 @@ void mcd_gen_coredump(struct thread_info_ops *ops)
265 272
 
266 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 278
     int elf_size = 0;
269 279
     int segment_count;
270 280
     uint32_t addr, memlen;
@@ -337,6 +347,7 @@ static int32_t minidump_memarea(struct thread_info_ops *ops, int32_t idx,
337 347
 
338 348
 void mcd_mini_dump_ops(struct thread_info_ops *ops)
339 349
 {
350
+    memset(ops, 0, sizeof(struct thread_info_ops));
340 351
     ops->get_threads_count = minidump_thr_cnts;
341 352
     ops->get_current_thread_idx = minidump_cur_idx;
342 353
     ops->get_thread_regset = minidump_thr_rset;

+ 18
- 11
Middlewares/MCoreDump/rtthread_port.c ファイルの表示

@@ -13,10 +13,18 @@
13 13
 #include "arch/mcd_arch_interface.h"
14 14
 #include "addr2line/addr2line.h"
15 15
 
16
+#define PRINT_COREDUMP_ELF 0 // 直接打印elf格式
16 17
 #define PRINT_COREDUMP_INFO_STRING 1 // 打印字符串格式的coredump信息
17 18
 #define STACK_CORE_REG_SIZE (17 * 4) // 16个自动+手动压栈寄存器 + exe_return
18 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 29
  * RT-Thread OS abstraction layer implementation for MCoreDump
22 30
  */
@@ -26,12 +34,6 @@ typedef struct
26 34
     rt_int32_t cur_idx;
27 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 37
 static int32_t rtthread_thread_cnts(struct thread_info_ops *ops)
36 38
 {
37 39
     rtthread_ti_priv_t *priv = (rtthread_ti_priv_t *)ops->priv;
@@ -196,11 +198,12 @@ static int32_t rtthread_get_memarea(struct thread_info_ops *ops, int32_t idx,
196 198
     }
197 199
     return 0;
198 200
 }
201
+#endif
199 202
 
200 203
 #if PRINT_COREDUMP_INFO_STRING
201 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 207
     rt_int32_t idx_l = 0;
205 208
     struct rt_object_information *information;
206 209
     struct rt_object *object;
@@ -220,7 +223,7 @@ static int mcd_print_coredump_info_string(struct thread_info_ops *ops)
220 223
         if (is_thread_object(thread))
221 224
         {
222 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 228
                 uint32_t fpu_flag = 0;
226 229
                 addr = (rt_uint32_t)get_cur_core_regset_address()->sp;      // 异常中填充
@@ -273,18 +276,22 @@ static int mcd_print_coredump_info_string(struct thread_info_ops *ops)
273 276
 
274 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 281
     static rtthread_ti_priv_t priv;
277 282
     ops->get_threads_count = rtthread_thread_cnts;
278 283
     ops->get_current_thread_idx = rtthread_cur_index;
279 284
     ops->get_thread_regset = rtthread_thread_register;
280 285
     ops->get_memarea_count = rtthread_get_mem_cnts;
281 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 287
     ops->priv = &priv;
286 288
     priv.cur_idx = -1;
287 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 297
 MCD_WEAK rt_err_t rtt_hard_fault_exception_hook(void *context)

読み込み中…
キャンセル
保存