tracechild.hh revision 6407
1/* 2 * Copyright (c) 2009 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Ali Saidi 29 * Gabe Black 30 */ 31 32#ifndef TRACECHILD_ARM_HH 33#define TRACECHILD_ARM_HH 34 35#include <cassert> 36#include <string> 37#include <sys/user.h> 38#include <sys/ptrace.h> 39#include "tracechild.hh" 40 41 42class ARMTraceChild : public TraceChild 43{ 44 public: 45 enum RegNum 46 { 47 // r0 - r3 argument, temp, caller save 48 // r4 - r10 callee save 49 // r11 - FP 50 // r12 - temp 51 // r13 - stack 52 // r14 - link 53 // r15 - pc 54 R0, R1, R2, R3, R4, R5, R6, R7, 55 R8, R9, R10, FP, R12, SP, LR, PC, 56 CPSR, 57 numregs 58 }; 59 private: 60 char printBuffer[256]; 61 static const char *regNames[numregs]; 62 uint32_t getRegs(user_regs& myregs, int num); 63 user_regs regs; 64 user_regs oldregs; 65 bool regDiffSinceUpdate[numregs]; 66 67 protected: 68 bool update(int pid); 69 70 public: 71 ARMTraceChild(); 72 bool sendState(int socket); 73 74 int getNumRegs() 75 { 76 return numregs; 77 } 78 79 bool diffSinceUpdate(int num) 80 { 81 assert(num < numregs && num >= 0); 82 return regDiffSinceUpdate[num]; 83 } 84 85 std::string getRegName(int num) 86 { 87 assert(num < numregs && num >= 0); 88 return regNames[num]; 89 } 90 91 int64_t getRegVal(int num); 92 int64_t getOldRegVal(int num); 93 94 bool step(); 95 96 uint64_t getPC() 97 { 98 return getRegVal(PC); 99 } 100 101 uint64_t getSP() 102 { 103 return getRegVal(SP); 104 } 105 106 char * printReg(int num); 107 108 std::ostream & outputStartState(std::ostream & os); 109 110}; 111 112#endif 113 114