stacktrace.hh revision 2680
11917SN/A/* 21917SN/A * Copyright (c) 2005 The Regents of The University of Michigan 31917SN/A * All rights reserved. 41917SN/A * 51917SN/A * Redistribution and use in source and binary forms, with or without 61917SN/A * modification, are permitted provided that the following conditions are 71917SN/A * met: redistributions of source code must retain the above copyright 81917SN/A * notice, this list of conditions and the following disclaimer; 91917SN/A * redistributions in binary form must reproduce the above copyright 101917SN/A * notice, this list of conditions and the following disclaimer in the 111917SN/A * documentation and/or other materials provided with the distribution; 121917SN/A * neither the name of the copyright holders nor the names of its 131917SN/A * contributors may be used to endorse or promote products derived from 141917SN/A * this software without specific prior written permission. 151917SN/A * 161917SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171917SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181917SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191917SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201917SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211917SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221917SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231917SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241917SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251917SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261917SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 291917SN/A */ 301917SN/A 311917SN/A#ifndef __ARCH_ALPHA_STACKTRACE_HH__ 321917SN/A#define __ARCH_ALPHA_STACKTRACE_HH__ 331917SN/A 341917SN/A#include "base/trace.hh" 351917SN/A#include "cpu/static_inst.hh" 361917SN/A 372680Sktlim@umich.educlass ThreadContext; 381917SN/Aclass StackTrace; 391917SN/A 401917SN/Aclass ProcessInfo 411917SN/A{ 421917SN/A private: 432680Sktlim@umich.edu ThreadContext *tc; 441917SN/A 451917SN/A int thread_info_size; 461917SN/A int task_struct_size; 471917SN/A int task_off; 481917SN/A int pid_off; 491917SN/A int name_off; 501917SN/A 511917SN/A public: 522680Sktlim@umich.edu ProcessInfo(ThreadContext *_tc); 531917SN/A 541917SN/A Addr task(Addr ksp) const; 551917SN/A int pid(Addr ksp) const; 561917SN/A std::string name(Addr ksp) const; 571917SN/A}; 581917SN/A 591917SN/Aclass StackTrace 601917SN/A{ 612107SN/A protected: 622107SN/A typedef TheISA::MachInst MachInst; 631917SN/A private: 642680Sktlim@umich.edu ThreadContext *tc; 651917SN/A std::vector<Addr> stack; 661917SN/A 671917SN/A private: 681917SN/A bool isEntry(Addr addr); 691917SN/A bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra); 701917SN/A bool decodeSave(MachInst inst, int ®, int &disp); 711917SN/A bool decodeStack(MachInst inst, int &disp); 721917SN/A 732680Sktlim@umich.edu void trace(ThreadContext *tc, bool is_call); 741977SN/A 751917SN/A public: 761977SN/A StackTrace(); 772680Sktlim@umich.edu StackTrace(ThreadContext *tc, StaticInstPtr inst); 781917SN/A ~StackTrace(); 791917SN/A 801977SN/A void clear() 811977SN/A { 822680Sktlim@umich.edu tc = 0; 831977SN/A stack.clear(); 841977SN/A } 851977SN/A 862680Sktlim@umich.edu bool valid() const { return tc != NULL; } 872680Sktlim@umich.edu bool trace(ThreadContext *tc, StaticInstPtr inst); 881977SN/A 891917SN/A public: 901917SN/A const std::vector<Addr> &getstack() const { return stack; } 911977SN/A 921977SN/A static const int user = 1; 931977SN/A static const int console = 2; 941977SN/A static const int unknown = 3; 951917SN/A 961917SN/A#if TRACING_ON 971917SN/A private: 981917SN/A void dump(); 991917SN/A 1001917SN/A public: 1011917SN/A void dprintf() { if (DTRACE(Stack)) dump(); } 1021917SN/A#else 1031917SN/A public: 1041917SN/A void dprintf() {} 1051917SN/A#endif 1061917SN/A}; 1071917SN/A 1081977SN/Ainline bool 1092680Sktlim@umich.eduStackTrace::trace(ThreadContext *tc, StaticInstPtr inst) 1101917SN/A{ 1111917SN/A if (!inst->isCall() && !inst->isReturn()) 1121977SN/A return false; 1131917SN/A 1141977SN/A if (valid()) 1151977SN/A clear(); 1161977SN/A 1172680Sktlim@umich.edu trace(tc, !inst->isReturn()); 1181977SN/A return true; 1191917SN/A} 1201917SN/A 1211917SN/A#endif // __ARCH_ALPHA_STACKTRACE_HH__ 122