8 #ifdef ABT_CONFIG_ENABLE_STACK_UNWIND
10 #ifndef ABT_CONFIG_ENABLE_PEEK_CONTEXT
11 #error "ABT_CONFIG_ENABLE_PEEK_CONTEXT must be enabled"
14 #define UNW_LOCAL_ONLY
15 #include <libunwind.h>
16 struct unwind_stack_t {
19 static void ythread_unwind_stack(
void *arg);
54 LOG_DEBUG(
"[U%" PRIu64
":E%d] suspended\n",
57 sync_event_type, p_sync);
78 LOG_DEBUG(
"[U%" PRIu64
":E%d] set ready\n",
106 "stacksize : %" PRIu64
"\n",
109 #ifdef ABT_CONFIG_ENABLE_STACK_UNWIND
117 struct unwind_stack_t arg;
119 ABTI_ythread_context_peek(p_ythread, ythread_unwind_stack, &arg);
124 void *p_stack = p_ythread->
p_stack;
125 size_t i, j, stacksize = p_ythread->
stacksize;
126 if (stacksize == 0 || p_stack == NULL) {
128 fprintf(p_os,
"no stack\n");
134 const size_t value_width = 8;
135 const int num_bytes =
sizeof(buffer);
137 for (i = 0; i < stacksize; i += num_bytes) {
138 if (stacksize >= i + num_bytes) {
139 memcpy(buffer, &((uint8_t *)p_stack)[i], num_bytes);
141 memset(buffer, 0, num_bytes);
142 memcpy(buffer, &((uint8_t *)p_stack)[i], stacksize - i);
145 #if SIZEOF_VOID_P == 8
146 fprintf(p_os,
"%016" PRIxPTR
":",
147 (uintptr_t)(&((uint8_t *)p_stack)[i]));
148 #elif SIZEOF_VOID_P == 4
149 fprintf(p_os,
"%08" PRIxPTR
":", (uintptr_t)(&((uint8_t *)p_stack)[i]));
151 #error "unknown pointer size"
154 for (j = 0; j < num_bytes / value_width; j++) {
155 if (value_width == 8) {
156 uint64_t val = ((uint64_t *)buffer)[j];
157 fprintf(p_os,
" %016" PRIx64, val);
158 }
else if (value_width == 4) {
159 uint32_t val = ((uint32_t *)buffer)[j];
160 fprintf(p_os,
" %08" PRIx32, val);
161 }
else if (value_width == 2) {
162 uint16_t val = ((uint16_t *)buffer)[j];
163 fprintf(p_os,
" %04" PRIx16, val);
165 uint8_t val = ((uint8_t *)buffer)[j];
166 fprintf(p_os,
" %02" PRIx8, val);
168 if (j == (num_bytes / value_width) - 1)
175 #ifdef ABT_CONFIG_ENABLE_STACK_UNWIND
183 ret = unw_getcontext(&uc);
187 ret = unw_init_local(&cursor, &uc);
191 while (unw_step(&cursor) > 0 && level < 50) {
194 ret = unw_get_reg(&cursor, UNW_REG_IP, &ip);
198 ret = unw_get_reg(&cursor, UNW_REG_SP, &sp);
204 ret = unw_get_proc_name(&cursor, proc_name, 256, &offset);
209 fprintf(fp,
"#%d %p in %s () <+%d> (%s = %p)\n", level,
210 (
void *)((uintptr_t)ip), proc_name, (
int)offset,
211 unw_regname(UNW_REG_SP), (
void *)((uintptr_t)sp));
216 static void ythread_unwind_stack(
void *arg)
218 struct unwind_stack_t *p_arg = (
struct unwind_stack_t *)arg;
219 if (ythread_unwind_stack_impl(p_arg->fp) !=
ABT_SUCCESS) {
220 fprintf(p_arg->fp,
"libunwind error\n");