remote_gdb.cc revision 11274:d9a0136ab8cc
1/* 2 * Copyright 2015 LabWare 3 * Copyright 2014 Google, Inc. 4 * Copyright (c) 2007 The Hewlett-Packard Development Company 5 * All rights reserved. 6 * 7 * The license below extends only to copyright in the software and shall 8 * not be construed as granting a license to any other intellectual 9 * property including but not limited to intellectual property relating 10 * to a hardware implementation of the functionality of the software 11 * licensed hereunder. You may use the software subject to the license 12 * terms below provided that you ensure that this notice is replicated 13 * unmodified and in its entirety in all distributions of the software, 14 * modified or unmodified, in source code or in binary form. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions are 18 * met: redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer; 20 * redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution; 23 * neither the name of the copyright holders nor the names of its 24 * contributors may be used to endorse or promote products derived from 25 * this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 * 39 * Authors: Gabe Black 40 * Boris Shingarov 41 */ 42 43#include <sys/signal.h> 44#include <unistd.h> 45 46#include <string> 47 48#include "arch/x86/regs/int.hh" 49#include "arch/x86/regs/misc.hh" 50#include "arch/x86/pagetable_walker.hh" 51#include "arch/x86/process.hh" 52#include "arch/x86/remote_gdb.hh" 53#include "arch/vtophys.hh" 54#include "base/remote_gdb.hh" 55#include "base/socket.hh" 56#include "base/trace.hh" 57#include "cpu/base.hh" 58#include "cpu/thread_context.hh" 59#include "debug/GDBAcc.hh" 60#include "mem/page_table.hh" 61#include "sim/full_system.hh" 62 63using namespace std; 64using namespace X86ISA; 65 66RemoteGDB::RemoteGDB(System *_system, ThreadContext *c) : 67 BaseRemoteGDB(_system, c) 68{} 69 70bool 71RemoteGDB::acc(Addr va, size_t len) 72{ 73 if (FullSystem) { 74 Walker *walker = context->getDTBPtr()->getWalker(); 75 unsigned logBytes; 76 Fault fault = walker->startFunctional(context, va, logBytes, 77 BaseTLB::Read); 78 if (fault != NoFault) 79 return false; 80 81 Addr endVa = va + len - 1; 82 if ((va & ~mask(logBytes)) == (endVa & ~mask(logBytes))) 83 return true; 84 85 fault = walker->startFunctional(context, endVa, logBytes, 86 BaseTLB::Read); 87 return fault == NoFault; 88 } else { 89 TlbEntry entry; 90 return context->getProcessPtr()->pTable->lookup(va, entry); 91 } 92} 93 94RemoteGDB::BaseGdbRegCache* 95RemoteGDB::gdbRegs() 96{ 97 HandyM5Reg m5reg = context->readMiscRegNoEffect(MISCREG_M5_REG); 98 if (m5reg.submode == SixtyFourBitMode) 99 return new AMD64GdbRegCache(this); 100 else 101 return new X86GdbRegCache(this); 102} 103 104 105 106void 107RemoteGDB::AMD64GdbRegCache::getRegs(ThreadContext *context) 108{ 109 DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 110 r.rax = context->readIntReg(INTREG_RAX); 111 r.rbx = context->readIntReg(INTREG_RBX); 112 r.rcx = context->readIntReg(INTREG_RCX); 113 r.rdx = context->readIntReg(INTREG_RDX); 114 r.rsi = context->readIntReg(INTREG_RSI); 115 r.rdi = context->readIntReg(INTREG_RDI); 116 r.rbp = context->readIntReg(INTREG_RBP); 117 r.rsp = context->readIntReg(INTREG_RSP); 118 r.r8 = context->readIntReg(INTREG_R8); 119 r.r9 = context->readIntReg(INTREG_R9); 120 r.r10 = context->readIntReg(INTREG_R10); 121 r.r11 = context->readIntReg(INTREG_R11); 122 r.r12 = context->readIntReg(INTREG_R12); 123 r.r13 = context->readIntReg(INTREG_R13); 124 r.r14 = context->readIntReg(INTREG_R14); 125 r.r15 = context->readIntReg(INTREG_R15); 126 r.rip = context->pcState().pc(); 127 r.eflags = context->readMiscRegNoEffect(MISCREG_RFLAGS); 128 r.cs = context->readMiscRegNoEffect(MISCREG_CS); 129 r.ss = context->readMiscRegNoEffect(MISCREG_SS); 130 r.ds = context->readMiscRegNoEffect(MISCREG_DS); 131 r.es = context->readMiscRegNoEffect(MISCREG_ES); 132 r.fs = context->readMiscRegNoEffect(MISCREG_FS); 133 r.gs = context->readMiscRegNoEffect(MISCREG_GS); 134} 135 136void 137RemoteGDB::X86GdbRegCache::getRegs(ThreadContext *context) 138{ 139 DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 140 r.eax = context->readIntReg(INTREG_RAX); 141 r.ecx = context->readIntReg(INTREG_RCX); 142 r.edx = context->readIntReg(INTREG_RDX); 143 r.ebx = context->readIntReg(INTREG_RBX); 144 r.esp = context->readIntReg(INTREG_RSP); 145 r.ebp = context->readIntReg(INTREG_RBP); 146 r.esi = context->readIntReg(INTREG_RSI); 147 r.edi = context->readIntReg(INTREG_RDI); 148 r.eip = context->pcState().pc(); 149 r.eflags = context->readMiscRegNoEffect(MISCREG_RFLAGS); 150 r.cs = context->readMiscRegNoEffect(MISCREG_CS); 151 r.ss = context->readMiscRegNoEffect(MISCREG_SS); 152 r.ds = context->readMiscRegNoEffect(MISCREG_DS); 153 r.es = context->readMiscRegNoEffect(MISCREG_ES); 154 r.fs = context->readMiscRegNoEffect(MISCREG_FS); 155 r.gs = context->readMiscRegNoEffect(MISCREG_GS); 156} 157 158void 159RemoteGDB::AMD64GdbRegCache::setRegs(ThreadContext *context) const 160{ 161 DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 162 context->setIntReg(INTREG_RAX, r.rax); 163 context->setIntReg(INTREG_RBX, r.rbx); 164 context->setIntReg(INTREG_RCX, r.rcx); 165 context->setIntReg(INTREG_RDX, r.rdx); 166 context->setIntReg(INTREG_RSI, r.rsi); 167 context->setIntReg(INTREG_RDI, r.rdi); 168 context->setIntReg(INTREG_RBP, r.rbp); 169 context->setIntReg(INTREG_RSP, r.rsp); 170 context->setIntReg(INTREG_R8, r.r8); 171 context->setIntReg(INTREG_R9, r.r9); 172 context->setIntReg(INTREG_R10, r.r10); 173 context->setIntReg(INTREG_R11, r.r11); 174 context->setIntReg(INTREG_R12, r.r12); 175 context->setIntReg(INTREG_R13, r.r13); 176 context->setIntReg(INTREG_R14, r.r14); 177 context->setIntReg(INTREG_R15, r.r15); 178 context->pcState(r.rip); 179 context->setMiscReg(MISCREG_RFLAGS, r.eflags); 180 if (r.cs != context->readMiscRegNoEffect(MISCREG_CS)) 181 warn("Remote gdb: Ignoring update to CS.\n"); 182 if (r.ss != context->readMiscRegNoEffect(MISCREG_SS)) 183 warn("Remote gdb: Ignoring update to SS.\n"); 184 if (r.ds != context->readMiscRegNoEffect(MISCREG_DS)) 185 warn("Remote gdb: Ignoring update to DS.\n"); 186 if (r.es != context->readMiscRegNoEffect(MISCREG_ES)) 187 warn("Remote gdb: Ignoring update to ES.\n"); 188 if (r.fs != context->readMiscRegNoEffect(MISCREG_FS)) 189 warn("Remote gdb: Ignoring update to FS.\n"); 190 if (r.gs != context->readMiscRegNoEffect(MISCREG_GS)) 191 warn("Remote gdb: Ignoring update to GS.\n"); 192} 193 194void 195RemoteGDB::X86GdbRegCache::setRegs(ThreadContext *context) const 196{ 197 DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 198 context->setIntReg(INTREG_RAX, r.eax); 199 context->setIntReg(INTREG_RCX, r.ecx); 200 context->setIntReg(INTREG_RDX, r.edx); 201 context->setIntReg(INTREG_RBX, r.ebx); 202 context->setIntReg(INTREG_RSP, r.esp); 203 context->setIntReg(INTREG_RBP, r.ebp); 204 context->setIntReg(INTREG_RSI, r.esi); 205 context->setIntReg(INTREG_RDI, r.edi); 206 context->pcState(r.eip); 207 context->setMiscReg(MISCREG_RFLAGS, r.eflags); 208 if (r.cs != context->readMiscRegNoEffect(MISCREG_CS)) 209 warn("Remote gdb: Ignoring update to CS.\n"); 210 if (r.ss != context->readMiscRegNoEffect(MISCREG_SS)) 211 warn("Remote gdb: Ignoring update to SS.\n"); 212 if (r.ds != context->readMiscRegNoEffect(MISCREG_DS)) 213 warn("Remote gdb: Ignoring update to DS.\n"); 214 if (r.es != context->readMiscRegNoEffect(MISCREG_ES)) 215 warn("Remote gdb: Ignoring update to ES.\n"); 216 if (r.fs != context->readMiscRegNoEffect(MISCREG_FS)) 217 warn("Remote gdb: Ignoring update to FS.\n"); 218 if (r.gs != context->readMiscRegNoEffect(MISCREG_GS)) 219 warn("Remote gdb: Ignoring update to GS.\n"); 220} 221