tracechild.hh revision 6216
12SN/A/* 21762SN/A * Copyright (c) 2006 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272SN/A * 282SN/A * Authors: Gabe Black 292SN/A */ 302SN/A 312SN/A#ifndef REGSTATE_I386_HH 322SN/A#define REGSTATE_I386_HH 332SN/A 342432SN/A#include <linux/user.h> 351147SN/A#include <sys/types.h> 362090SN/A#include <sys/ptrace.h> 371147SN/A#include <cassert> 382517SN/A#include <string> 3956SN/A 402SN/A#include "tracechild.hh" 412SN/A 422SN/Aclass I386TraceChild : public TraceChild 43674SN/A{ 442SN/Apublic: 452SN/A enum RegNum 462SN/A { 472SN/A //GPRs 482SN/A EAX, EBX, ECX, EDX, 492SN/A //Index registers 502SN/A ESI, EDI, 512SN/A //Base pointer and stack pointer 522SN/A EBP, ESP, 532SN/A //Segmentation registers 542SN/A CS, DS, ES, FS, GS, SS, 552SN/A //PC 562SN/A EIP, 57674SN/A numregs 58674SN/A }; 592SN/Aprivate: 602SN/A char printBuffer [256]; 612SN/A static char * regNames[numregs]; 62555SN/A int64_t getRegs(user_regs_struct & myregs, int num); 632SN/A user_regs_struct regs; 642SN/A user_regs_struct oldregs; 652SN/A bool regDiffSinceUpdate[numregs]; 662SN/A 672SN/Aprotected: 682SN/A bool update(int pid); 692SN/A 702SN/Apublic: 712SN/A 721147SN/A I386TraceChild(); 731147SN/A 742SN/A int getNumRegs() 752SN/A { 762532SN/A return numregs; 772SN/A } 782SN/A 79217SN/A bool diffSinceUpdate(int num) 80237SN/A { 812SN/A assert(num < numregs && num >= 0); 822SN/A return regDiffSinceUpdate[num]; 83674SN/A } 842SN/A 852SN/A std::string getRegName(int num) 86729SN/A { 87729SN/A assert(num < numregs && num >= 0); 88729SN/A return regNames[num]; 89729SN/A } 902SN/A 912SN/A int64_t getRegVal(int num); 92674SN/A int64_t getOldRegVal(int num); 932SN/A uint64_t getPC() {return getRegVal(EIP);} 942SN/A uint64_t getSP() {return getRegVal(ESP);} 952532SN/A std::ostream & outputStartState(std::ostream & output) 962SN/A { 972SN/A output << "Printing i386 initial state not yet implemented" 98674SN/A << std::endl; 992SN/A return output; 1002SN/A } 101729SN/A 102729SN/A char * printReg(int num); 103729SN/A}; 104729SN/A 105729SN/A#endif 106729SN/A