C++ strings: missing space for null terminator
[helenos.git] / uspace / app / taskdump / fibrildump.c
blob7401c86c5041d5e7de189c6f6f46ba0a801fcdce
1 /*
2 * Copyright (c) 2014 Jiri Svoboda
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
30 * @{
32 /** @file
35 #include <adt/list.h>
36 #include <context.h>
37 #include <errno.h>
38 #include <fibril.h>
39 #include <fibrildump.h>
40 #include <stacktrace.h>
41 #include <stdio.h>
42 #include <stdbool.h>
43 #include <symtab.h>
44 #include <taskdump.h>
45 #include <udebug.h>
47 struct fibril {
48 link_t all_link;
49 context_t ctx;
50 uint8_t __opaque[];
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)
68 errno_t rc;
70 rc = udebug_mem_read(sess, (void *)link, addr, sizeof(link_t));
71 return rc;
74 static errno_t read_fibril(async_sess_t *sess, uintptr_t addr, fibril_t *fibril)
76 errno_t rc;
78 rc = udebug_mem_read(sess, (void *)fibril, addr, sizeof(fibril_t));
79 return rc;
82 errno_t fibrils_dump(symtab_t *symtab, async_sess_t *sess)
84 uintptr_t fibril_list_addr;
85 link_t link;
86 fibril_t fibril;
87 uintptr_t addr, fibril_addr;
88 uintptr_t pc, fp;
89 errno_t rc;
92 * If we for whatever reason could not obtain symbols table from the binary,
93 * we cannot dump fibrils.
95 if (symtab == NULL) {
96 return EIO;
99 rc = symtab_name_to_addr(symtab, "fibril_list", &fibril_list_addr);
100 if (rc != EOK)
101 return EIO;
103 addr = fibril_list_addr;
104 while (true) {
105 rc = read_link(sess, addr, &link);
106 if (rc != EOK)
107 return EIO;
109 addr = (uintptr_t) link.next;
110 if (addr == fibril_list_addr)
111 break;
113 fibril_addr = (uintptr_t) list_get_instance((void *)addr,
114 fibril_t, all_link);
115 printf("Fibril %p:\n", (void *) fibril_addr);
116 rc = read_fibril(sess, fibril_addr, &fibril);
117 if (rc != EOK)
118 return EIO;
120 pc = context_get_pc(&fibril.ctx);
121 fp = context_get_fp(&fibril.ctx);
122 if (0)
123 stacktrace_print_generic(&fibrildump_st_ops, sess,
124 fp, pc);
125 td_stacktrace(fp, pc);
128 return EOK;
131 /** @}