remote_gdb.cc revision 12449:2260f4a68210
1695SN/A/* 29262Ssascha.bischoff@arm.com * Copyright 2015 LabWare 39262Ssascha.bischoff@arm.com * Copyright 2014 Google, Inc. 49262Ssascha.bischoff@arm.com * Copyright (c) 2007 The Hewlett-Packard Development Company 59262Ssascha.bischoff@arm.com * All rights reserved. 69262Ssascha.bischoff@arm.com * 79262Ssascha.bischoff@arm.com * The license below extends only to copyright in the software and shall 89262Ssascha.bischoff@arm.com * not be construed as granting a license to any other intellectual 99262Ssascha.bischoff@arm.com * property including but not limited to intellectual property relating 109262Ssascha.bischoff@arm.com * to a hardware implementation of the functionality of the software 119262Ssascha.bischoff@arm.com * licensed hereunder. You may use the software subject to the license 129262Ssascha.bischoff@arm.com * terms below provided that you ensure that this notice is replicated 139262Ssascha.bischoff@arm.com * unmodified and in its entirety in all distributions of the software, 141762SN/A * modified or unmodified, in source code or in binary form. 15695SN/A * 16695SN/A * Redistribution and use in source and binary forms, with or without 17695SN/A * modification, are permitted provided that the following conditions are 18695SN/A * met: redistributions of source code must retain the above copyright 19695SN/A * notice, this list of conditions and the following disclaimer; 20695SN/A * redistributions in binary form must reproduce the above copyright 21695SN/A * notice, this list of conditions and the following disclaimer in the 22695SN/A * documentation and/or other materials provided with the distribution; 23695SN/A * neither the name of the copyright holders nor the names of its 24695SN/A * contributors may be used to endorse or promote products derived from 25695SN/A * this software without specific prior written permission. 26695SN/A * 27695SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28695SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29695SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30695SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31695SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32695SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33695SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34695SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35695SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36695SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37695SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38695SN/A * 392665Ssaidi@eecs.umich.edu * Authors: Gabe Black 402665Ssaidi@eecs.umich.edu * Boris Shingarov 419262Ssascha.bischoff@arm.com */ 42695SN/A 43695SN/A#include "arch/x86/remote_gdb.hh" 44695SN/A 45695SN/A#include <sys/signal.h> 46695SN/A#include <unistd.h> 4711793Sbrandon.potter@amd.com 4811793Sbrandon.potter@amd.com#include <string> 4911793Sbrandon.potter@amd.com 50729SN/A#include "arch/vtophys.hh" 51695SN/A#include "arch/x86/pagetable_walker.hh" 529554Sandreas.hansson@arm.com#include "arch/x86/process.hh" 539554Sandreas.hansson@arm.com#include "arch/x86/regs/int.hh" 549554Sandreas.hansson@arm.com#include "arch/x86/regs/misc.hh" 559554Sandreas.hansson@arm.com#include "base/remote_gdb.hh" 569554Sandreas.hansson@arm.com#include "base/socket.hh" 579554Sandreas.hansson@arm.com#include "base/trace.hh" 584078Sbinkertn@umich.edu#include "cpu/base.hh" 599262Ssascha.bischoff@arm.com#include "cpu/thread_context.hh" 609262Ssascha.bischoff@arm.com#include "debug/GDBAcc.hh" 619262Ssascha.bischoff@arm.com#include "mem/page_table.hh" 629262Ssascha.bischoff@arm.com#include "sim/full_system.hh" 639262Ssascha.bischoff@arm.com 649262Ssascha.bischoff@arm.comusing namespace std; 659262Ssascha.bischoff@arm.comusing namespace X86ISA; 669262Ssascha.bischoff@arm.com 679262Ssascha.bischoff@arm.comRemoteGDB::RemoteGDB(System *_system, ThreadContext *c, int _port) : 689262Ssascha.bischoff@arm.com BaseRemoteGDB(_system, c, _port), regCache32(this), regCache64(this) 699262Ssascha.bischoff@arm.com{} 709262Ssascha.bischoff@arm.com 719262Ssascha.bischoff@arm.combool 729262Ssascha.bischoff@arm.comRemoteGDB::acc(Addr va, size_t len) 739262Ssascha.bischoff@arm.com{ 749262Ssascha.bischoff@arm.com if (FullSystem) { 759262Ssascha.bischoff@arm.com Walker *walker = dynamic_cast<TLB *>( 769262Ssascha.bischoff@arm.com context()->getDTBPtr())->getWalker(); 777823Ssteve.reinhardt@amd.com unsigned logBytes; 787822Ssteve.reinhardt@amd.com Fault fault = walker->startFunctional(context(), va, logBytes, 79695SN/A BaseTLB::Read); 809262Ssascha.bischoff@arm.com if (fault != NoFault) 819262Ssascha.bischoff@arm.com return false; 829262Ssascha.bischoff@arm.com 839262Ssascha.bischoff@arm.com Addr endVa = va + len - 1; 849262Ssascha.bischoff@arm.com if ((va & ~mask(logBytes)) == (endVa & ~mask(logBytes))) 859262Ssascha.bischoff@arm.com return true; 869450Ssascha.bischoff@arm.com 877811Ssteve.reinhardt@amd.com fault = walker->startFunctional(context(), endVa, logBytes, 88695SN/A BaseTLB::Read); 89695SN/A return fault == NoFault; 90 } else { 91 TlbEntry entry; 92 return context()->getProcessPtr()->pTable->lookup(va, entry); 93 } 94} 95 96BaseGdbRegCache* 97RemoteGDB::gdbRegs() 98{ 99 HandyM5Reg m5reg = context()->readMiscRegNoEffect(MISCREG_M5_REG); 100 if (m5reg.submode == SixtyFourBitMode) 101 return ®Cache64; 102 else 103 return ®Cache32; 104} 105 106 107 108void 109RemoteGDB::AMD64GdbRegCache::getRegs(ThreadContext *context) 110{ 111 DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 112 r.rax = context->readIntReg(INTREG_RAX); 113 r.rbx = context->readIntReg(INTREG_RBX); 114 r.rcx = context->readIntReg(INTREG_RCX); 115 r.rdx = context->readIntReg(INTREG_RDX); 116 r.rsi = context->readIntReg(INTREG_RSI); 117 r.rdi = context->readIntReg(INTREG_RDI); 118 r.rbp = context->readIntReg(INTREG_RBP); 119 r.rsp = context->readIntReg(INTREG_RSP); 120 r.r8 = context->readIntReg(INTREG_R8); 121 r.r9 = context->readIntReg(INTREG_R9); 122 r.r10 = context->readIntReg(INTREG_R10); 123 r.r11 = context->readIntReg(INTREG_R11); 124 r.r12 = context->readIntReg(INTREG_R12); 125 r.r13 = context->readIntReg(INTREG_R13); 126 r.r14 = context->readIntReg(INTREG_R14); 127 r.r15 = context->readIntReg(INTREG_R15); 128 r.rip = context->pcState().pc(); 129 r.eflags = context->readMiscRegNoEffect(MISCREG_RFLAGS); 130 r.cs = context->readMiscRegNoEffect(MISCREG_CS); 131 r.ss = context->readMiscRegNoEffect(MISCREG_SS); 132 r.ds = context->readMiscRegNoEffect(MISCREG_DS); 133 r.es = context->readMiscRegNoEffect(MISCREG_ES); 134 r.fs = context->readMiscRegNoEffect(MISCREG_FS); 135 r.gs = context->readMiscRegNoEffect(MISCREG_GS); 136} 137 138void 139RemoteGDB::X86GdbRegCache::getRegs(ThreadContext *context) 140{ 141 DPRINTF(GDBAcc, "getRegs in remotegdb \n"); 142 r.eax = context->readIntReg(INTREG_RAX); 143 r.ecx = context->readIntReg(INTREG_RCX); 144 r.edx = context->readIntReg(INTREG_RDX); 145 r.ebx = context->readIntReg(INTREG_RBX); 146 r.esp = context->readIntReg(INTREG_RSP); 147 r.ebp = context->readIntReg(INTREG_RBP); 148 r.esi = context->readIntReg(INTREG_RSI); 149 r.edi = context->readIntReg(INTREG_RDI); 150 r.eip = context->pcState().pc(); 151 r.eflags = context->readMiscRegNoEffect(MISCREG_RFLAGS); 152 r.cs = context->readMiscRegNoEffect(MISCREG_CS); 153 r.ss = context->readMiscRegNoEffect(MISCREG_SS); 154 r.ds = context->readMiscRegNoEffect(MISCREG_DS); 155 r.es = context->readMiscRegNoEffect(MISCREG_ES); 156 r.fs = context->readMiscRegNoEffect(MISCREG_FS); 157 r.gs = context->readMiscRegNoEffect(MISCREG_GS); 158} 159 160void 161RemoteGDB::AMD64GdbRegCache::setRegs(ThreadContext *context) const 162{ 163 DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 164 context->setIntReg(INTREG_RAX, r.rax); 165 context->setIntReg(INTREG_RBX, r.rbx); 166 context->setIntReg(INTREG_RCX, r.rcx); 167 context->setIntReg(INTREG_RDX, r.rdx); 168 context->setIntReg(INTREG_RSI, r.rsi); 169 context->setIntReg(INTREG_RDI, r.rdi); 170 context->setIntReg(INTREG_RBP, r.rbp); 171 context->setIntReg(INTREG_RSP, r.rsp); 172 context->setIntReg(INTREG_R8, r.r8); 173 context->setIntReg(INTREG_R9, r.r9); 174 context->setIntReg(INTREG_R10, r.r10); 175 context->setIntReg(INTREG_R11, r.r11); 176 context->setIntReg(INTREG_R12, r.r12); 177 context->setIntReg(INTREG_R13, r.r13); 178 context->setIntReg(INTREG_R14, r.r14); 179 context->setIntReg(INTREG_R15, r.r15); 180 context->pcState(r.rip); 181 context->setMiscReg(MISCREG_RFLAGS, r.eflags); 182 if (r.cs != context->readMiscRegNoEffect(MISCREG_CS)) 183 warn("Remote gdb: Ignoring update to CS.\n"); 184 if (r.ss != context->readMiscRegNoEffect(MISCREG_SS)) 185 warn("Remote gdb: Ignoring update to SS.\n"); 186 if (r.ds != context->readMiscRegNoEffect(MISCREG_DS)) 187 warn("Remote gdb: Ignoring update to DS.\n"); 188 if (r.es != context->readMiscRegNoEffect(MISCREG_ES)) 189 warn("Remote gdb: Ignoring update to ES.\n"); 190 if (r.fs != context->readMiscRegNoEffect(MISCREG_FS)) 191 warn("Remote gdb: Ignoring update to FS.\n"); 192 if (r.gs != context->readMiscRegNoEffect(MISCREG_GS)) 193 warn("Remote gdb: Ignoring update to GS.\n"); 194} 195 196void 197RemoteGDB::X86GdbRegCache::setRegs(ThreadContext *context) const 198{ 199 DPRINTF(GDBAcc, "setRegs in remotegdb \n"); 200 context->setIntReg(INTREG_RAX, r.eax); 201 context->setIntReg(INTREG_RCX, r.ecx); 202 context->setIntReg(INTREG_RDX, r.edx); 203 context->setIntReg(INTREG_RBX, r.ebx); 204 context->setIntReg(INTREG_RSP, r.esp); 205 context->setIntReg(INTREG_RBP, r.ebp); 206 context->setIntReg(INTREG_RSI, r.esi); 207 context->setIntReg(INTREG_RDI, r.edi); 208 context->pcState(r.eip); 209 context->setMiscReg(MISCREG_RFLAGS, r.eflags); 210 if (r.cs != context->readMiscRegNoEffect(MISCREG_CS)) 211 warn("Remote gdb: Ignoring update to CS.\n"); 212 if (r.ss != context->readMiscRegNoEffect(MISCREG_SS)) 213 warn("Remote gdb: Ignoring update to SS.\n"); 214 if (r.ds != context->readMiscRegNoEffect(MISCREG_DS)) 215 warn("Remote gdb: Ignoring update to DS.\n"); 216 if (r.es != context->readMiscRegNoEffect(MISCREG_ES)) 217 warn("Remote gdb: Ignoring update to ES.\n"); 218 if (r.fs != context->readMiscRegNoEffect(MISCREG_FS)) 219 warn("Remote gdb: Ignoring update to FS.\n"); 220 if (r.gs != context->readMiscRegNoEffect(MISCREG_GS)) 221 warn("Remote gdb: Ignoring update to GS.\n"); 222} 223