|
|
@@ -23,11 +23,11 @@ typedef struct
|
|
23
|
23
|
|
|
24
|
24
|
/* Architecture-specific exception hook function */
|
|
25
|
25
|
#ifdef PKG_USING_MCOREDUMP_ARCH_ARMV7M
|
|
26
|
|
-#define arch_hard_fault_exception_hook armv7m_hard_fault_exception_hook
|
|
|
26
|
+ #define arch_hard_fault_exception_hook armv7m_hard_fault_exception_hook
|
|
27
|
27
|
#elif defined(PKG_USING_MCOREDUMP_ARCH_ARMV8M)
|
|
28
|
|
-#define arch_hard_fault_exception_hook armv8m_hard_fault_exception_hook
|
|
|
28
|
+ #define arch_hard_fault_exception_hook armv8m_hard_fault_exception_hook
|
|
29
|
29
|
#else
|
|
30
|
|
-#error "MCoredump does not support this architecture"
|
|
|
30
|
+ #error "MCoredump does not support this architecture"
|
|
31
|
31
|
#endif
|
|
32
|
32
|
|
|
33
|
33
|
static rt_int32_t is_thread_object(rt_thread_t thread)
|
|
|
@@ -36,7 +36,7 @@ static rt_int32_t is_thread_object(rt_thread_t thread)
|
|
36
|
36
|
return ((thread->type & ~RT_Object_Class_Static) == RT_Object_Class_Thread);
|
|
37
|
37
|
}
|
|
38
|
38
|
|
|
39
|
|
-static int32_t rtthread_thr_cnts(struct thread_info_ops *ops)
|
|
|
39
|
+static int32_t rtthread_thread_cnts(struct thread_info_ops *ops)
|
|
40
|
40
|
{
|
|
41
|
41
|
rtthread_ti_priv_t *priv = (rtthread_ti_priv_t *)ops->priv;
|
|
42
|
42
|
rt_int32_t idx = 0;
|
|
|
@@ -49,13 +49,13 @@ static int32_t rtthread_thr_cnts(struct thread_info_ops *ops)
|
|
49
|
49
|
{
|
|
50
|
50
|
information = rt_object_get_information(RT_Object_Class_Thread);
|
|
51
|
51
|
mcd_assert(information != RT_NULL);
|
|
52
|
|
-
|
|
|
52
|
+
|
|
53
|
53
|
current_thread = rt_thread_self();
|
|
54
|
54
|
priv->cur_idx = -1; /* Initialize current thread index */
|
|
55
|
55
|
|
|
56
|
56
|
for (node = information->object_list.next;
|
|
57
|
|
- node != &(information->object_list);
|
|
58
|
|
- node = node->next)
|
|
|
57
|
+ node != &(information->object_list);
|
|
|
58
|
+ node = node->next)
|
|
59
|
59
|
{
|
|
60
|
60
|
object = rt_list_entry(node, struct rt_object, list);
|
|
61
|
61
|
rt_thread_t thread = (rt_thread_t)object;
|
|
|
@@ -72,7 +72,7 @@ static int32_t rtthread_thr_cnts(struct thread_info_ops *ops)
|
|
72
|
72
|
}
|
|
73
|
73
|
|
|
74
|
74
|
priv->thr_cnts = idx;
|
|
75
|
|
-
|
|
|
75
|
+
|
|
76
|
76
|
/* If current thread not found, default to 0 */
|
|
77
|
77
|
if (priv->cur_idx == -1)
|
|
78
|
78
|
{
|
|
|
@@ -84,22 +84,22 @@ static int32_t rtthread_thr_cnts(struct thread_info_ops *ops)
|
|
84
|
84
|
return priv->thr_cnts;
|
|
85
|
85
|
}
|
|
86
|
86
|
|
|
87
|
|
-static int32_t rtthread_cur_idx(struct thread_info_ops *ops)
|
|
|
87
|
+static int32_t rtthread_cur_index(struct thread_info_ops *ops)
|
|
88
|
88
|
{
|
|
89
|
89
|
rtthread_ti_priv_t *priv = (rtthread_ti_priv_t *)ops->priv;
|
|
90
|
90
|
|
|
91
|
91
|
if (-1 == priv->cur_idx)
|
|
92
|
|
- rtthread_thr_cnts(ops);
|
|
|
92
|
+ rtthread_thread_cnts(ops);
|
|
93
|
93
|
|
|
94
|
94
|
return priv->cur_idx;
|
|
95
|
95
|
}
|
|
96
|
96
|
|
|
97
|
|
-static void rtthread_thr_rset(struct thread_info_ops *ops, int32_t idx,
|
|
98
|
|
- core_regset_type *core_regset,
|
|
99
|
|
- fp_regset_type *fp_regset)
|
|
|
97
|
+static void rtthread_thread_register(struct thread_info_ops *ops, int32_t idx,
|
|
|
98
|
+ core_regset_type *core_regset,
|
|
|
99
|
+ fp_regset_type *fp_regset)
|
|
100
|
100
|
{
|
|
101
|
101
|
rt_int32_t idx_l = 0;
|
|
102
|
|
- rt_int32_t current_idx = rtthread_cur_idx(ops);
|
|
|
102
|
+ rt_int32_t current_idx = rtthread_cur_index(ops);
|
|
103
|
103
|
struct rt_object_information *information;
|
|
104
|
104
|
struct rt_object *object;
|
|
105
|
105
|
struct rt_list_node *node;
|
|
|
@@ -107,9 +107,7 @@ static void rtthread_thr_rset(struct thread_info_ops *ops, int32_t idx,
|
|
107
|
107
|
information = rt_object_get_information(RT_Object_Class_Thread);
|
|
108
|
108
|
mcd_assert(information != RT_NULL);
|
|
109
|
109
|
|
|
110
|
|
- for (node = information->object_list.next;
|
|
111
|
|
- node != &(information->object_list);
|
|
112
|
|
- node = node->next)
|
|
|
110
|
+ for (node = information->object_list.next; node != &(information->object_list); node = node->next)
|
|
113
|
111
|
{
|
|
114
|
112
|
object = rt_list_entry(node, struct rt_object, list);
|
|
115
|
113
|
rt_thread_t thread = (rt_thread_t)object;
|
|
|
@@ -121,7 +119,7 @@ static void rtthread_thr_rset(struct thread_info_ops *ops, int32_t idx,
|
|
121
|
119
|
/* If this is the current thread, use current registers */
|
|
122
|
120
|
if (idx_l == current_idx)
|
|
123
|
121
|
{
|
|
124
|
|
- mcd_memcpy(core_regset, get_cur_core_regset_address(), sizeof(core_regset_type));
|
|
|
122
|
+ mcd_memcpy(core_regset, get_cur_core_regset_address(), sizeof(core_regset_type)); // 异常中填充
|
|
125
|
123
|
mcd_memcpy(fp_regset, get_cur_fp_regset_address(), sizeof(fp_regset_type));
|
|
126
|
124
|
}
|
|
127
|
125
|
else
|
|
|
@@ -138,14 +136,14 @@ static void rtthread_thr_rset(struct thread_info_ops *ops, int32_t idx,
|
|
138
|
136
|
|
|
139
|
137
|
static int32_t rtthread_get_mem_cnts(struct thread_info_ops *ops)
|
|
140
|
138
|
{
|
|
141
|
|
- return rtthread_thr_cnts(ops);
|
|
|
139
|
+ return rtthread_thread_cnts(ops);
|
|
142
|
140
|
}
|
|
143
|
141
|
|
|
144
|
142
|
static int32_t rtthread_get_memarea(struct thread_info_ops *ops, int32_t idx,
|
|
145
|
|
- uint32_t *addr, uint32_t *memlen)
|
|
|
143
|
+ uint32_t *addr, uint32_t *memlen)
|
|
146
|
144
|
{
|
|
147
|
|
- rt_int32_t idx_l = 0;
|
|
148
|
|
- rt_int32_t current_idx = rtthread_cur_idx(ops);
|
|
|
145
|
+ rt_int32_t idx_l = 0;
|
|
|
146
|
+ rt_int32_t current_idx = rtthread_cur_index(ops);
|
|
149
|
147
|
struct rt_object_information *information;
|
|
150
|
148
|
struct rt_object *object;
|
|
151
|
149
|
struct rt_list_node *node;
|
|
|
@@ -153,9 +151,7 @@ static int32_t rtthread_get_memarea(struct thread_info_ops *ops, int32_t idx,
|
|
153
|
151
|
information = rt_object_get_information(RT_Object_Class_Thread);
|
|
154
|
152
|
mcd_assert(information != RT_NULL);
|
|
155
|
153
|
|
|
156
|
|
- for (node = information->object_list.next;
|
|
157
|
|
- node != &(information->object_list);
|
|
158
|
|
- node = node->next)
|
|
|
154
|
+ for (node = information->object_list.next; node != &(information->object_list); node = node->next)
|
|
159
|
155
|
{
|
|
160
|
156
|
object = rt_list_entry(node, struct rt_object, list);
|
|
161
|
157
|
rt_thread_t thread = (rt_thread_t)object;
|
|
|
@@ -167,8 +163,14 @@ static int32_t rtthread_get_memarea(struct thread_info_ops *ops, int32_t idx,
|
|
167
|
163
|
/* If this is the current thread, use current stack pointer */
|
|
168
|
164
|
if (idx_l == current_idx)
|
|
169
|
165
|
{
|
|
170
|
|
- *addr = get_cur_core_regset_address()->sp;
|
|
171
|
|
- *memlen = 1024;
|
|
|
166
|
+ *addr = get_cur_core_regset_address()->sp; // 异常中填充
|
|
|
167
|
+ *memlen = (rt_uint32_t)thread->stack_addr + thread->stack_size - (rt_uint32_t)thread->sp;
|
|
|
168
|
+
|
|
|
169
|
+ if (*memlen > thread->stack_size)
|
|
|
170
|
+ {
|
|
|
171
|
+ mcd_println("The stack may overflow!!!");
|
|
|
172
|
+ *memlen = thread->stack_size;
|
|
|
173
|
+ }
|
|
172
|
174
|
}
|
|
173
|
175
|
else
|
|
174
|
176
|
{
|
|
|
@@ -186,9 +188,9 @@ static int32_t rtthread_get_memarea(struct thread_info_ops *ops, int32_t idx,
|
|
186
|
188
|
void mcd_rtos_thread_ops(struct thread_info_ops *ops)
|
|
187
|
189
|
{
|
|
188
|
190
|
static rtthread_ti_priv_t priv;
|
|
189
|
|
- ops->get_threads_count = rtthread_thr_cnts;
|
|
190
|
|
- ops->get_current_thread_idx = rtthread_cur_idx;
|
|
191
|
|
- ops->get_thread_regset = rtthread_thr_rset;
|
|
|
191
|
+ ops->get_threads_count = rtthread_thread_cnts;
|
|
|
192
|
+ ops->get_current_thread_idx = rtthread_cur_index;
|
|
|
193
|
+ ops->get_thread_regset = rtthread_thread_register;
|
|
192
|
194
|
ops->get_memarea_count = rtthread_get_mem_cnts;
|
|
193
|
195
|
ops->get_memarea = rtthread_get_memarea;
|
|
194
|
196
|
ops->priv = &priv;
|
|
|
@@ -217,7 +219,7 @@ MCD_WEAK void rtt_assert_hook(const char *ex, const char *func, rt_size_t line)
|
|
217
|
219
|
while (_continue == 1);
|
|
218
|
220
|
}
|
|
219
|
221
|
|
|
220
|
|
-static int mcd_coredump_init(void)
|
|
|
222
|
+static int mcd_coredump_init(void)
|
|
221
|
223
|
{
|
|
222
|
224
|
static mcd_bool_t is_init = MCD_FALSE;
|
|
223
|
225
|
|
|
|
@@ -227,11 +229,11 @@ static int mcd_coredump_init(void)
|
|
227
|
229
|
}
|
|
228
|
230
|
|
|
229
|
231
|
//mcd_print_memoryinfo();
|
|
230
|
|
-
|
|
|
232
|
+
|
|
231
|
233
|
rt_hw_exception_install(rtt_hard_fault_exception_hook);
|
|
232
|
234
|
|
|
233
|
235
|
//rt_assert_set_hook(rtt_assert_hook);
|
|
234
|
|
-
|
|
|
236
|
+
|
|
235
|
237
|
is_init = MCD_TRUE;
|
|
236
|
238
|
return RT_EOK;
|
|
237
|
239
|
}
|