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>
|
29 30#include <sys/param.h> 31#include <sys/proc.h> 32#include <machine/pcb.h> 33#include <machine/frame.h> 34#include <machine/segments.h> 35#include <machine/tss.h> 36#include <err.h> 37#include <kvm.h> 38#include <string.h> 39 40#include <defs.h> 41#include <target.h> 42#include <gdbthread.h> 43#include <inferior.h> 44#include <regcache.h> 45#include <frame-unwind.h> 46#include <i386-tdep.h> 47 48#include "kgdb.h" 49 50static int ofs_fix; 51 52void 53kgdb_trgt_fetch_registers(int regno __unused) 54{ 55 struct kthr *kt; 56 struct pcb pcb; 57 58 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 59 if (kt == NULL) 60 return; 61 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { 62 warnx("kvm_read: %s", kvm_geterr(kvm)); 63 memset(&pcb, 0, sizeof(pcb)); 64 } 65 supply_register(I386_EBX_REGNUM, (char *)&pcb.pcb_ebx); 66 supply_register(I386_ESP_REGNUM, (char *)&pcb.pcb_esp); 67 supply_register(I386_EBP_REGNUM, (char *)&pcb.pcb_ebp); 68 supply_register(I386_ESI_REGNUM, (char *)&pcb.pcb_esi); 69 supply_register(I386_EDI_REGNUM, (char *)&pcb.pcb_edi); 70 supply_register(I386_EIP_REGNUM, (char *)&pcb.pcb_eip); 71} 72 73void 74kgdb_trgt_store_registers(int regno __unused) 75{ 76 fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); 77} 78 79void 80kgdb_trgt_new_objfile(struct objfile *objfile) 81{ 82 83 /* 84 * In revision 1.117 of i386/i386/exception.S trap handlers 85 * were changed to pass trapframes by reference rather than 86 * by value. Detect this by seeing if the first instruction 87 * at the 'calltrap' label is a "push %esp" which has the 88 * opcode 0x54. 89 */ 90 if (kgdb_parse("((char *)calltrap)[0]") == 0x54) 91 ofs_fix = 4; 92 else 93 ofs_fix = 0; 94} 95 96struct kgdb_tss_cache { 97 CORE_ADDR pc; 98 CORE_ADDR sp; 99 CORE_ADDR tss; 100}; 101 102static int kgdb_trgt_tss_offset[15] = { 103 offsetof(struct i386tss, tss_eax), 104 offsetof(struct i386tss, tss_ecx), 105 offsetof(struct i386tss, tss_edx), 106 offsetof(struct i386tss, tss_ebx), 107 offsetof(struct i386tss, tss_esp), 108 offsetof(struct i386tss, tss_ebp), 109 offsetof(struct i386tss, tss_esi), 110 offsetof(struct i386tss, tss_edi), 111 offsetof(struct i386tss, tss_eip), 112 offsetof(struct i386tss, tss_eflags), 113 offsetof(struct i386tss, tss_cs), 114 offsetof(struct i386tss, tss_ss), 115 offsetof(struct i386tss, tss_ds), 116 offsetof(struct i386tss, tss_es), 117 offsetof(struct i386tss, tss_fs) 118}; 119 120/* 121 * If the current thread is executing on a CPU, fetch the common_tss 122 * for that CPU. 123 * 124 * This is painful because 'struct pcpu' is variant sized, so we can't 125 * use it. Instead, we lookup the GDT selector for this CPU and 126 * extract the base of the TSS from there. 127 */ 128static CORE_ADDR 129kgdb_trgt_fetch_tss(void) 130{ 131 struct kthr *kt; 132 struct segment_descriptor sd; 133 uintptr_t addr, cpu0prvpage, tss; 134 135 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 136 if (kt == NULL || kt->cpu == NOCPU) 137 return (0); 138
| 29 30#include <sys/param.h> 31#include <sys/proc.h> 32#include <machine/pcb.h> 33#include <machine/frame.h> 34#include <machine/segments.h> 35#include <machine/tss.h> 36#include <err.h> 37#include <kvm.h> 38#include <string.h> 39 40#include <defs.h> 41#include <target.h> 42#include <gdbthread.h> 43#include <inferior.h> 44#include <regcache.h> 45#include <frame-unwind.h> 46#include <i386-tdep.h> 47 48#include "kgdb.h" 49 50static int ofs_fix; 51 52void 53kgdb_trgt_fetch_registers(int regno __unused) 54{ 55 struct kthr *kt; 56 struct pcb pcb; 57 58 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 59 if (kt == NULL) 60 return; 61 if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { 62 warnx("kvm_read: %s", kvm_geterr(kvm)); 63 memset(&pcb, 0, sizeof(pcb)); 64 } 65 supply_register(I386_EBX_REGNUM, (char *)&pcb.pcb_ebx); 66 supply_register(I386_ESP_REGNUM, (char *)&pcb.pcb_esp); 67 supply_register(I386_EBP_REGNUM, (char *)&pcb.pcb_ebp); 68 supply_register(I386_ESI_REGNUM, (char *)&pcb.pcb_esi); 69 supply_register(I386_EDI_REGNUM, (char *)&pcb.pcb_edi); 70 supply_register(I386_EIP_REGNUM, (char *)&pcb.pcb_eip); 71} 72 73void 74kgdb_trgt_store_registers(int regno __unused) 75{ 76 fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); 77} 78 79void 80kgdb_trgt_new_objfile(struct objfile *objfile) 81{ 82 83 /* 84 * In revision 1.117 of i386/i386/exception.S trap handlers 85 * were changed to pass trapframes by reference rather than 86 * by value. Detect this by seeing if the first instruction 87 * at the 'calltrap' label is a "push %esp" which has the 88 * opcode 0x54. 89 */ 90 if (kgdb_parse("((char *)calltrap)[0]") == 0x54) 91 ofs_fix = 4; 92 else 93 ofs_fix = 0; 94} 95 96struct kgdb_tss_cache { 97 CORE_ADDR pc; 98 CORE_ADDR sp; 99 CORE_ADDR tss; 100}; 101 102static int kgdb_trgt_tss_offset[15] = { 103 offsetof(struct i386tss, tss_eax), 104 offsetof(struct i386tss, tss_ecx), 105 offsetof(struct i386tss, tss_edx), 106 offsetof(struct i386tss, tss_ebx), 107 offsetof(struct i386tss, tss_esp), 108 offsetof(struct i386tss, tss_ebp), 109 offsetof(struct i386tss, tss_esi), 110 offsetof(struct i386tss, tss_edi), 111 offsetof(struct i386tss, tss_eip), 112 offsetof(struct i386tss, tss_eflags), 113 offsetof(struct i386tss, tss_cs), 114 offsetof(struct i386tss, tss_ss), 115 offsetof(struct i386tss, tss_ds), 116 offsetof(struct i386tss, tss_es), 117 offsetof(struct i386tss, tss_fs) 118}; 119 120/* 121 * If the current thread is executing on a CPU, fetch the common_tss 122 * for that CPU. 123 * 124 * This is painful because 'struct pcpu' is variant sized, so we can't 125 * use it. Instead, we lookup the GDT selector for this CPU and 126 * extract the base of the TSS from there. 127 */ 128static CORE_ADDR 129kgdb_trgt_fetch_tss(void) 130{ 131 struct kthr *kt; 132 struct segment_descriptor sd; 133 uintptr_t addr, cpu0prvpage, tss; 134 135 kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); 136 if (kt == NULL || kt->cpu == NOCPU) 137 return (0); 138
|
167 if (kvm_read(kvm, addr, &cpu0prvpage, sizeof(cpu0prvpage)) != 168 sizeof(cpu0prvpage)) { 169 warnx("kvm_read: %s", kvm_geterr(kvm)); 170 return (0); 171 } 172 tss = cpu0prvpage + (tss & PAGE_MASK); 173 } 174 return ((CORE_ADDR)tss); 175} 176 177static struct kgdb_tss_cache * 178kgdb_trgt_tss_cache(struct frame_info *next_frame, void **this_cache) 179{ 180 char buf[MAX_REGISTER_SIZE]; 181 struct kgdb_tss_cache *cache; 182 183 cache = *this_cache; 184 if (cache == NULL) { 185 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_tss_cache); 186 *this_cache = cache; 187 cache->pc = frame_func_unwind(next_frame); 188 frame_unwind_register(next_frame, SP_REGNUM, buf); 189 cache->sp = extract_unsigned_integer(buf, 190 register_size(current_gdbarch, SP_REGNUM)); 191 cache->tss = kgdb_trgt_fetch_tss(); 192 } 193 return (cache); 194} 195 196static void 197kgdb_trgt_dblfault_this_id(struct frame_info *next_frame, void **this_cache, 198 struct frame_id *this_id) 199{ 200 struct kgdb_tss_cache *cache; 201 202 cache = kgdb_trgt_tss_cache(next_frame, this_cache); 203 *this_id = frame_id_build(cache->sp, cache->pc); 204} 205 206static void 207kgdb_trgt_dblfault_prev_register(struct frame_info *next_frame, 208 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 209 CORE_ADDR *addrp, int *realnump, void *valuep) 210{ 211 char dummy_valuep[MAX_REGISTER_SIZE]; 212 struct kgdb_tss_cache *cache; 213 int ofs, regsz; 214 215 regsz = register_size(current_gdbarch, regnum); 216 217 if (valuep == NULL) 218 valuep = dummy_valuep; 219 memset(valuep, 0, regsz); 220 *optimizedp = 0; 221 *addrp = 0; 222 *lvalp = not_lval; 223 *realnump = -1; 224 225 ofs = (regnum >= I386_EAX_REGNUM && regnum <= I386_FS_REGNUM) 226 ? kgdb_trgt_tss_offset[regnum] : -1; 227 if (ofs == -1) 228 return; 229 230 cache = kgdb_trgt_tss_cache(next_frame, this_cache); 231 if (cache->tss == 0) 232 return; 233 *addrp = cache->tss + ofs; 234 *lvalp = lval_memory; 235 target_read_memory(*addrp, valuep, regsz); 236} 237 238static const struct frame_unwind kgdb_trgt_dblfault_unwind = { 239 UNKNOWN_FRAME, 240 &kgdb_trgt_dblfault_this_id, 241 &kgdb_trgt_dblfault_prev_register 242}; 243 244struct kgdb_frame_cache { 245 int frame_type; 246 CORE_ADDR pc; 247 CORE_ADDR sp; 248}; 249#define FT_NORMAL 1 250#define FT_INTRFRAME 2 251#define FT_INTRTRAPFRAME 3 252#define FT_TIMERFRAME 4 253 254static int kgdb_trgt_frame_offset[15] = { 255 offsetof(struct trapframe, tf_eax), 256 offsetof(struct trapframe, tf_ecx), 257 offsetof(struct trapframe, tf_edx), 258 offsetof(struct trapframe, tf_ebx), 259 offsetof(struct trapframe, tf_esp), 260 offsetof(struct trapframe, tf_ebp), 261 offsetof(struct trapframe, tf_esi), 262 offsetof(struct trapframe, tf_edi), 263 offsetof(struct trapframe, tf_eip), 264 offsetof(struct trapframe, tf_eflags), 265 offsetof(struct trapframe, tf_cs), 266 offsetof(struct trapframe, tf_ss), 267 offsetof(struct trapframe, tf_ds), 268 offsetof(struct trapframe, tf_es), 269 offsetof(struct trapframe, tf_fs) 270}; 271 272static struct kgdb_frame_cache * 273kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) 274{ 275 char buf[MAX_REGISTER_SIZE]; 276 struct kgdb_frame_cache *cache; 277 char *pname; 278 279 cache = *this_cache; 280 if (cache == NULL) { 281 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); 282 *this_cache = cache; 283 cache->pc = frame_func_unwind(next_frame); 284 find_pc_partial_function(cache->pc, &pname, NULL, NULL); 285 if (pname[0] != 'X') 286 cache->frame_type = FT_NORMAL; 287 else if (strcmp(pname, "Xtimerint") == 0) 288 cache->frame_type = FT_TIMERFRAME; 289 else if (strcmp(pname, "Xcpustop") == 0 || 290 strcmp(pname, "Xrendezvous") == 0 || 291 strcmp(pname, "Xipi_intr_bitmap_handler") == 0 || 292 strcmp(pname, "Xlazypmap") == 0) 293 cache->frame_type = FT_INTRTRAPFRAME; 294 else 295 cache->frame_type = FT_INTRFRAME; 296 frame_unwind_register(next_frame, SP_REGNUM, buf); 297 cache->sp = extract_unsigned_integer(buf, 298 register_size(current_gdbarch, SP_REGNUM)); 299 } 300 return (cache); 301} 302 303static void 304kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, 305 struct frame_id *this_id) 306{ 307 struct kgdb_frame_cache *cache; 308 309 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 310 *this_id = frame_id_build(cache->sp, cache->pc); 311} 312 313static void 314kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, 315 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 316 CORE_ADDR *addrp, int *realnump, void *valuep) 317{ 318 char dummy_valuep[MAX_REGISTER_SIZE]; 319 struct kgdb_frame_cache *cache; 320 int ofs, regsz; 321 322 regsz = register_size(current_gdbarch, regnum); 323 324 if (valuep == NULL) 325 valuep = dummy_valuep; 326 memset(valuep, 0, regsz); 327 *optimizedp = 0; 328 *addrp = 0; 329 *lvalp = not_lval; 330 *realnump = -1; 331 332 ofs = (regnum >= I386_EAX_REGNUM && regnum <= I386_FS_REGNUM) 333 ? kgdb_trgt_frame_offset[regnum] + ofs_fix : -1; 334 if (ofs == -1) 335 return; 336 337 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 338 switch (cache->frame_type) { 339 case FT_NORMAL: 340 break; 341 case FT_INTRFRAME: 342 ofs += 4; 343 break; 344 case FT_TIMERFRAME: 345 break; 346 case FT_INTRTRAPFRAME: 347 ofs -= ofs_fix; 348 break; 349 default: 350 fprintf_unfiltered(gdb_stderr, "Correct FT_XXX frame offsets " 351 "for %d\n", cache->frame_type); 352 break; 353 } 354 *addrp = cache->sp + ofs; 355 *lvalp = lval_memory; 356 target_read_memory(*addrp, valuep, regsz); 357} 358 359static const struct frame_unwind kgdb_trgt_trapframe_unwind = { 360 UNKNOWN_FRAME, 361 &kgdb_trgt_trapframe_this_id, 362 &kgdb_trgt_trapframe_prev_register 363}; 364 365const struct frame_unwind * 366kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) 367{ 368 char *pname; 369 CORE_ADDR pc; 370 371 pc = frame_pc_unwind(next_frame); 372 pname = NULL; 373 find_pc_partial_function(pc, &pname, NULL, NULL); 374 if (pname == NULL) 375 return (NULL); 376 if (strcmp(pname, "dblfault_handler") == 0) 377 return (&kgdb_trgt_dblfault_unwind); 378 if (strcmp(pname, "calltrap") == 0 || 379 (pname[0] == 'X' && pname[1] != '_')) 380 return (&kgdb_trgt_trapframe_unwind); 381 /* printf("%s: %llx =%s\n", __func__, pc, pname); */ 382 return (NULL); 383}
| 165 if (kvm_read(kvm, addr, &cpu0prvpage, sizeof(cpu0prvpage)) != 166 sizeof(cpu0prvpage)) { 167 warnx("kvm_read: %s", kvm_geterr(kvm)); 168 return (0); 169 } 170 tss = cpu0prvpage + (tss & PAGE_MASK); 171 } 172 return ((CORE_ADDR)tss); 173} 174 175static struct kgdb_tss_cache * 176kgdb_trgt_tss_cache(struct frame_info *next_frame, void **this_cache) 177{ 178 char buf[MAX_REGISTER_SIZE]; 179 struct kgdb_tss_cache *cache; 180 181 cache = *this_cache; 182 if (cache == NULL) { 183 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_tss_cache); 184 *this_cache = cache; 185 cache->pc = frame_func_unwind(next_frame); 186 frame_unwind_register(next_frame, SP_REGNUM, buf); 187 cache->sp = extract_unsigned_integer(buf, 188 register_size(current_gdbarch, SP_REGNUM)); 189 cache->tss = kgdb_trgt_fetch_tss(); 190 } 191 return (cache); 192} 193 194static void 195kgdb_trgt_dblfault_this_id(struct frame_info *next_frame, void **this_cache, 196 struct frame_id *this_id) 197{ 198 struct kgdb_tss_cache *cache; 199 200 cache = kgdb_trgt_tss_cache(next_frame, this_cache); 201 *this_id = frame_id_build(cache->sp, cache->pc); 202} 203 204static void 205kgdb_trgt_dblfault_prev_register(struct frame_info *next_frame, 206 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 207 CORE_ADDR *addrp, int *realnump, void *valuep) 208{ 209 char dummy_valuep[MAX_REGISTER_SIZE]; 210 struct kgdb_tss_cache *cache; 211 int ofs, regsz; 212 213 regsz = register_size(current_gdbarch, regnum); 214 215 if (valuep == NULL) 216 valuep = dummy_valuep; 217 memset(valuep, 0, regsz); 218 *optimizedp = 0; 219 *addrp = 0; 220 *lvalp = not_lval; 221 *realnump = -1; 222 223 ofs = (regnum >= I386_EAX_REGNUM && regnum <= I386_FS_REGNUM) 224 ? kgdb_trgt_tss_offset[regnum] : -1; 225 if (ofs == -1) 226 return; 227 228 cache = kgdb_trgt_tss_cache(next_frame, this_cache); 229 if (cache->tss == 0) 230 return; 231 *addrp = cache->tss + ofs; 232 *lvalp = lval_memory; 233 target_read_memory(*addrp, valuep, regsz); 234} 235 236static const struct frame_unwind kgdb_trgt_dblfault_unwind = { 237 UNKNOWN_FRAME, 238 &kgdb_trgt_dblfault_this_id, 239 &kgdb_trgt_dblfault_prev_register 240}; 241 242struct kgdb_frame_cache { 243 int frame_type; 244 CORE_ADDR pc; 245 CORE_ADDR sp; 246}; 247#define FT_NORMAL 1 248#define FT_INTRFRAME 2 249#define FT_INTRTRAPFRAME 3 250#define FT_TIMERFRAME 4 251 252static int kgdb_trgt_frame_offset[15] = { 253 offsetof(struct trapframe, tf_eax), 254 offsetof(struct trapframe, tf_ecx), 255 offsetof(struct trapframe, tf_edx), 256 offsetof(struct trapframe, tf_ebx), 257 offsetof(struct trapframe, tf_esp), 258 offsetof(struct trapframe, tf_ebp), 259 offsetof(struct trapframe, tf_esi), 260 offsetof(struct trapframe, tf_edi), 261 offsetof(struct trapframe, tf_eip), 262 offsetof(struct trapframe, tf_eflags), 263 offsetof(struct trapframe, tf_cs), 264 offsetof(struct trapframe, tf_ss), 265 offsetof(struct trapframe, tf_ds), 266 offsetof(struct trapframe, tf_es), 267 offsetof(struct trapframe, tf_fs) 268}; 269 270static struct kgdb_frame_cache * 271kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) 272{ 273 char buf[MAX_REGISTER_SIZE]; 274 struct kgdb_frame_cache *cache; 275 char *pname; 276 277 cache = *this_cache; 278 if (cache == NULL) { 279 cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); 280 *this_cache = cache; 281 cache->pc = frame_func_unwind(next_frame); 282 find_pc_partial_function(cache->pc, &pname, NULL, NULL); 283 if (pname[0] != 'X') 284 cache->frame_type = FT_NORMAL; 285 else if (strcmp(pname, "Xtimerint") == 0) 286 cache->frame_type = FT_TIMERFRAME; 287 else if (strcmp(pname, "Xcpustop") == 0 || 288 strcmp(pname, "Xrendezvous") == 0 || 289 strcmp(pname, "Xipi_intr_bitmap_handler") == 0 || 290 strcmp(pname, "Xlazypmap") == 0) 291 cache->frame_type = FT_INTRTRAPFRAME; 292 else 293 cache->frame_type = FT_INTRFRAME; 294 frame_unwind_register(next_frame, SP_REGNUM, buf); 295 cache->sp = extract_unsigned_integer(buf, 296 register_size(current_gdbarch, SP_REGNUM)); 297 } 298 return (cache); 299} 300 301static void 302kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, 303 struct frame_id *this_id) 304{ 305 struct kgdb_frame_cache *cache; 306 307 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 308 *this_id = frame_id_build(cache->sp, cache->pc); 309} 310 311static void 312kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, 313 void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, 314 CORE_ADDR *addrp, int *realnump, void *valuep) 315{ 316 char dummy_valuep[MAX_REGISTER_SIZE]; 317 struct kgdb_frame_cache *cache; 318 int ofs, regsz; 319 320 regsz = register_size(current_gdbarch, regnum); 321 322 if (valuep == NULL) 323 valuep = dummy_valuep; 324 memset(valuep, 0, regsz); 325 *optimizedp = 0; 326 *addrp = 0; 327 *lvalp = not_lval; 328 *realnump = -1; 329 330 ofs = (regnum >= I386_EAX_REGNUM && regnum <= I386_FS_REGNUM) 331 ? kgdb_trgt_frame_offset[regnum] + ofs_fix : -1; 332 if (ofs == -1) 333 return; 334 335 cache = kgdb_trgt_frame_cache(next_frame, this_cache); 336 switch (cache->frame_type) { 337 case FT_NORMAL: 338 break; 339 case FT_INTRFRAME: 340 ofs += 4; 341 break; 342 case FT_TIMERFRAME: 343 break; 344 case FT_INTRTRAPFRAME: 345 ofs -= ofs_fix; 346 break; 347 default: 348 fprintf_unfiltered(gdb_stderr, "Correct FT_XXX frame offsets " 349 "for %d\n", cache->frame_type); 350 break; 351 } 352 *addrp = cache->sp + ofs; 353 *lvalp = lval_memory; 354 target_read_memory(*addrp, valuep, regsz); 355} 356 357static const struct frame_unwind kgdb_trgt_trapframe_unwind = { 358 UNKNOWN_FRAME, 359 &kgdb_trgt_trapframe_this_id, 360 &kgdb_trgt_trapframe_prev_register 361}; 362 363const struct frame_unwind * 364kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) 365{ 366 char *pname; 367 CORE_ADDR pc; 368 369 pc = frame_pc_unwind(next_frame); 370 pname = NULL; 371 find_pc_partial_function(pc, &pname, NULL, NULL); 372 if (pname == NULL) 373 return (NULL); 374 if (strcmp(pname, "dblfault_handler") == 0) 375 return (&kgdb_trgt_dblfault_unwind); 376 if (strcmp(pname, "calltrap") == 0 || 377 (pname[0] == 'X' && pname[1] != '_')) 378 return (&kgdb_trgt_trapframe_unwind); 379 /* printf("%s: %llx =%s\n", __func__, pc, pname); */ 380 return (NULL); 381}
|