[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 |
|
---|
| 35 | #include <errno.h>
|
---|
| 36 | #include <fibril.h>
|
---|
| 37 | #include <fibrildump.h>
|
---|
| 38 | #include <stacktrace.h>
|
---|
| 39 | #include <stdio.h>
|
---|
| 40 | #include <stdbool.h>
|
---|
| 41 | #include <symtab.h>
|
---|
| 42 | #include <taskdump.h>
|
---|
| 43 | #include <udebug.h>
|
---|
| 44 |
|
---|
| 45 | static int fibrildump_read_uintptr(void *, uintptr_t, uintptr_t *);
|
---|
| 46 |
|
---|
| 47 | static stacktrace_ops_t fibrildump_st_ops = {
|
---|
| 48 | .read_uintptr = fibrildump_read_uintptr
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | static int fibrildump_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data)
|
---|
| 52 | {
|
---|
| 53 | async_sess_t *sess = (async_sess_t *)arg;
|
---|
| 54 |
|
---|
| 55 | return udebug_mem_read(sess, data, addr, sizeof(uintptr_t));
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | static int read_link(async_sess_t *sess, uintptr_t addr, link_t *link)
|
---|
| 59 | {
|
---|
| 60 | int rc;
|
---|
| 61 |
|
---|
| 62 | rc = udebug_mem_read(sess, (void *)link, addr, sizeof(link_t));
|
---|
| 63 | return rc;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | static int read_fibril(async_sess_t *sess, uintptr_t addr, fibril_t *fibril)
|
---|
| 67 | {
|
---|
| 68 | int rc;
|
---|
| 69 |
|
---|
| 70 | rc = udebug_mem_read(sess, (void *)fibril, addr, sizeof(fibril_t));
|
---|
| 71 | return rc;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | int fibrils_dump(symtab_t *symtab, async_sess_t *sess)
|
---|
| 75 | {
|
---|
| 76 | uintptr_t fibril_list_addr;
|
---|
| 77 | link_t link;
|
---|
| 78 | fibril_t fibril;
|
---|
| 79 | uintptr_t addr, fibril_addr;
|
---|
| 80 | uintptr_t pc, fp;
|
---|
| 81 | int rc;
|
---|
| 82 |
|
---|
| 83 | rc = symtab_name_to_addr(symtab, "fibril_list", &fibril_list_addr);
|
---|
| 84 | if (rc != EOK)
|
---|
| 85 | return EIO;
|
---|
| 86 |
|
---|
| 87 | addr = fibril_list_addr;
|
---|
| 88 | while (true) {
|
---|
| 89 | rc = read_link(sess, addr, &link);
|
---|
| 90 | if (rc != EOK)
|
---|
| 91 | return EIO;
|
---|
| 92 |
|
---|
| 93 | addr = (uintptr_t) link.next;
|
---|
| 94 | if (addr == fibril_list_addr)
|
---|
| 95 | break;
|
---|
| 96 |
|
---|
| 97 | fibril_addr = (uintptr_t) list_get_instance((void *)addr,
|
---|
| 98 | fibril_t, all_link);
|
---|
| 99 | printf("Fibril %p:\n", (void *) fibril_addr);
|
---|
| 100 | rc = read_fibril(sess, fibril_addr, &fibril);
|
---|
| 101 | if (rc != EOK)
|
---|
| 102 | return EIO;
|
---|
| 103 |
|
---|
| 104 | pc = fibril.ctx.pc;
|
---|
| 105 | fp = context_get_fp(&fibril.ctx);
|
---|
| 106 | if (0) stacktrace_print_generic(&fibrildump_st_ops, sess,
|
---|
| 107 | fp, pc);
|
---|
| 108 | td_stacktrace(fp, pc);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | return EOK;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /** @}
|
---|
| 115 | */
|
---|