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