13115SN/A/* 23115SN/A * Copyright (c) 2006 The Regents of The University of Michigan 33115SN/A * All rights reserved. 43115SN/A * 53115SN/A * Redistribution and use in source and binary forms, with or without 63115SN/A * modification, are permitted provided that the following conditions are 73115SN/A * met: redistributions of source code must retain the above copyright 83115SN/A * notice, this list of conditions and the following disclaimer; 93115SN/A * redistributions in binary form must reproduce the above copyright 103115SN/A * notice, this list of conditions and the following disclaimer in the 113115SN/A * documentation and/or other materials provided with the distribution; 123115SN/A * neither the name of the copyright holders nor the names of its 133115SN/A * contributors may be used to endorse or promote products derived from 143115SN/A * this software without specific prior written permission. 153115SN/A * 163115SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173115SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183115SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193115SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203115SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213115SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223115SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233115SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243115SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253115SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263115SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273115SN/A * 283115SN/A * Authors: Gabe Black 293115SN/A */ 303115SN/A 313115SN/A#include <sys/ptrace.h> 323115SN/A#include <stdint.h> 333115SN/A 348229Snate@binkert.org#include <cerrno> 358229Snate@binkert.org#include <iostream> 368229Snate@binkert.org 378117Sgblack@eecs.umich.edu#include "arch/i686/tracechild.hh" 383115SN/A 393115SN/Ausing namespace std; 403115SN/A 418108SN/Aint64_t 428117Sgblack@eecs.umich.eduI686TraceChild::getRegs(user_regs_struct & myregs, int num) 433115SN/A{ 448108SN/A assert(num < numregs && num >= 0); 458108SN/A switch (num) { 468108SN/A //GPRs 478108SN/A case EAX: return myregs.eax; 488108SN/A case EBX: return myregs.ebx; 498108SN/A case ECX: return myregs.ecx; 508108SN/A case EDX: return myregs.edx; 518108SN/A //Index registers 528108SN/A case ESI: return myregs.esi; 538108SN/A case EDI: return myregs.edi; 548108SN/A //Base pointer and stack pointer 558108SN/A case EBP: return myregs.ebp; 568108SN/A case ESP: return myregs.esp; 578108SN/A //Segmentation registers 588115SN/A case CS: return myregs.xcs; 598115SN/A case DS: return myregs.xds; 608115SN/A case ES: return myregs.xes; 618115SN/A case FS: return myregs.xfs; 628115SN/A case GS: return myregs.xgs; 638115SN/A case SS: return myregs.xss; 648108SN/A //PC 658108SN/A case EIP: return myregs.eip; 668108SN/A default: 678108SN/A assert(0); 688108SN/A return 0; 698108SN/A } 703115SN/A} 713115SN/A 728108SN/Abool 738117Sgblack@eecs.umich.eduI686TraceChild::update(int pid) 743115SN/A{ 758108SN/A oldregs = regs; 768108SN/A if (ptrace(PTRACE_GETREGS, pid, 0, ®s) != 0) 778108SN/A return false; 788108SN/A for (unsigned int x = 0; x < numregs; x++) { 798108SN/A regDiffSinceUpdate[x] = (getRegVal(x) != getOldRegVal(x)); 808108SN/A } 813115SN/A} 823115SN/A 838117Sgblack@eecs.umich.eduI686TraceChild::I686TraceChild() 843115SN/A{ 858108SN/A for (unsigned int x = 0; x < numregs; x++) 868108SN/A regDiffSinceUpdate[x] = false; 873115SN/A} 883115SN/A 898108SN/Aint64_t 908117Sgblack@eecs.umich.eduI686TraceChild::getRegVal(int num) 913115SN/A{ 928108SN/A return getRegs(regs, num); 933115SN/A} 943115SN/A 958108SN/Aint64_t 968117Sgblack@eecs.umich.eduI686TraceChild::getOldRegVal(int num) 973115SN/A{ 988108SN/A return getRegs(oldregs, num); 993115SN/A} 1003115SN/A 1018118Sgblack@eecs.umich.edubool 1028118Sgblack@eecs.umich.eduI686TraceChild::sendState(int socket) 1038118Sgblack@eecs.umich.edu{ 1048118Sgblack@eecs.umich.edu return false; 1058118Sgblack@eecs.umich.edu} 1068118Sgblack@eecs.umich.edu 1078108SN/ATraceChild * 1088108SN/AgenTraceChild() 1093115SN/A{ 1108117Sgblack@eecs.umich.edu return new I686TraceChild; 1113115SN/A} 112