2 * Copyright (c) 2014 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup taskdump
39 #include <fibrildump.h>
40 #include <stacktrace.h>
53 static errno_t
fibrildump_read_uintptr(void *, uintptr_t, uintptr_t *);
55 static stacktrace_ops_t fibrildump_st_ops
= {
56 .read_uintptr
= fibrildump_read_uintptr
59 static errno_t
fibrildump_read_uintptr(void *arg
, uintptr_t addr
, uintptr_t *data
)
61 async_sess_t
*sess
= (async_sess_t
*)arg
;
63 return udebug_mem_read(sess
, data
, addr
, sizeof(uintptr_t));
66 static errno_t
read_link(async_sess_t
*sess
, uintptr_t addr
, link_t
*link
)
70 rc
= udebug_mem_read(sess
, (void *)link
, addr
, sizeof(link_t
));
74 static errno_t
read_fibril(async_sess_t
*sess
, uintptr_t addr
, fibril_t
*fibril
)
78 rc
= udebug_mem_read(sess
, (void *)fibril
, addr
, sizeof(fibril_t
));
82 errno_t
fibrils_dump(symtab_t
*symtab
, async_sess_t
*sess
)
84 uintptr_t fibril_list_addr
;
87 uintptr_t addr
, fibril_addr
;
92 * If we for whatever reason could not obtain symbols table from the binary,
93 * we cannot dump fibrils.
99 rc
= symtab_name_to_addr(symtab
, "fibril_list", &fibril_list_addr
);
103 addr
= fibril_list_addr
;
105 rc
= read_link(sess
, addr
, &link
);
109 addr
= (uintptr_t) link
.next
;
110 if (addr
== fibril_list_addr
)
113 fibril_addr
= (uintptr_t) list_get_instance((void *)addr
,
115 printf("Fibril %p:\n", (void *) fibril_addr
);
116 rc
= read_fibril(sess
, fibril_addr
, &fibril
);
120 pc
= context_get_pc(&fibril
.ctx
);
121 fp
= context_get_fp(&fibril
.ctx
);
123 stacktrace_print_generic(&fibrildump_st_ops
, sess
,
125 td_stacktrace(fp
, pc
);