nativetrace.hh revision 6365:a3037fa327a0
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2006-2009 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com * 2812855Sgabeblack@google.com * Authors: Gabe Black 2912855Sgabeblack@google.com */ 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com#ifndef __CPU_NATIVETRACE_HH__ 3212855Sgabeblack@google.com#define __CPU_NATIVETRACE_HH__ 3312855Sgabeblack@google.com 3412855Sgabeblack@google.com#include <errno.h> 3512855Sgabeblack@google.com#include <unistd.h> 3612855Sgabeblack@google.com 3712855Sgabeblack@google.com#include "base/socket.hh" 3812855Sgabeblack@google.com#include "base/trace.hh" 3912855Sgabeblack@google.com#include "base/types.hh" 4012855Sgabeblack@google.com#include "cpu/static_inst.hh" 4112855Sgabeblack@google.com#include "sim/insttracer.hh" 4212855Sgabeblack@google.com 4312855Sgabeblack@google.comclass ThreadContext; 4412855Sgabeblack@google.com 4512855Sgabeblack@google.comnamespace Trace { 4612855Sgabeblack@google.com 4712855Sgabeblack@google.comclass NativeTrace; 4812855Sgabeblack@google.com 4912855Sgabeblack@google.comclass NativeTraceRecord : public InstRecord 5012855Sgabeblack@google.com{ 5112855Sgabeblack@google.com protected: 5212855Sgabeblack@google.com NativeTrace * parent; 5312855Sgabeblack@google.com 5412855Sgabeblack@google.com public: 5512855Sgabeblack@google.com NativeTraceRecord(NativeTrace * _parent, 5612855Sgabeblack@google.com Tick _when, ThreadContext *_thread, 5712855Sgabeblack@google.com const StaticInstPtr _staticInst, Addr _pc, bool spec, 5812855Sgabeblack@google.com const StaticInstPtr _macroStaticInst = NULL, MicroPC _upc = 0) 5912855Sgabeblack@google.com : InstRecord(_when, _thread, _staticInst, _pc, spec, 6012855Sgabeblack@google.com _macroStaticInst, _upc), 6112855Sgabeblack@google.com parent(_parent) 6212855Sgabeblack@google.com { 6312855Sgabeblack@google.com } 6412855Sgabeblack@google.com 6512855Sgabeblack@google.com void dump(); 6612855Sgabeblack@google.com}; 6712855Sgabeblack@google.com 6812855Sgabeblack@google.comclass NativeTrace : public InstTracer 6912855Sgabeblack@google.com{ 7012855Sgabeblack@google.com protected: 7112855Sgabeblack@google.com int fd; 7212855Sgabeblack@google.com 7312855Sgabeblack@google.com ListenSocket native_listener; 7412855Sgabeblack@google.com 7512855Sgabeblack@google.com public: 7612855Sgabeblack@google.com 7712855Sgabeblack@google.com NativeTrace(const Params *p); 7812855Sgabeblack@google.com virtual ~NativeTrace() {} 7912855Sgabeblack@google.com 8012855Sgabeblack@google.com NativeTraceRecord * 8112855Sgabeblack@google.com getInstRecord(Tick when, ThreadContext *tc, 8212855Sgabeblack@google.com const StaticInstPtr staticInst, Addr pc, 8312855Sgabeblack@google.com const StaticInstPtr macroStaticInst = NULL, MicroPC upc = 0) 8412855Sgabeblack@google.com { 8512855Sgabeblack@google.com if (tc->misspeculating()) 8612855Sgabeblack@google.com return NULL; 8712855Sgabeblack@google.com 8812855Sgabeblack@google.com return new NativeTraceRecord(this, when, tc, 8912855Sgabeblack@google.com staticInst, pc, tc->misspeculating(), macroStaticInst, upc); 9012855Sgabeblack@google.com } 9112855Sgabeblack@google.com 9212855Sgabeblack@google.com template<class T> 9312855Sgabeblack@google.com bool 9412855Sgabeblack@google.com checkReg(const char * regName, T &val, T &realVal) 9512855Sgabeblack@google.com { 9612855Sgabeblack@google.com if(val != realVal) 9712855Sgabeblack@google.com { 9812855Sgabeblack@google.com DPRINTFN("Register %s should be %#x but is %#x.\n", 9912855Sgabeblack@google.com regName, realVal, val); 10012855Sgabeblack@google.com return false; 10112855Sgabeblack@google.com } 10212855Sgabeblack@google.com return true; 10312855Sgabeblack@google.com } 10412855Sgabeblack@google.com 10512855Sgabeblack@google.com void 10612855Sgabeblack@google.com read(void *ptr, size_t size) 10712855Sgabeblack@google.com { 10812855Sgabeblack@google.com size_t soFar = 0; 10912855Sgabeblack@google.com while (soFar < size) { 11012855Sgabeblack@google.com size_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar); 11112855Sgabeblack@google.com if (res < 0) 11212855Sgabeblack@google.com panic("Read call failed! %s\n", strerror(errno)); 11312855Sgabeblack@google.com else 11412855Sgabeblack@google.com soFar += res; 11512855Sgabeblack@google.com } 11612855Sgabeblack@google.com } 11712855Sgabeblack@google.com 11812855Sgabeblack@google.com virtual void 11912855Sgabeblack@google.com check(NativeTraceRecord *record) = 0; 12012855Sgabeblack@google.com}; 12112855Sgabeblack@google.com 12212855Sgabeblack@google.com} /* namespace Trace */ 12312855Sgabeblack@google.com 12412855Sgabeblack@google.com#endif // __CPU_NATIVETRACE_HH__ 12512855Sgabeblack@google.com