stacktrace.hh revision 3580
12810SN/A/* 22810SN/A * Copyright (c) 2005 The Regents of The University of Michigan 32810SN/A * All rights reserved. 42810SN/A * 52810SN/A * Redistribution and use in source and binary forms, with or without 62810SN/A * modification, are permitted provided that the following conditions are 72810SN/A * met: redistributions of source code must retain the above copyright 82810SN/A * notice, this list of conditions and the following disclaimer; 92810SN/A * redistributions in binary form must reproduce the above copyright 102810SN/A * notice, this list of conditions and the following disclaimer in the 112810SN/A * documentation and/or other materials provided with the distribution; 122810SN/A * neither the name of the copyright holders nor the names of its 132810SN/A * contributors may be used to endorse or promote products derived from 142810SN/A * this software without specific prior written permission. 152810SN/A * 162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272810SN/A * 282810SN/A * Authors: Ali Saidi 292810SN/A */ 302810SN/A 312810SN/A#ifndef __ARCH_MIPS_STACKTRACE_HH__ 322810SN/A#define __ARCH_MIPS_STACKTRACE_HH__ 332810SN/A 342810SN/A#include "base/trace.hh" 352810SN/A#include "cpu/static_inst.hh" 363348SN/A 373348SN/Aclass ThreadContext; 388232Snate@binkert.orgclass StackTrace; 395338Sstever@gmail.com 405338Sstever@gmail.comnamespace MipsISA 412810SN/A{ 422810SN/A 432810SN/Aclass ProcessInfo 444965SN/A{ 456122SSteve.Reinhardt@amd.com private: 465314SN/A ThreadContext *tc; 475314SN/A 486122SSteve.Reinhardt@amd.com int thread_info_size; 492810SN/A int task_struct_size; 504475SN/A int task_off; 514475SN/A int pid_off; 524475SN/A int name_off; 535034SN/A 545034SN/A public: 555314SN/A ProcessInfo(ThreadContext *_tc); 565314SN/A 574628SN/A Addr task(Addr ksp) const; 585034SN/A int pid(Addr ksp) const; 595034SN/A std::string name(Addr ksp) const; 605034SN/A}; 616122SSteve.Reinhardt@amd.com 628134SAli.Saidi@ARM.comclass StackTrace 634626SN/A{ 644626SN/A protected: 655034SN/A typedef TheISA::MachInst MachInst; 666122SSteve.Reinhardt@amd.com private: 676978SLisa.Hsu@amd.com ThreadContext *tc; 686978SLisa.Hsu@amd.com std::vector<Addr> stack; 694458SN/A 702810SN/A private: 712810SN/A bool isEntry(Addr addr); 722811SN/A bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra); 732810SN/A bool decodeSave(MachInst inst, int ®, int &disp); 742810SN/A bool decodeStack(MachInst inst, int &disp); 754458SN/A 764458SN/A void trace(ThreadContext *tc, bool is_call); 774458SN/A 782810SN/A public: 792810SN/A StackTrace(); 805314SN/A StackTrace(ThreadContext *tc, StaticInstPtr inst); 815314SN/A ~StackTrace(); 825314SN/A 835314SN/A void clear() 845314SN/A { 855314SN/A tc = 0; 865314SN/A stack.clear(); 875314SN/A } 885314SN/A 895314SN/A bool valid() const { return tc != NULL; } 905314SN/A bool trace(ThreadContext *tc, StaticInstPtr inst); 916227Snate@binkert.org 926227Snate@binkert.org public: 932810SN/A const std::vector<Addr> &getstack() const { return stack; } 942810SN/A 952810SN/A static const int user = 1; 962810SN/A static const int console = 2; 973606SN/A static const int unknown = 3; 984458SN/A 994458SN/A#if TRACING_ON 1003013SN/A private: 1013236SN/A void dump(); 1024458SN/A 1034458SN/A public: 1044458SN/A void dprintf() { if (DTRACE(Stack)) dump(); } 1053246SN/A#else 1063309SN/A public: 1073013SN/A void dprintf() {} 1082810SN/A#endif 1092810SN/A}; 1103013SN/A 1113013SN/Ainline bool 1122810SN/AStackTrace::trace(ThreadContext *tc, StaticInstPtr inst) 1133013SN/A{ 1143013SN/A if (!inst->isCall() && !inst->isReturn()) 1152810SN/A return false; 1162810SN/A 1172810SN/A if (valid()) 1182810SN/A clear(); 1192810SN/A 1203013SN/A trace(tc, !inst->isReturn()); 1213013SN/A return true; 1223013SN/A} 1232897SN/A 1242897SN/A} 1253013SN/A 1262897SN/A#endif // __ARCH_MIPS_STACKTRACE_HH__ 1274666SN/A