1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #include "debug_api.h"
6 
debug_task_find(char * name)7 ktask_t *debug_task_find(char *name)
8 {
9 #if (RHINO_CONFIG_KOBJ_LIST > 0)
10     klist_t *listnode;
11     ktask_t *task;
12 
13     for (listnode = g_kobj_list.task_head.next;
14          listnode != &g_kobj_list.task_head; listnode = listnode->next) {
15         task = krhino_list_entry(listnode, ktask_t, task_stats_item);
16         if (0 == strcmp(name, task->task_name)) {
17             return task;
18         }
19     }
20 #endif
21 
22     return NULL;
23 }
24 
debug_task_find_running(char ** name)25 ktask_t *debug_task_find_running(char **name)
26 {
27     ktask_t *task_running;
28 
29     task_running = g_active_task[cpu_cur_get()];
30     if (task_running != NULL && name != NULL) {
31         *name = (char *)task_running->task_name;
32     }
33     return task_running;
34 }
35 
debug_task_find_by_id(uint32_t task_id)36 ktask_t *debug_task_find_by_id(uint32_t task_id)
37 {
38 #if (RHINO_CONFIG_KOBJ_LIST > 0)
39     klist_t *listnode;
40     ktask_t *task;
41 
42     for (listnode = g_kobj_list.task_head.next;
43          listnode != &g_kobj_list.task_head; listnode = listnode->next) {
44         task = krhino_list_entry(listnode, ktask_t, task_stats_item);
45         if (task->task_id == task_id) {
46             return task;
47         }
48     }
49 #endif
50 
51     return NULL;
52 }
53 
54 /* return:
55    0 not ready
56    1 ready but not running
57    2 running but interrupted
58    3 running*/
debug_task_is_running(ktask_t * task)59 int debug_task_is_running(ktask_t *task)
60 {
61     int i;
62     for (i = 0; i < RHINO_CONFIG_CPU_NUM; i++) {
63         if (g_active_task[i] == task
64             && g_intrpt_nested_level[i] == 0) {
65             return 3;
66         } else if (g_active_task[i] == task) {
67             return 2;
68         }
69     }
70 
71     if (task->task_state == K_RDY) {
72         return 1;
73     } else {
74         return 0;
75     }
76 }
77 
debug_task_id_now()78 uint32_t debug_task_id_now()
79 {
80     if (g_active_task[cpu_cur_get()] == NULL || g_intrpt_nested_level[cpu_cur_get()] != 0) {
81         return 0;
82     }
83 
84     return g_active_task[cpu_cur_get()]->task_id;
85 }
86 
debug_task_stack_bottom(ktask_t * task)87 void *debug_task_stack_bottom(ktask_t *task)
88 {
89     if (task == NULL) {
90         task = g_active_task[cpu_cur_get()];
91     }
92 
93     if (task->task_state == K_DELETED) {
94         return NULL;
95     }
96 
97 #if (RHINO_CONFIG_CPU_STACK_DOWN > 0)
98     return task->task_stack_base + task->stack_size;
99 #else
100     return task->task_stack_base;
101 #endif
102 }
103 
104