1/* 2 * Copyright (c) 2004 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 AUTHORS ``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 AUTHORS 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) 2004 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 AUTHORS ``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 AUTHORS 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>
|
47void 48kgdb_trgt_fetch_registers(int regno __unused) 49{ 50 struct kthr *kt; 51 struct pcb pcb; 52 53 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 54 if (kt == NULL) 55 return; 56 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { 57 warnx("kvm_read: %s", kvm_geterr(kvm)); 58 memset(&pcb, 0, sizeof(pcb)); 59 } 60 61 supply_register(AMD64_RBX_REGNUM, (char *)&pcb.pcb_rbx); 62 supply_register(AMD64_RBP_REGNUM, (char *)&pcb.pcb_rbp); 63 supply_register(AMD64_RSP_REGNUM, (char *)&pcb.pcb_rsp); 64 supply_register(AMD64_R8_REGNUM + 4, (char *)&pcb.pcb_r12); 65 supply_register(AMD64_R8_REGNUM + 5, (char *)&pcb.pcb_r13); 66 supply_register(AMD64_R8_REGNUM + 6, (char *)&pcb.pcb_r14); 67 supply_register(AMD64_R15_REGNUM, (char *)&pcb.pcb_r15); 68 supply_register(AMD64_RIP_REGNUM, (char *)&pcb.pcb_rip); 69 amd64_supply_fxsave(current_regcache, -1, (struct fpusave *)(&pcb + 1)); 70} 71 72void 73kgdb_trgt_store_registers(int regno __unused) 74{ 75 fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); 76} 77 78void 79kgdb_trgt_new_objfile(struct objfile *objfile) 80{ 81} 82 83struct kgdb_frame_cache { 84 CORE_ADDR pc; 85 CORE_ADDR sp; 86}; 87 88static int kgdb_trgt_frame_offset[20] = { 89 offsetof(struct trapframe, tf_rax), 90 offsetof(struct trapframe, tf_rbx), 91 offsetof(struct trapframe, tf_rcx), 92 offsetof(struct trapframe, tf_rdx), 93 offsetof(struct trapframe, tf_rsi), 94 offsetof(struct trapframe, tf_rdi), 95 offsetof(struct trapframe, tf_rbp), 96 offsetof(struct trapframe, tf_rsp), 97 offsetof(struct trapframe, tf_r8), 98 offsetof(struct trapframe, tf_r9), 99 offsetof(struct trapframe, tf_r10), 100 offsetof(struct trapframe, tf_r11), 101 offsetof(struct trapframe, tf_r12), 102 offsetof(struct trapframe, tf_r13), 103 offsetof(struct trapframe, tf_r14), 104 offsetof(struct trapframe, tf_r15), 105 offsetof(struct trapframe, tf_rip), 106 offsetof(struct trapframe, tf_rflags), 107 offsetof(struct trapframe, tf_cs), 108 offsetof(struct trapframe, tf_ss) 109}; 110 111static struct kgdb_frame_cache * 112kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) 113{ 114 char buf[MAX_REGISTER_SIZE]; 115 struct kgdb_frame_cache *cache; 116 117 cache = *this_cache; 118 if (cache == NULL) { 119 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); 120 *this_cache = cache; 121 cache->pc = frame_func_unwind(next_frame); 122 frame_unwind_register(next_frame, SP_REGNUM, buf); 123 cache->sp = extract_unsigned_integer(buf, 124 register_size(current_gdbarch, SP_REGNUM)); 125 } 126 return (cache); 127} 128 129static void 130kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, 131 struct frame_id *this_id) 132{ 133 struct kgdb_frame_cache *cache; 134 135 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 136 *this_id = frame_id_build(cache->sp, cache->pc); 137} 138 139static void 140kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, 141 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 142 CORE_ADDR *addrp, int *realnump, void *valuep) 143{ 144 char dummy_valuep[MAX_REGISTER_SIZE]; 145 struct kgdb_frame_cache *cache; 146 int ofs, regsz; 147 148 regsz = register_size(current_gdbarch, regnum); 149 150 if (valuep == NULL) 151 valuep = dummy_valuep; 152 memset(valuep, 0, regsz); 153 *optimizedp = 0; 154 *addrp = 0; 155 *lvalp = not_lval; 156 *realnump = -1; 157 158 ofs = (regnum >= AMD64_RAX_REGNUM && regnum <= AMD64_EFLAGS_REGNUM + 2) 159 ? kgdb_trgt_frame_offset[regnum] : -1; 160 if (ofs == -1) 161 return; 162 163 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 164 *addrp = cache->sp + ofs; 165 *lvalp = lval_memory; 166 target_read_memory(*addrp, valuep, regsz); 167} 168 169static const struct frame_unwind kgdb_trgt_trapframe_unwind = { 170 UNKNOWN_FRAME, 171 &kgdb_trgt_trapframe_this_id, 172 &kgdb_trgt_trapframe_prev_register 173}; 174 175const struct frame_unwind * 176kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) 177{ 178 char *pname; 179 CORE_ADDR pc; 180 181 pc = frame_pc_unwind(next_frame); 182 pname = NULL; 183 find_pc_partial_function(pc, &pname, NULL, NULL); 184 if (pname == NULL) 185 return (NULL); 186 if (strcmp(pname, "calltrap") == 0 || 187 strcmp(pname, "nmi_calltrap") == 0 || 188 (pname[0] == 'X' && pname[1] != '_')) 189 return (&kgdb_trgt_trapframe_unwind); 190 /* printf("%s: %lx =%s\n", __func__, pc, pname); */ 191 return (NULL); 192}
| 53void 54kgdb_trgt_fetch_registers(int regno __unused) 55{ 56 struct kthr *kt; 57 struct pcb pcb; 58 59 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 60 if (kt == NULL) 61 return; 62 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { 63 warnx("kvm_read: %s", kvm_geterr(kvm)); 64 memset(&pcb, 0, sizeof(pcb)); 65 } 66 67 supply_register(AMD64_RBX_REGNUM, (char *)&pcb.pcb_rbx); 68 supply_register(AMD64_RBP_REGNUM, (char *)&pcb.pcb_rbp); 69 supply_register(AMD64_RSP_REGNUM, (char *)&pcb.pcb_rsp); 70 supply_register(AMD64_R8_REGNUM + 4, (char *)&pcb.pcb_r12); 71 supply_register(AMD64_R8_REGNUM + 5, (char *)&pcb.pcb_r13); 72 supply_register(AMD64_R8_REGNUM + 6, (char *)&pcb.pcb_r14); 73 supply_register(AMD64_R15_REGNUM, (char *)&pcb.pcb_r15); 74 supply_register(AMD64_RIP_REGNUM, (char *)&pcb.pcb_rip); 75 amd64_supply_fxsave(current_regcache, -1, (struct fpusave *)(&pcb + 1)); 76} 77 78void 79kgdb_trgt_store_registers(int regno __unused) 80{ 81 fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); 82} 83 84void 85kgdb_trgt_new_objfile(struct objfile *objfile) 86{ 87} 88 89struct kgdb_frame_cache { 90 CORE_ADDR pc; 91 CORE_ADDR sp; 92}; 93 94static int kgdb_trgt_frame_offset[20] = { 95 offsetof(struct trapframe, tf_rax), 96 offsetof(struct trapframe, tf_rbx), 97 offsetof(struct trapframe, tf_rcx), 98 offsetof(struct trapframe, tf_rdx), 99 offsetof(struct trapframe, tf_rsi), 100 offsetof(struct trapframe, tf_rdi), 101 offsetof(struct trapframe, tf_rbp), 102 offsetof(struct trapframe, tf_rsp), 103 offsetof(struct trapframe, tf_r8), 104 offsetof(struct trapframe, tf_r9), 105 offsetof(struct trapframe, tf_r10), 106 offsetof(struct trapframe, tf_r11), 107 offsetof(struct trapframe, tf_r12), 108 offsetof(struct trapframe, tf_r13), 109 offsetof(struct trapframe, tf_r14), 110 offsetof(struct trapframe, tf_r15), 111 offsetof(struct trapframe, tf_rip), 112 offsetof(struct trapframe, tf_rflags), 113 offsetof(struct trapframe, tf_cs), 114 offsetof(struct trapframe, tf_ss) 115}; 116 117static struct kgdb_frame_cache * 118kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) 119{ 120 char buf[MAX_REGISTER_SIZE]; 121 struct kgdb_frame_cache *cache; 122 123 cache = *this_cache; 124 if (cache == NULL) { 125 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); 126 *this_cache = cache; 127 cache->pc = frame_func_unwind(next_frame); 128 frame_unwind_register(next_frame, SP_REGNUM, buf); 129 cache->sp = extract_unsigned_integer(buf, 130 register_size(current_gdbarch, SP_REGNUM)); 131 } 132 return (cache); 133} 134 135static void 136kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, 137 struct frame_id *this_id) 138{ 139 struct kgdb_frame_cache *cache; 140 141 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 142 *this_id = frame_id_build(cache->sp, cache->pc); 143} 144 145static void 146kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, 147 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 148 CORE_ADDR *addrp, int *realnump, void *valuep) 149{ 150 char dummy_valuep[MAX_REGISTER_SIZE]; 151 struct kgdb_frame_cache *cache; 152 int ofs, regsz; 153 154 regsz = register_size(current_gdbarch, regnum); 155 156 if (valuep == NULL) 157 valuep = dummy_valuep; 158 memset(valuep, 0, regsz); 159 *optimizedp = 0; 160 *addrp = 0; 161 *lvalp = not_lval; 162 *realnump = -1; 163 164 ofs = (regnum >= AMD64_RAX_REGNUM && regnum <= AMD64_EFLAGS_REGNUM + 2) 165 ? kgdb_trgt_frame_offset[regnum] : -1; 166 if (ofs == -1) 167 return; 168 169 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 170 *addrp = cache->sp + ofs; 171 *lvalp = lval_memory; 172 target_read_memory(*addrp, valuep, regsz); 173} 174 175static const struct frame_unwind kgdb_trgt_trapframe_unwind = { 176 UNKNOWN_FRAME, 177 &kgdb_trgt_trapframe_this_id, 178 &kgdb_trgt_trapframe_prev_register 179}; 180 181const struct frame_unwind * 182kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) 183{ 184 char *pname; 185 CORE_ADDR pc; 186 187 pc = frame_pc_unwind(next_frame); 188 pname = NULL; 189 find_pc_partial_function(pc, &pname, NULL, NULL); 190 if (pname == NULL) 191 return (NULL); 192 if (strcmp(pname, "calltrap") == 0 || 193 strcmp(pname, "nmi_calltrap") == 0 || 194 (pname[0] == 'X' && pname[1] != '_')) 195 return (&kgdb_trgt_trapframe_unwind); 196 /* printf("%s: %lx =%s\n", __func__, pc, pname); */ 197 return (NULL); 198}
|