tracechild.cc revision 3115
1545SN/A/* 28948Sandreas.hansson@arm.com * Copyright (c) 2006 The Regents of The University of Michigan 38948Sandreas.hansson@arm.com * All rights reserved. 48948Sandreas.hansson@arm.com * 58948Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68948Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78948Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88948Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98948Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108948Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118948Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128948Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138948Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 142512SN/A * this software without specific prior written permission. 15545SN/A * 16545SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17545SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18545SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19545SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20545SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21545SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22545SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23545SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24545SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25545SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26545SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27545SN/A * 28545SN/A * Authors: Gabe Black 29545SN/A */ 30545SN/A 31545SN/A#include <iostream> 32545SN/A#include <errno.h> 33545SN/A#include <sys/ptrace.h> 34545SN/A#include <stdint.h> 35545SN/A 36545SN/A#include "tracechild_i386.hh" 37545SN/A 38545SN/Ausing namespace std; 392665Ssaidi@eecs.umich.edu 402665Ssaidi@eecs.umich.educhar * I386TraceChild::regNames[numregs] = { 412665Ssaidi@eecs.umich.edu //GPRs 42545SN/A "eax", "ebx", "ecx", "edx", 43545SN/A //Index registers 442657Ssaidi@eecs.umich.edu "esi", "edi", 458232Snate@binkert.org //Base pointer and stack pointer 46545SN/A "ebp", "esp", 472901Ssaidi@eecs.umich.edu //Segmentation registers 48545SN/A "cs", "ds", "es", "fs", "gs", "ss", 498914Sandreas.hansson@arm.com //PC 509095Sandreas.hansson@arm.com "eip"}; 518914Sandreas.hansson@arm.com 528914Sandreas.hansson@arm.comint64_t I386TraceChild::getRegs(user_regs_struct & myregs, int num) 532489SN/A{ 542489SN/A assert(num < numregs && num >= 0); 553349Sbinkertn@umich.edu switch(num) 562489SN/A { 573091Sstever@eecs.umich.edu //GPRs 582489SN/A case EAX: return myregs.eax; 592489SN/A case EBX: return myregs.ebx; 608711Sandreas.hansson@arm.com case ECX: return myregs.ecx; 619090Sandreas.hansson@arm.com case EDX: return myregs.edx; 622489SN/A //Index registers 638711Sandreas.hansson@arm.com case ESI: return myregs.esi; 642489SN/A case EDI: return myregs.edi; 652489SN/A //Base pointer and stack pointer 664762Snate@binkert.org case EBP: return myregs.ebp; 678914Sandreas.hansson@arm.com case ESP: return myregs.esp; 684762Snate@binkert.org //Segmentation registers 694762Snate@binkert.org case CS: return myregs.cs; 70545SN/A case DS: return myregs.ds; 71545SN/A case ES: return myregs.es; 72545SN/A case FS: return myregs.fs; 73545SN/A case GS: return myregs.gs; 742542SN/A case SS: return myregs.ss; 752541SN/A //PC 762541SN/A case EIP: return myregs.eip; 778851Sandreas.hansson@arm.com default: 788674Snilay@cs.wisc.edu assert(0); 798851Sandreas.hansson@arm.com return 0; 802541SN/A } 812541SN/A} 828922Swilliam.wang@arm.com 838922Swilliam.wang@arm.combool I386TraceChild::update(int pid) 848598Ssteve.reinhardt@amd.com{ 858598Ssteve.reinhardt@amd.com oldregs = regs; 868922Swilliam.wang@arm.com if(ptrace(PTRACE_GETREGS, pid, 0, ®s) != 0) 878598Ssteve.reinhardt@amd.com return false; 888922Swilliam.wang@arm.com for(unsigned int x = 0; x < numregs; x++) 898598Ssteve.reinhardt@amd.com { 902901Ssaidi@eecs.umich.edu regDiffSinceUpdate[x] = 912901Ssaidi@eecs.umich.edu (getRegVal(x) != getOldRegVal(x)); 922901Ssaidi@eecs.umich.edu } 932901Ssaidi@eecs.umich.edu} 942901Ssaidi@eecs.umich.edu 958851Sandreas.hansson@arm.comI386TraceChild::I386TraceChild() 962901Ssaidi@eecs.umich.edu{ 972901Ssaidi@eecs.umich.edu for(unsigned int x = 0; x < numregs; x++) 982901Ssaidi@eecs.umich.edu regDiffSinceUpdate[x] = false; 992901Ssaidi@eecs.umich.edu} 1002901Ssaidi@eecs.umich.edu 1012901Ssaidi@eecs.umich.eduint64_t I386TraceChild::getRegVal(int num) 1022901Ssaidi@eecs.umich.edu{ 1034762Snate@binkert.org return getRegs(regs, num); 1044762Snate@binkert.org} 1054762Snate@binkert.org 1064762Snate@binkert.orgint64_t I386TraceChild::getOldRegVal(int num) 1074762Snate@binkert.org{ 1088711Sandreas.hansson@arm.com return getRegs(oldregs, num); 1099090Sandreas.hansson@arm.com} 1102539SN/A 1112539SN/Achar * I386TraceChild::printReg(int num) 1128711Sandreas.hansson@arm.com{ 1137729SAli.Saidi@ARM.com sprintf(printBuffer, "0x%08X", getRegVal(num)); 1148711Sandreas.hansson@arm.com return printBuffer; 1158711Sandreas.hansson@arm.com} 1162539SN/A 117TraceChild * genTraceChild() 118{ 119 return new I386TraceChild; 120} 121