stacktrace.hh revision 5254
12239SN/A/* 25254Sksewell@umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan 35254Sksewell@umich.edu * All rights reserved. 42239SN/A * 55254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 65254Sksewell@umich.edu * modification, are permitted provided that the following conditions are 75254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 85254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 95254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 105254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 115254Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 125254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 135254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 145254Sksewell@umich.edu * this software without specific prior written permission. 152239SN/A * 165254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205254Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215254Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225254Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235254Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245254Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255254Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265254Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 285254Sksewell@umich.edu * Authors: Ali Saidi 292239SN/A */ 302239SN/A 312745Sksewell@umich.edu#ifndef __ARCH_MIPS_STACKTRACE_HH__ 322745Sksewell@umich.edu#define __ARCH_MIPS_STACKTRACE_HH__ 332239SN/A 342239SN/A#include "base/trace.hh" 352239SN/A#include "cpu/static_inst.hh" 362239SN/A 372680Sktlim@umich.educlass ThreadContext; 382239SN/A 393580Sgblack@eecs.umich.edunamespace MipsISA 403580Sgblack@eecs.umich.edu{ 413580Sgblack@eecs.umich.edu 422239SN/Aclass ProcessInfo 432239SN/A{ 442239SN/A private: 452680Sktlim@umich.edu ThreadContext *tc; 462239SN/A 472239SN/A int thread_info_size; 482239SN/A int task_struct_size; 492239SN/A int task_off; 502239SN/A int pid_off; 512239SN/A int name_off; 522239SN/A 532239SN/A public: 542680Sktlim@umich.edu ProcessInfo(ThreadContext *_tc); 552239SN/A 562239SN/A Addr task(Addr ksp) const; 572239SN/A int pid(Addr ksp) const; 582239SN/A std::string name(Addr ksp) const; 592239SN/A}; 602239SN/A 612239SN/Aclass StackTrace 622239SN/A{ 632239SN/A protected: 642239SN/A typedef TheISA::MachInst MachInst; 652239SN/A private: 662680Sktlim@umich.edu ThreadContext *tc; 672239SN/A std::vector<Addr> stack; 682239SN/A 692239SN/A private: 702239SN/A bool isEntry(Addr addr); 712239SN/A bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra); 722239SN/A bool decodeSave(MachInst inst, int ®, int &disp); 732239SN/A bool decodeStack(MachInst inst, int &disp); 742239SN/A 752680Sktlim@umich.edu void trace(ThreadContext *tc, bool is_call); 762239SN/A 772239SN/A public: 782239SN/A StackTrace(); 792680Sktlim@umich.edu StackTrace(ThreadContext *tc, StaticInstPtr inst); 802239SN/A ~StackTrace(); 812239SN/A 822239SN/A void clear() 832239SN/A { 842680Sktlim@umich.edu tc = 0; 852239SN/A stack.clear(); 862239SN/A } 872239SN/A 882680Sktlim@umich.edu bool valid() const { return tc != NULL; } 892680Sktlim@umich.edu bool trace(ThreadContext *tc, StaticInstPtr inst); 902239SN/A 912239SN/A public: 922239SN/A const std::vector<Addr> &getstack() const { return stack; } 932239SN/A 942239SN/A static const int user = 1; 952239SN/A static const int console = 2; 962239SN/A static const int unknown = 3; 972239SN/A 982239SN/A#if TRACING_ON 992239SN/A private: 1002239SN/A void dump(); 1012239SN/A 1022239SN/A public: 1032239SN/A void dprintf() { if (DTRACE(Stack)) dump(); } 1042239SN/A#else 1052239SN/A public: 1062239SN/A void dprintf() {} 1072239SN/A#endif 1082239SN/A}; 1092239SN/A 1102239SN/Ainline bool 1112680Sktlim@umich.eduStackTrace::trace(ThreadContext *tc, StaticInstPtr inst) 1122239SN/A{ 1132239SN/A if (!inst->isCall() && !inst->isReturn()) 1142239SN/A return false; 1152239SN/A 1162239SN/A if (valid()) 1172239SN/A clear(); 1182239SN/A 1192680Sktlim@umich.edu trace(tc, !inst->isReturn()); 1202239SN/A return true; 1212239SN/A} 1222239SN/A 1233580Sgblack@eecs.umich.edu} 1243580Sgblack@eecs.umich.edu 1252745Sksewell@umich.edu#endif // __ARCH_MIPS_STACKTRACE_HH__ 126