remote_gdb.cc (3536:89aa06409e4d) | remote_gdb.cc (3550:515e876568b4) |
---|---|
1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 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 are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 110 unchanged lines hidden (view full) --- 119#include <sys/signal.h> 120 121#include <string> 122#include <unistd.h> 123 124#include "arch/vtophys.hh" 125#include "arch/sparc/remote_gdb.hh" 126#include "base/intmath.hh" | 1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 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 are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 110 unchanged lines hidden (view full) --- 119#include <sys/signal.h> 120 121#include <string> 122#include <unistd.h> 123 124#include "arch/vtophys.hh" 125#include "arch/sparc/remote_gdb.hh" 126#include "base/intmath.hh" |
127#include "base/kgdb.h" | |
128#include "base/remote_gdb.hh" 129#include "base/socket.hh" 130#include "base/trace.hh" 131#include "config/full_system.hh" 132#include "cpu/thread_context.hh" 133#include "cpu/static_inst.hh" 134#include "mem/physical.hh" 135#include "mem/port.hh" 136#include "sim/system.hh" 137 138using namespace std; 139using namespace TheISA; 140 | 127#include "base/remote_gdb.hh" 128#include "base/socket.hh" 129#include "base/trace.hh" 130#include "config/full_system.hh" 131#include "cpu/thread_context.hh" 132#include "cpu/static_inst.hh" 133#include "mem/physical.hh" 134#include "mem/port.hh" 135#include "sim/system.hh" 136 137using namespace std; 138using namespace TheISA; 139 |
141RemoteGDB::Event::Event(RemoteGDB *g, int fd, int e) 142 : PollEvent(fd, e), gdb(g) 143{} 144 145void 146RemoteGDB::Event::process(int revent) 147{ 148 if (revent & POLLIN) 149 gdb->trap(ALPHA_KENTRY_IF); 150 else if (revent & POLLNVAL) 151 gdb->detach(); 152} 153 | |
154RemoteGDB::RemoteGDB(System *_system, ThreadContext *c) | 140RemoteGDB::RemoteGDB(System *_system, ThreadContext *c) |
155 : BaseRemoteGDB(_system, c, KGDB_NUMREGS), 156 event(NULL) | 141 : BaseRemoteGDB(_system, c, NumGDBRegs) |
157{} 158 | 142{} 143 |
159RemoteGDB::~RemoteGDB() 160{ 161 if (event) 162 delete event; 163} 164 | |
165/////////////////////////////////////////////////////////// 166// RemoteGDB::acc 167// 168// Determine if the mapping at va..(va+len) is valid. 169// 170bool 171RemoteGDB::acc(Addr va, size_t len) 172{ | 144/////////////////////////////////////////////////////////// 145// RemoteGDB::acc 146// 147// Determine if the mapping at va..(va+len) is valid. 148// 149bool 150RemoteGDB::acc(Addr va, size_t len) 151{ |
152#if 0 |
|
173 Addr last_va; 174 175 va = TheISA::TruncPage(va); 176 last_va = TheISA::RoundPage(va + len); 177 178 do { 179 if (TheISA::IsK0Seg(va)) { 180 if (va < (TheISA::K0SegBase + pmem->size())) { --- 22 unchanged lines hidden (view full) --- 203 if (!pte.valid()) { 204 DPRINTF(GDBAcc, "acc: %#x pte is invalid\n", va); 205 return false; 206 } 207 va += TheISA::PageBytes; 208 } while (va < last_va); 209 210 DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); | 153 Addr last_va; 154 155 va = TheISA::TruncPage(va); 156 last_va = TheISA::RoundPage(va + len); 157 158 do { 159 if (TheISA::IsK0Seg(va)) { 160 if (va < (TheISA::K0SegBase + pmem->size())) { --- 22 unchanged lines hidden (view full) --- 183 if (!pte.valid()) { 184 DPRINTF(GDBAcc, "acc: %#x pte is invalid\n", va); 185 return false; 186 } 187 va += TheISA::PageBytes; 188 } while (va < last_va); 189 190 DPRINTF(GDBAcc, "acc: %#x mapping is valid\n", va); |
191#endif |
|
211 return true; 212} 213 214/////////////////////////////////////////////////////////// | 192 return true; 193} 194 195/////////////////////////////////////////////////////////// |
215// RemoteGDB::signal 216// 217// Translate a trap number into a Unix-compatible signal number. 218// (GDB only understands Unix signal numbers.) 219// 220int 221RemoteGDB::signal(int type) 222{ 223 switch (type) { 224 case ALPHA_KENTRY_INT: 225 return (SIGTRAP); 226 227 case ALPHA_KENTRY_UNA: 228 return (SIGBUS); 229 230 case ALPHA_KENTRY_ARITH: 231 return (SIGFPE); 232 233 case ALPHA_KENTRY_IF: 234 return (SIGILL); 235 236 case ALPHA_KENTRY_MM: 237 return (SIGSEGV); 238 239 default: 240 panic("unknown signal type"); 241 return 0; 242 } 243} 244 245/////////////////////////////////////////////////////////// | |
246// RemoteGDB::getregs 247// 248// Translate the kernel debugger register format into 249// the GDB register format. 250void 251RemoteGDB::getregs() 252{ 253 memset(gdbregs.regs, 0, gdbregs.size); 254 | 196// RemoteGDB::getregs 197// 198// Translate the kernel debugger register format into 199// the GDB register format. 200void 201RemoteGDB::getregs() 202{ 203 memset(gdbregs.regs, 0, gdbregs.size); 204 |
255 gdbregs.regs[KGDB_REG_PC] = context->readPC(); 256 257 // @todo: Currently this is very Alpha specific. 258 if (AlphaISA::PcPAL(gdbregs.regs[KGDB_REG_PC])) { 259 for (int i = 0; i < TheISA::NumIntArchRegs; ++i) { 260 gdbregs.regs[i] = context->readIntReg(AlphaISA::reg_redir[i]); 261 } 262 } else { 263 for (int i = 0; i < TheISA::NumIntArchRegs; ++i) { 264 gdbregs.regs[i] = context->readIntReg(i); 265 } 266 } 267 268#ifdef KGDB_FP_REGS 269 for (int i = 0; i < TheISA::NumFloatArchRegs; ++i) { 270 gdbregs.regs[i + KGDB_REG_F0] = context->readFloatRegBits(i); 271 } 272#endif | 205 gdbregs.regs[RegPc] = context->readPC(); 206 gdbregs.regs[RegNpc] = context->readNextPC(); 207 for(int x = RegG0; x <= RegI7; x++) 208 gdbregs.regs[x] = context->readIntReg(x - RegG0); 209 for(int x = RegF0; x <= RegF31; x++) 210 gdbregs.regs[x] = context->readFloatRegBits(x - RegF0); 211 gdbregs.regs[RegY] = context->readMiscReg(MISCREG_Y); 212 //XXX need to also load up Psr, Wim, Tbr, Fpsr, and Cpsr |
273} 274 275/////////////////////////////////////////////////////////// 276// RemoteGDB::setregs 277// 278// Translate the GDB register format into the kernel 279// debugger register format. 280// 281void 282RemoteGDB::setregs() 283{ | 213} 214 215/////////////////////////////////////////////////////////// 216// RemoteGDB::setregs 217// 218// Translate the GDB register format into the kernel 219// debugger register format. 220// 221void 222RemoteGDB::setregs() 223{ |
284 // @todo: Currently this is very Alpha specific. 285 if (AlphaISA::PcPAL(gdbregs.regs[KGDB_REG_PC])) { 286 for (int i = 0; i < TheISA::NumIntArchRegs; ++i) { 287 context->setIntReg(AlphaISA::reg_redir[i], gdbregs.regs[i]); 288 } 289 } else { 290 for (int i = 0; i < TheISA::NumIntArchRegs; ++i) { 291 context->setIntReg(i, gdbregs.regs[i]); 292 } 293 } 294 295#ifdef KGDB_FP_REGS 296 for (int i = 0; i < TheISA::NumFloatArchRegs; ++i) { 297 context->setFloatRegBits(i, gdbregs.regs[i + KGDB_REG_F0]); 298 } 299#endif 300 context->setPC(gdbregs.regs[KGDB_REG_PC]); | 224 context->setPC(gdbregs.regs[RegPc]); 225 context->setNextPC(gdbregs.regs[RegNpc]); 226 for(int x = RegG0; x <= RegI7; x++) 227 context->setIntReg(x - RegG0, gdbregs.regs[x]); 228 for(int x = RegF0; x <= RegF31; x++) 229 context->setFloatRegBits(x - RegF0, gdbregs.regs[x]); 230 context->setMiscRegWithEffect(MISCREG_Y, gdbregs.regs[RegY]); 231 //XXX need to also set Psr, Wim, Tbr, Fpsr, and Cpsr |
301} 302 303void | 232} 233 234void |
304RemoteGDB::setTempBreakpoint(TempBreakpoint &bkpt, Addr addr) 305{ 306 DPRINTF(GDBMisc, "setTempBreakpoint: addr=%#x\n", addr); 307 308 bkpt.address = addr; 309 insertHardBreak(addr, 4); 310} 311 312void 313RemoteGDB::clearTempBreakpoint(TempBreakpoint &bkpt) 314{ 315 DPRINTF(GDBMisc, "setTempBreakpoint: addr=%#x\n", 316 bkpt.address); 317 318 319 removeHardBreak(bkpt.address, 4); 320 bkpt.address = 0; 321} 322 323void | |
324RemoteGDB::clearSingleStep() 325{ | 235RemoteGDB::clearSingleStep() 236{ |
237#if 0 |
|
326 DPRINTF(GDBMisc, "clearSingleStep bt_addr=%#x nt_addr=%#x\n", 327 takenBkpt.address, notTakenBkpt.address); 328 329 if (takenBkpt.address != 0) 330 clearTempBreakpoint(takenBkpt); 331 332 if (notTakenBkpt.address != 0) 333 clearTempBreakpoint(notTakenBkpt); | 238 DPRINTF(GDBMisc, "clearSingleStep bt_addr=%#x nt_addr=%#x\n", 239 takenBkpt.address, notTakenBkpt.address); 240 241 if (takenBkpt.address != 0) 242 clearTempBreakpoint(takenBkpt); 243 244 if (notTakenBkpt.address != 0) 245 clearTempBreakpoint(notTakenBkpt); |
246#endif |
|
334} 335 336void 337RemoteGDB::setSingleStep() 338{ | 247} 248 249void 250RemoteGDB::setSingleStep() 251{ |
252#if 0 |
|
339 Addr pc = context->readPC(); 340 Addr npc, bpc; 341 bool set_bt = false; 342 343 npc = pc + sizeof(MachInst); 344 345 // User was stopped at pc, e.g. the instruction at pc was not 346 // executed. --- 8 unchanged lines hidden (view full) --- 355 356 DPRINTF(GDBMisc, "setSingleStep bt_addr=%#x nt_addr=%#x\n", 357 takenBkpt.address, notTakenBkpt.address); 358 359 setTempBreakpoint(notTakenBkpt, npc); 360 361 if (set_bt) 362 setTempBreakpoint(takenBkpt, bpc); | 253 Addr pc = context->readPC(); 254 Addr npc, bpc; 255 bool set_bt = false; 256 257 npc = pc + sizeof(MachInst); 258 259 // User was stopped at pc, e.g. the instruction at pc was not 260 // executed. --- 8 unchanged lines hidden (view full) --- 269 270 DPRINTF(GDBMisc, "setSingleStep bt_addr=%#x nt_addr=%#x\n", 271 takenBkpt.address, notTakenBkpt.address); 272 273 setTempBreakpoint(notTakenBkpt, npc); 274 275 if (set_bt) 276 setTempBreakpoint(takenBkpt, bpc); |
363} 364 365// Write bytes to kernel address space for debugger. 366bool 367RemoteGDB::write(Addr vaddr, size_t size, const char *data) 368{ 369 if (BaseRemoteGDB::write(vaddr, size, data)) { 370#ifdef IMB 371 alpha_pal_imb(); | |
372#endif | 277#endif |
373 return true; 374 } else { 375 return false; 376 } | |
377} | 278} |
378 379 380PCEventQueue *RemoteGDB::getPcEventQueue() 381{ 382 return &system->pcEventQueue; 383} 384 385 386RemoteGDB::HardBreakpoint::HardBreakpoint(RemoteGDB *_gdb, Addr pc) 387 : PCEvent(_gdb->getPcEventQueue(), "HardBreakpoint Event", pc), 388 gdb(_gdb), refcount(0) 389{ 390 DPRINTF(GDBMisc, "creating hardware breakpoint at %#x\n", evpc); 391} 392 393void 394RemoteGDB::HardBreakpoint::process(ThreadContext *tc) 395{ 396 DPRINTF(GDBMisc, "handling hardware breakpoint at %#x\n", pc()); 397 398 if (tc == gdb->context) 399 gdb->trap(ALPHA_KENTRY_INT); 400} 401 402bool 403RemoteGDB::insertSoftBreak(Addr addr, size_t len) 404{ 405 if (len != sizeof(MachInst)) 406 panic("invalid length\n"); 407 408 return insertHardBreak(addr, len); 409} 410 411bool 412RemoteGDB::removeSoftBreak(Addr addr, size_t len) 413{ 414 if (len != sizeof(MachInst)) 415 panic("invalid length\n"); 416 417 return removeHardBreak(addr, len); 418} 419 420bool 421RemoteGDB::insertHardBreak(Addr addr, size_t len) 422{ 423 if (len != sizeof(MachInst)) 424 panic("invalid length\n"); 425 426 DPRINTF(GDBMisc, "inserting hardware breakpoint at %#x\n", addr); 427 428 HardBreakpoint *&bkpt = hardBreakMap[addr]; 429 if (bkpt == 0) 430 bkpt = new HardBreakpoint(this, addr); 431 432 bkpt->refcount++; 433 434 return true; 435} 436 437bool 438RemoteGDB::removeHardBreak(Addr addr, size_t len) 439{ 440 if (len != sizeof(MachInst)) 441 panic("invalid length\n"); 442 443 DPRINTF(GDBMisc, "removing hardware breakpoint at %#x\n", addr); 444 445 break_iter_t i = hardBreakMap.find(addr); 446 if (i == hardBreakMap.end()) 447 return false; 448 449 HardBreakpoint *hbp = (*i).second; 450 if (--hbp->refcount == 0) { 451 delete hbp; 452 hardBreakMap.erase(i); 453 } 454 455 return true; 456} | |