nativetrace.hh revision 8737:770ccf3af571
1/* 2 * Copyright (c) 2006-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: Gabe Black 29 */ 30 31#ifndef __CPU_NATIVETRACE_HH__ 32#define __CPU_NATIVETRACE_HH__ 33 34#include <unistd.h> 35 36#include <cerrno> 37 38#include "base/socket.hh" 39#include "base/trace.hh" 40#include "base/types.hh" 41#include "cpu/exetrace.hh" 42#include "cpu/static_inst.hh" 43 44class ThreadContext; 45 46namespace Trace { 47 48class NativeTrace; 49 50class NativeTraceRecord : public ExeTracerRecord 51{ 52 protected: 53 NativeTrace * parent; 54 55 public: 56 NativeTraceRecord(NativeTrace * _parent, 57 Tick _when, ThreadContext *_thread, 58 const StaticInstPtr _staticInst, TheISA::PCState _pc, 59 bool spec, const StaticInstPtr _macroStaticInst = NULL) 60 : ExeTracerRecord(_when, _thread, _staticInst, _pc, spec, 61 _macroStaticInst), 62 parent(_parent) 63 { 64 } 65 66 void dump(); 67}; 68 69class NativeTrace : public ExeTracer 70{ 71 protected: 72 int fd; 73 74 ListenSocket native_listener; 75 76 public: 77 78 NativeTrace(const Params *p); 79 virtual ~NativeTrace() {} 80 81 NativeTraceRecord * 82 getInstRecord(Tick when, ThreadContext *tc, 83 const StaticInstPtr staticInst, TheISA::PCState pc, 84 const StaticInstPtr macroStaticInst = NULL) 85 { 86 if (tc->misspeculating()) 87 return NULL; 88 89 return new NativeTraceRecord(this, when, tc, 90 staticInst, pc, tc->misspeculating(), macroStaticInst); 91 } 92 93 template<class T> 94 bool 95 checkReg(const char * regName, T &val, T &realVal) 96 { 97 if(val != realVal) 98 { 99 DPRINTFN("Register %s should be %#x but is %#x.\n", 100 regName, realVal, val); 101 return false; 102 } 103 return true; 104 } 105 106 void 107 read(void *ptr, size_t size) 108 { 109 size_t soFar = 0; 110 while (soFar < size) { 111 ssize_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar); 112 if (res < 0) 113 panic("Read call failed! %s\n", strerror(errno)); 114 else 115 soFar += res; 116 } 117 } 118 119 virtual void 120 check(NativeTraceRecord *record) = 0; 121}; 122 123} // namespace Trace 124 125#endif // __CPU_NATIVETRACE_HH__ 126