stacktrace.hh revision 3580
12239SN/A/*
22239SN/A * Copyright (c) 2005 The Regents of The University of Michigan
32239SN/A * All rights reserved.
42239SN/A *
52239SN/A * Redistribution and use in source and binary forms, with or without
62239SN/A * modification, are permitted provided that the following conditions are
72239SN/A * met: redistributions of source code must retain the above copyright
82239SN/A * notice, this list of conditions and the following disclaimer;
92239SN/A * redistributions in binary form must reproduce the above copyright
102239SN/A * notice, this list of conditions and the following disclaimer in the
112239SN/A * documentation and/or other materials provided with the distribution;
122239SN/A * neither the name of the copyright holders nor the names of its
132239SN/A * contributors may be used to endorse or promote products derived from
142239SN/A * this software without specific prior written permission.
152239SN/A *
162239SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172239SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182239SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192239SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202239SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212239SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222239SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232239SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242239SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252239SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262239SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282754Sksewell@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/Aclass StackTrace;
392239SN/A
403580Sgblack@eecs.umich.edunamespace MipsISA
413580Sgblack@eecs.umich.edu{
423580Sgblack@eecs.umich.edu
432239SN/Aclass ProcessInfo
442239SN/A{
452239SN/A  private:
462680Sktlim@umich.edu    ThreadContext *tc;
472239SN/A
482239SN/A    int thread_info_size;
492239SN/A    int task_struct_size;
502239SN/A    int task_off;
512239SN/A    int pid_off;
522239SN/A    int name_off;
532239SN/A
542239SN/A  public:
552680Sktlim@umich.edu    ProcessInfo(ThreadContext *_tc);
562239SN/A
572239SN/A    Addr task(Addr ksp) const;
582239SN/A    int pid(Addr ksp) const;
592239SN/A    std::string name(Addr ksp) const;
602239SN/A};
612239SN/A
622239SN/Aclass StackTrace
632239SN/A{
642239SN/A  protected:
652239SN/A    typedef TheISA::MachInst MachInst;
662239SN/A  private:
672680Sktlim@umich.edu    ThreadContext *tc;
682239SN/A    std::vector<Addr> stack;
692239SN/A
702239SN/A  private:
712239SN/A    bool isEntry(Addr addr);
722239SN/A    bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
732239SN/A    bool decodeSave(MachInst inst, int &reg, int &disp);
742239SN/A    bool decodeStack(MachInst inst, int &disp);
752239SN/A
762680Sktlim@umich.edu    void trace(ThreadContext *tc, bool is_call);
772239SN/A
782239SN/A  public:
792239SN/A    StackTrace();
802680Sktlim@umich.edu    StackTrace(ThreadContext *tc, StaticInstPtr inst);
812239SN/A    ~StackTrace();
822239SN/A
832239SN/A    void clear()
842239SN/A    {
852680Sktlim@umich.edu        tc = 0;
862239SN/A        stack.clear();
872239SN/A    }
882239SN/A
892680Sktlim@umich.edu    bool valid() const { return tc != NULL; }
902680Sktlim@umich.edu    bool trace(ThreadContext *tc, StaticInstPtr inst);
912239SN/A
922239SN/A  public:
932239SN/A    const std::vector<Addr> &getstack() const { return stack; }
942239SN/A
952239SN/A    static const int user = 1;
962239SN/A    static const int console = 2;
972239SN/A    static const int unknown = 3;
982239SN/A
992239SN/A#if TRACING_ON
1002239SN/A  private:
1012239SN/A    void dump();
1022239SN/A
1032239SN/A  public:
1042239SN/A    void dprintf() { if (DTRACE(Stack)) dump(); }
1052239SN/A#else
1062239SN/A  public:
1072239SN/A    void dprintf() {}
1082239SN/A#endif
1092239SN/A};
1102239SN/A
1112239SN/Ainline bool
1122680Sktlim@umich.eduStackTrace::trace(ThreadContext *tc, StaticInstPtr inst)
1132239SN/A{
1142239SN/A    if (!inst->isCall() && !inst->isReturn())
1152239SN/A        return false;
1162239SN/A
1172239SN/A    if (valid())
1182239SN/A        clear();
1192239SN/A
1202680Sktlim@umich.edu    trace(tc, !inst->isReturn());
1212239SN/A    return true;
1222239SN/A}
1232239SN/A
1243580Sgblack@eecs.umich.edu}
1253580Sgblack@eecs.umich.edu
1262745Sksewell@umich.edu#endif // __ARCH_MIPS_STACKTRACE_HH__
127