stacktrace.hh revision 5567
12810SN/A/*
22810SN/A * Copyright (c) 2004-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;
385338Sstever@gmail.com
395338Sstever@gmail.comnamespace MipsISA
402810SN/A{
412810SN/A
422810SN/Aclass ProcessInfo
434965SN/A{
446122SSteve.Reinhardt@amd.com  private:
455314SN/A    ThreadContext *tc;
465314SN/A
476122SSteve.Reinhardt@amd.com    int thread_info_size;
482810SN/A    int task_struct_size;
494475SN/A    int task_off;
504475SN/A    int pid_off;
514475SN/A    int name_off;
525034SN/A
535034SN/A  public:
545314SN/A    ProcessInfo(ThreadContext *_tc);
555314SN/A
564628SN/A    Addr task(Addr ksp) const;
575034SN/A    int pid(Addr ksp) const;
585034SN/A    std::string name(Addr ksp) const;
595034SN/A};
606122SSteve.Reinhardt@amd.com
618134SAli.Saidi@ARM.comclass StackTrace
624626SN/A{
634626SN/A  protected:
645034SN/A    typedef MipsISA::MachInst MachInst;
656122SSteve.Reinhardt@amd.com  private:
666978SLisa.Hsu@amd.com    ThreadContext *tc;
676978SLisa.Hsu@amd.com    std::vector<Addr> stack;
684458SN/A
692810SN/A  private:
702810SN/A    bool isEntry(Addr addr);
712811SN/A    bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
722810SN/A    bool decodeSave(MachInst inst, int &reg, int &disp);
732810SN/A    bool decodeStack(MachInst inst, int &disp);
744458SN/A
754458SN/A    void trace(ThreadContext *tc, bool is_call);
764458SN/A
772810SN/A  public:
782810SN/A    StackTrace();
795314SN/A    StackTrace(ThreadContext *tc, StaticInstPtr inst);
805314SN/A    ~StackTrace();
815314SN/A
825314SN/A    void clear()
835314SN/A    {
845314SN/A        tc = 0;
855314SN/A        stack.clear();
865314SN/A    }
875314SN/A
885314SN/A    bool valid() const { return tc != NULL; }
895314SN/A    bool trace(ThreadContext *tc, StaticInstPtr inst);
906227Snate@binkert.org
916227Snate@binkert.org  public:
922810SN/A    const std::vector<Addr> &getstack() const { return stack; }
932810SN/A
942810SN/A    static const int user = 1;
952810SN/A    static const int console = 2;
963606SN/A    static const int unknown = 3;
974458SN/A
984458SN/A#if TRACING_ON
993013SN/A  private:
1003236SN/A    void dump();
1014458SN/A
1024458SN/A  public:
1034458SN/A    void dprintf() { if (DTRACE(Stack)) dump(); }
1043246SN/A#else
1053309SN/A  public:
1063013SN/A    void dprintf() {}
1072810SN/A#endif
1082810SN/A};
1093013SN/A
1103013SN/Ainline bool
1112810SN/AStackTrace::trace(ThreadContext *tc, StaticInstPtr inst)
1123013SN/A{
1133013SN/A    if (!inst->isCall() && !inst->isReturn())
1142810SN/A        return false;
1152810SN/A
1162810SN/A    if (valid())
1172810SN/A        clear();
1182810SN/A
1193013SN/A    trace(tc, !inst->isReturn());
1203013SN/A    return true;
1213013SN/A}
1222897SN/A
1232897SN/A}
1243013SN/A
1252897SN/A#endif // __ARCH_MIPS_STACKTRACE_HH__
1264666SN/A