stacktrace.hh revision 8232
113219Sodanrc@yahoo.com.br/* 213219Sodanrc@yahoo.com.br * Copyright (c) 2005 The Regents of The University of Michigan 313219Sodanrc@yahoo.com.br * Copyright (c) 2007-2008 The Florida State University 413219Sodanrc@yahoo.com.br * Copyright (c) 2009 The University of Edinburgh 513219Sodanrc@yahoo.com.br * All rights reserved. 613219Sodanrc@yahoo.com.br * 713219Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 813219Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 913219Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 1013219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 1113219Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1213219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1313219Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1413219Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1513219Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1613219Sodanrc@yahoo.com.br * this software without specific prior written permission. 1713219Sodanrc@yahoo.com.br * 1813219Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1913219Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2013219Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2113219Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2213219Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2313219Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2413219Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2513219Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2613219Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2713219Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2813219Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2913219Sodanrc@yahoo.com.br * 3013219Sodanrc@yahoo.com.br * Authors: Ali Saidi 3113219Sodanrc@yahoo.com.br * Stephen Hines 3213219Sodanrc@yahoo.com.br * Timothy M. Jones 3313219Sodanrc@yahoo.com.br */ 3413219Sodanrc@yahoo.com.br 3513219Sodanrc@yahoo.com.br#ifndef __ARCH_POWER_STACKTRACE_HH__ 3613219Sodanrc@yahoo.com.br#define __ARCH_POWER_STACKTRACE_HH__ 3713219Sodanrc@yahoo.com.br 3813219Sodanrc@yahoo.com.br#include "base/trace.hh" 3913219Sodanrc@yahoo.com.br#include "cpu/static_inst.hh" 4013219Sodanrc@yahoo.com.br#include "debug/Stack.hh" 4113219Sodanrc@yahoo.com.br 4213219Sodanrc@yahoo.com.brclass ThreadContext; 4313219Sodanrc@yahoo.com.brclass StackTrace; 4413219Sodanrc@yahoo.com.br 4513219Sodanrc@yahoo.com.brnamespace PowerISA 4613219Sodanrc@yahoo.com.br{ 4713219Sodanrc@yahoo.com.br 4813219Sodanrc@yahoo.com.brclass ProcessInfo 4913219Sodanrc@yahoo.com.br{ 5013219Sodanrc@yahoo.com.br private: 5113219Sodanrc@yahoo.com.br ThreadContext *tc; 5213219Sodanrc@yahoo.com.br 5313219Sodanrc@yahoo.com.br int thread_info_size; 5413219Sodanrc@yahoo.com.br int task_struct_size; 5513219Sodanrc@yahoo.com.br int task_off; 5613219Sodanrc@yahoo.com.br int pid_off; 5713219Sodanrc@yahoo.com.br int name_off; 5813219Sodanrc@yahoo.com.br 5913219Sodanrc@yahoo.com.br public: 6013219Sodanrc@yahoo.com.br ProcessInfo(ThreadContext *_tc); 6113219Sodanrc@yahoo.com.br 6213219Sodanrc@yahoo.com.br Addr task(Addr ksp) const; 6313219Sodanrc@yahoo.com.br int pid(Addr ksp) const; 6413219Sodanrc@yahoo.com.br std::string name(Addr ksp) const; 6513219Sodanrc@yahoo.com.br}; 6613219Sodanrc@yahoo.com.br 6713219Sodanrc@yahoo.com.brclass StackTrace 6813219Sodanrc@yahoo.com.br{ 6913219Sodanrc@yahoo.com.br protected: 7013219Sodanrc@yahoo.com.br typedef TheISA::MachInst MachInst; 7113219Sodanrc@yahoo.com.br private: 7213219Sodanrc@yahoo.com.br ThreadContext *tc; 7313219Sodanrc@yahoo.com.br std::vector<Addr> stack; 7413219Sodanrc@yahoo.com.br 7513219Sodanrc@yahoo.com.br private: 7613219Sodanrc@yahoo.com.br bool isEntry(Addr addr); 7713219Sodanrc@yahoo.com.br bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra); 7813219Sodanrc@yahoo.com.br bool decodeSave(MachInst inst, int ®, int &disp); 7913219Sodanrc@yahoo.com.br bool decodeStack(MachInst inst, int &disp); 8013219Sodanrc@yahoo.com.br 8113219Sodanrc@yahoo.com.br void trace(ThreadContext *tc, bool is_call); 8213219Sodanrc@yahoo.com.br 8313219Sodanrc@yahoo.com.br public: 8413219Sodanrc@yahoo.com.br StackTrace(); 8513219Sodanrc@yahoo.com.br StackTrace(ThreadContext *tc, StaticInstPtr inst); 8613219Sodanrc@yahoo.com.br ~StackTrace(); 8713219Sodanrc@yahoo.com.br 8813219Sodanrc@yahoo.com.br void 8913219Sodanrc@yahoo.com.br clear() 9013219Sodanrc@yahoo.com.br { 9113219Sodanrc@yahoo.com.br tc = 0; 9213219Sodanrc@yahoo.com.br stack.clear(); 9313219Sodanrc@yahoo.com.br } 9413219Sodanrc@yahoo.com.br 9513219Sodanrc@yahoo.com.br bool 9613219Sodanrc@yahoo.com.br valid() const 9713219Sodanrc@yahoo.com.br { 9813219Sodanrc@yahoo.com.br return tc != NULL; 9913219Sodanrc@yahoo.com.br } 10013219Sodanrc@yahoo.com.br 10113219Sodanrc@yahoo.com.br bool trace(ThreadContext *tc, StaticInstPtr inst); 10213219Sodanrc@yahoo.com.br 10313219Sodanrc@yahoo.com.br public: 10413219Sodanrc@yahoo.com.br const std::vector<Addr> & 10513219Sodanrc@yahoo.com.br getstack() const 10613219Sodanrc@yahoo.com.br { 10713219Sodanrc@yahoo.com.br return stack; 10813219Sodanrc@yahoo.com.br } 10913219Sodanrc@yahoo.com.br 11013219Sodanrc@yahoo.com.br static const int user = 1; 11113219Sodanrc@yahoo.com.br static const int console = 2; 11213219Sodanrc@yahoo.com.br static const int unknown = 3; 11313219Sodanrc@yahoo.com.br 11413219Sodanrc@yahoo.com.br#if TRACING_ON 11513219Sodanrc@yahoo.com.br private: 11613219Sodanrc@yahoo.com.br void dump(); 11713219Sodanrc@yahoo.com.br 11813219Sodanrc@yahoo.com.br public: 11913219Sodanrc@yahoo.com.br void 12013219Sodanrc@yahoo.com.br dprintf() 12113219Sodanrc@yahoo.com.br { 12213219Sodanrc@yahoo.com.br if (DTRACE(Stack)) 12313219Sodanrc@yahoo.com.br dump(); 12413219Sodanrc@yahoo.com.br } 12513219Sodanrc@yahoo.com.br#else 12613219Sodanrc@yahoo.com.br public: 12713219Sodanrc@yahoo.com.br void 12813219Sodanrc@yahoo.com.br dprintf() 12913219Sodanrc@yahoo.com.br { 13013219Sodanrc@yahoo.com.br } 13113219Sodanrc@yahoo.com.br#endif 13213219Sodanrc@yahoo.com.br}; 133 134inline bool 135StackTrace::trace(ThreadContext *tc, StaticInstPtr inst) 136{ 137 if (!inst->isCall() && !inst->isReturn()) 138 return false; 139 140 if (valid()) 141 clear(); 142 143 trace(tc, !inst->isReturn()); 144 return true; 145} 146 147} // namespace PowerISA 148 149#endif // __ARCH_POWER_STACKTRACE_HH__ 150