1/*- 2 * Copyright (c) 2006 Marcel Moolenaar 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 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2006 Marcel Moolenaar 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 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
|
33#include <err.h> 34#include <kvm.h> 35#include <string.h> 36 37#include <defs.h> 38#include <target.h> 39#include <gdbthread.h> 40#include <inferior.h> 41#include <regcache.h> 42#include <frame-unwind.h> 43#include <ppc-tdep.h> 44 45#include "kgdb.h" 46 47void 48kgdb_trgt_fetch_registers(int regno __unused) 49{ 50 struct kthr *kt; 51 struct pcb pcb; 52 struct gdbarch_tdep *tdep; 53 int i; 54 55 tdep = gdbarch_tdep (current_gdbarch); 56 57 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 58 if (kt == NULL) 59 return; 60 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { 61 warnx("kvm_read: %s", kvm_geterr(kvm)); 62 memset(&pcb, 0, sizeof(pcb)); 63 } 64 65 /* 66 * r14-r31 are saved in the pcb 67 */ 68 for (i = 14; i <= 31; i++) { 69 supply_register(tdep->ppc_gp0_regnum + i, 70 (char *)&pcb.pcb_context[i]); 71 } 72 73 /* r1 is saved in the sp field */ 74 supply_register(tdep->ppc_gp0_regnum + 1, (char *)&pcb.pcb_sp); 75 76 supply_register(tdep->ppc_lr_regnum, (char *)&pcb.pcb_lr); 77 supply_register(tdep->ppc_cr_regnum, (char *)&pcb.pcb_cr); 78} 79 80void 81kgdb_trgt_store_registers(int regno __unused) 82{ 83 fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); 84} 85 86void 87kgdb_trgt_new_objfile(struct objfile *objfile) 88{ 89} 90 91struct kgdb_frame_cache { 92 CORE_ADDR pc; 93 CORE_ADDR sp; 94}; 95 96static struct kgdb_frame_cache * 97kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) 98{ 99 char buf[MAX_REGISTER_SIZE]; 100 struct kgdb_frame_cache *cache; 101 102 cache = *this_cache; 103 if (cache == NULL) { 104 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); 105 *this_cache = cache; 106 cache->pc = frame_func_unwind(next_frame); 107 frame_unwind_register(next_frame, SP_REGNUM, buf); 108 cache->sp = extract_unsigned_integer(buf, 109 register_size(current_gdbarch, SP_REGNUM)); 110 } 111 return (cache); 112} 113 114static void 115kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, 116 struct frame_id *this_id) 117{ 118 struct kgdb_frame_cache *cache; 119 120 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 121 *this_id = frame_id_build(cache->sp, cache->pc); 122} 123 124static void 125kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, 126 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 127 CORE_ADDR *addrp, int *realnump, void *valuep) 128{ 129 char dummy_valuep[MAX_REGISTER_SIZE]; 130 struct gdbarch_tdep *tdep; 131 struct kgdb_frame_cache *cache; 132 int ofs, regsz; 133 134 tdep = gdbarch_tdep(current_gdbarch); 135 regsz = register_size(current_gdbarch, regnum); 136 137 if (valuep == NULL) 138 valuep = dummy_valuep; 139 memset(valuep, 0, regsz); 140 *optimizedp = 0; 141 *addrp = 0; 142 *lvalp = not_lval; 143 *realnump = -1; 144 145 if (regnum >= tdep->ppc_gp0_regnum && 146 regnum <= tdep->ppc_gplast_regnum) 147 ofs = offsetof(struct trapframe, 148 fixreg[regnum - tdep->ppc_gp0_regnum]); 149 else if (regnum == tdep->ppc_lr_regnum) 150 ofs = offsetof(struct trapframe, lr); 151 else if (regnum == tdep->ppc_cr_regnum) 152 ofs = offsetof(struct trapframe, cr); 153 else if (regnum == tdep->ppc_xer_regnum) 154 ofs = offsetof(struct trapframe, xer); 155 else if (regnum == tdep->ppc_ctr_regnum) 156 ofs = offsetof(struct trapframe, ctr); 157 else if (regnum == PC_REGNUM) 158 ofs = offsetof(struct trapframe, srr0); 159 else 160 return; 161 162 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 163 *addrp = cache->sp + 8 + ofs; 164 *lvalp = lval_memory; 165 target_read_memory(*addrp, valuep, regsz); 166} 167 168static const struct frame_unwind kgdb_trgt_trapframe_unwind = { 169 UNKNOWN_FRAME, 170 &kgdb_trgt_trapframe_this_id, 171 &kgdb_trgt_trapframe_prev_register 172}; 173 174const struct frame_unwind * 175kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) 176{ 177 char *pname; 178 CORE_ADDR pc; 179 180 pc = frame_pc_unwind(next_frame); 181 pname = NULL; 182 find_pc_partial_function(pc, &pname, NULL, NULL); 183 if (pname == NULL) 184 return (NULL); 185 if (strcmp(pname, "asttrapexit") == 0 || 186 strcmp(pname, "trapexit") == 0) 187 return (&kgdb_trgt_trapframe_unwind); 188 /* printf("%s: %llx =%s\n", __func__, pc, pname); */ 189 return (NULL); 190}
| 38#include <err.h> 39#include <kvm.h> 40#include <string.h> 41 42#include <defs.h> 43#include <target.h> 44#include <gdbthread.h> 45#include <inferior.h> 46#include <regcache.h> 47#include <frame-unwind.h> 48#include <ppc-tdep.h> 49 50#include "kgdb.h" 51 52void 53kgdb_trgt_fetch_registers(int regno __unused) 54{ 55 struct kthr *kt; 56 struct pcb pcb; 57 struct gdbarch_tdep *tdep; 58 int i; 59 60 tdep = gdbarch_tdep (current_gdbarch); 61 62 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 63 if (kt == NULL) 64 return; 65 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { 66 warnx("kvm_read: %s", kvm_geterr(kvm)); 67 memset(&pcb, 0, sizeof(pcb)); 68 } 69 70 /* 71 * r14-r31 are saved in the pcb 72 */ 73 for (i = 14; i <= 31; i++) { 74 supply_register(tdep->ppc_gp0_regnum + i, 75 (char *)&pcb.pcb_context[i]); 76 } 77 78 /* r1 is saved in the sp field */ 79 supply_register(tdep->ppc_gp0_regnum + 1, (char *)&pcb.pcb_sp); 80 81 supply_register(tdep->ppc_lr_regnum, (char *)&pcb.pcb_lr); 82 supply_register(tdep->ppc_cr_regnum, (char *)&pcb.pcb_cr); 83} 84 85void 86kgdb_trgt_store_registers(int regno __unused) 87{ 88 fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); 89} 90 91void 92kgdb_trgt_new_objfile(struct objfile *objfile) 93{ 94} 95 96struct kgdb_frame_cache { 97 CORE_ADDR pc; 98 CORE_ADDR sp; 99}; 100 101static struct kgdb_frame_cache * 102kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) 103{ 104 char buf[MAX_REGISTER_SIZE]; 105 struct kgdb_frame_cache *cache; 106 107 cache = *this_cache; 108 if (cache == NULL) { 109 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); 110 *this_cache = cache; 111 cache->pc = frame_func_unwind(next_frame); 112 frame_unwind_register(next_frame, SP_REGNUM, buf); 113 cache->sp = extract_unsigned_integer(buf, 114 register_size(current_gdbarch, SP_REGNUM)); 115 } 116 return (cache); 117} 118 119static void 120kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, 121 struct frame_id *this_id) 122{ 123 struct kgdb_frame_cache *cache; 124 125 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 126 *this_id = frame_id_build(cache->sp, cache->pc); 127} 128 129static void 130kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, 131 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 132 CORE_ADDR *addrp, int *realnump, void *valuep) 133{ 134 char dummy_valuep[MAX_REGISTER_SIZE]; 135 struct gdbarch_tdep *tdep; 136 struct kgdb_frame_cache *cache; 137 int ofs, regsz; 138 139 tdep = gdbarch_tdep(current_gdbarch); 140 regsz = register_size(current_gdbarch, regnum); 141 142 if (valuep == NULL) 143 valuep = dummy_valuep; 144 memset(valuep, 0, regsz); 145 *optimizedp = 0; 146 *addrp = 0; 147 *lvalp = not_lval; 148 *realnump = -1; 149 150 if (regnum >= tdep->ppc_gp0_regnum && 151 regnum <= tdep->ppc_gplast_regnum) 152 ofs = offsetof(struct trapframe, 153 fixreg[regnum - tdep->ppc_gp0_regnum]); 154 else if (regnum == tdep->ppc_lr_regnum) 155 ofs = offsetof(struct trapframe, lr); 156 else if (regnum == tdep->ppc_cr_regnum) 157 ofs = offsetof(struct trapframe, cr); 158 else if (regnum == tdep->ppc_xer_regnum) 159 ofs = offsetof(struct trapframe, xer); 160 else if (regnum == tdep->ppc_ctr_regnum) 161 ofs = offsetof(struct trapframe, ctr); 162 else if (regnum == PC_REGNUM) 163 ofs = offsetof(struct trapframe, srr0); 164 else 165 return; 166 167 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 168 *addrp = cache->sp + 8 + ofs; 169 *lvalp = lval_memory; 170 target_read_memory(*addrp, valuep, regsz); 171} 172 173static const struct frame_unwind kgdb_trgt_trapframe_unwind = { 174 UNKNOWN_FRAME, 175 &kgdb_trgt_trapframe_this_id, 176 &kgdb_trgt_trapframe_prev_register 177}; 178 179const struct frame_unwind * 180kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) 181{ 182 char *pname; 183 CORE_ADDR pc; 184 185 pc = frame_pc_unwind(next_frame); 186 pname = NULL; 187 find_pc_partial_function(pc, &pname, NULL, NULL); 188 if (pname == NULL) 189 return (NULL); 190 if (strcmp(pname, "asttrapexit") == 0 || 191 strcmp(pname, "trapexit") == 0) 192 return (&kgdb_trgt_trapframe_unwind); 193 /* printf("%s: %llx =%s\n", __func__, pc, pname); */ 194 return (NULL); 195}
|