1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #include <stdio.h>
6 #include "k_api.h"
7 
8 /* follow functions should defined by arch\...\backtrace.c */
9 extern int backtrace_now(int (*print_func)(const char *fmt, ...));
10 extern int backtrace_task(void *task, int (*print_func)(const char *fmt, ...));
11 
debug_backtrace_now(int32_t (* print_func)(const char * fmt,...))12 void debug_backtrace_now(int32_t (*print_func)(const char *fmt, ...))
13 {
14     backtrace_now(print_func);
15 }
16 
debug_backtrace_task(char * taskname,int32_t (* print_func)(const char * fmt,...))17 void debug_backtrace_task(char *taskname, int32_t (*print_func)(const char *fmt, ...))
18 {
19     klist_t *listnode;
20     ktask_t *task;
21 
22     for (listnode = g_kobj_list.task_head.next;
23          listnode != &g_kobj_list.task_head; listnode = listnode->next) {
24         task = krhino_list_entry(listnode, ktask_t, task_stats_item);
25         if (taskname) {
26             if (0 == strcmp(taskname, "all")) {
27                 print_func("task name \"%s\" \r\n",
28                        ((ktask_t *)task)->task_name ? ((ktask_t *)task)->task_name : "anonym");
29                 backtrace_task(task, print_func);
30             } else {
31                 if (0 == strcmp(taskname, task->task_name)) {
32                     backtrace_task(task, print_func);
33                 }
34             }
35         }
36     }
37 }
38 
39 void backtrace_handle(char *PC, int *SP, char *LR, int (*print_func)(const char *fmt, ...));
debug_panic_backtrace(char * PC,int * SP,char * LR,int (* print_func)(const char * fmt,...))40 void debug_panic_backtrace(char *PC, int *SP, char *LR,
41                            int (*print_func)(const char *fmt, ...))
42 {
43     backtrace_handle(PC, SP, LR, print_func);
44 }
45