[c1b979a] | 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 |
|
---|
[d73d992] | 35 | #include <adt/list.h>
|
---|
| 36 | #include <context.h>
|
---|
[c1b979a] | 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 |
|
---|
[d73d992] | 47 | struct fibril {
|
---|
| 48 | link_t all_link;
|
---|
| 49 | context_t ctx;
|
---|
| 50 | uint8_t __opaque[];
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[b7fd2a0] | 53 | static errno_t fibrildump_read_uintptr(void *, uintptr_t, uintptr_t *);
|
---|
[c1b979a] | 54 |
|
---|
| 55 | static stacktrace_ops_t fibrildump_st_ops = {
|
---|
| 56 | .read_uintptr = fibrildump_read_uintptr
|
---|
[1b20da0] | 57 | };
|
---|
[c1b979a] | 58 |
|
---|
[b7fd2a0] | 59 | static errno_t fibrildump_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data)
|
---|
[c1b979a] | 60 | {
|
---|
| 61 | async_sess_t *sess = (async_sess_t *)arg;
|
---|
| 62 |
|
---|
| 63 | return udebug_mem_read(sess, data, addr, sizeof(uintptr_t));
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[b7fd2a0] | 66 | static errno_t read_link(async_sess_t *sess, uintptr_t addr, link_t *link)
|
---|
[c1b979a] | 67 | {
|
---|
[b7fd2a0] | 68 | errno_t rc;
|
---|
[c1b979a] | 69 |
|
---|
| 70 | rc = udebug_mem_read(sess, (void *)link, addr, sizeof(link_t));
|
---|
| 71 | return rc;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[b7fd2a0] | 74 | static errno_t read_fibril(async_sess_t *sess, uintptr_t addr, fibril_t *fibril)
|
---|
[c1b979a] | 75 | {
|
---|
[b7fd2a0] | 76 | errno_t rc;
|
---|
[c1b979a] | 77 |
|
---|
| 78 | rc = udebug_mem_read(sess, (void *)fibril, addr, sizeof(fibril_t));
|
---|
| 79 | return rc;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[b7fd2a0] | 82 | errno_t fibrils_dump(symtab_t *symtab, async_sess_t *sess)
|
---|
[c1b979a] | 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;
|
---|
[b7fd2a0] | 89 | errno_t rc;
|
---|
[c1b979a] | 90 |
|
---|
[1b20da0] | 91 | /*
|
---|
[1619faa] | 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 |
|
---|
[c1b979a] | 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 |
|
---|
[e0a4686] | 120 | pc = context_get_pc(&fibril.ctx);
|
---|
[c1b979a] | 121 | fp = context_get_fp(&fibril.ctx);
|
---|
[1433ecda] | 122 | if (0)
|
---|
| 123 | stacktrace_print_generic(&fibrildump_st_ops, sess,
|
---|
| 124 | fp, pc);
|
---|
[c1b979a] | 125 | td_stacktrace(fp, pc);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | return EOK;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /** @}
|
---|
| 132 | */
|
---|