source: mainline/uspace/app/taskdump/fibrildump.c

Last change on this file was d73d992, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Hide libc-internal details of the fibril implementation.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2014 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
16 *
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.
27 */
28
29/** @addtogroup taskdump
30 * @{
31 */
32/** @file
33 */
34
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>
46
47struct fibril {
48 link_t all_link;
49 context_t ctx;
50 uint8_t __opaque[];
51};
52
53static errno_t fibrildump_read_uintptr(void *, uintptr_t, uintptr_t *);
54
55static stacktrace_ops_t fibrildump_st_ops = {
56 .read_uintptr = fibrildump_read_uintptr
57};
58
59static errno_t fibrildump_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data)
60{
61 async_sess_t *sess = (async_sess_t *)arg;
62
63 return udebug_mem_read(sess, data, addr, sizeof(uintptr_t));
64}
65
66static errno_t read_link(async_sess_t *sess, uintptr_t addr, link_t *link)
67{
68 errno_t rc;
69
70 rc = udebug_mem_read(sess, (void *)link, addr, sizeof(link_t));
71 return rc;
72}
73
74static errno_t read_fibril(async_sess_t *sess, uintptr_t addr, fibril_t *fibril)
75{
76 errno_t rc;
77
78 rc = udebug_mem_read(sess, (void *)fibril, addr, sizeof(fibril_t));
79 return rc;
80}
81
82errno_t fibrils_dump(symtab_t *symtab, async_sess_t *sess)
83{
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;
90
91 /*
92 * If we for whatever reason could not obtain symbols table from the binary,
93 * we cannot dump fibrils.
94 */
95 if (symtab == NULL) {
96 return EIO;
97 }
98
99 rc = symtab_name_to_addr(symtab, "fibril_list", &fibril_list_addr);
100 if (rc != EOK)
101 return EIO;
102
103 addr = fibril_list_addr;
104 while (true) {
105 rc = read_link(sess, addr, &link);
106 if (rc != EOK)
107 return EIO;
108
109 addr = (uintptr_t) link.next;
110 if (addr == fibril_list_addr)
111 break;
112
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;
119
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);
126 }
127
128 return EOK;
129}
130
131/** @}
132 */
Note: See TracBrowser for help on using the repository browser.