stacktrace.hh revision 2632:1bb2f91485ea
16019Shines@cs.fsu.edu/*
26019Shines@cs.fsu.edu * Copyright (c) 2005 The Regents of The University of Michigan
36019Shines@cs.fsu.edu * All rights reserved.
46019Shines@cs.fsu.edu *
56019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without
66019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
76019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
86019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
96019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
106019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
116019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
126019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
136019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
146019Shines@cs.fsu.edu * this software without specific prior written permission.
156019Shines@cs.fsu.edu *
166019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276019Shines@cs.fsu.edu */
286757SAli.Saidi@ARM.com
296019Shines@cs.fsu.edu#ifndef __ARCH_ALPHA_STACKTRACE_HH__
306019Shines@cs.fsu.edu#define __ARCH_ALPHA_STACKTRACE_HH__
316019Shines@cs.fsu.edu
326019Shines@cs.fsu.edu#include "base/trace.hh"
336019Shines@cs.fsu.edu#include "cpu/static_inst.hh"
346019Shines@cs.fsu.edu
356019Shines@cs.fsu.educlass ExecContext;
368232Snate@binkert.orgclass StackTrace;
376019Shines@cs.fsu.edu
386019Shines@cs.fsu.educlass ProcessInfo
396019Shines@cs.fsu.edu{
406019Shines@cs.fsu.edu  private:
416019Shines@cs.fsu.edu    ExecContext *xc;
426757SAli.Saidi@ARM.com
436757SAli.Saidi@ARM.com    int thread_info_size;
446019Shines@cs.fsu.edu    int task_struct_size;
456019Shines@cs.fsu.edu    int task_off;
466019Shines@cs.fsu.edu    int pid_off;
476019Shines@cs.fsu.edu    int name_off;
486019Shines@cs.fsu.edu
496019Shines@cs.fsu.edu  public:
506019Shines@cs.fsu.edu    ProcessInfo(ExecContext *_xc);
516019Shines@cs.fsu.edu
526019Shines@cs.fsu.edu    Addr task(Addr ksp) const;
536019Shines@cs.fsu.edu    int pid(Addr ksp) const;
546019Shines@cs.fsu.edu    std::string name(Addr ksp) const;
556019Shines@cs.fsu.edu};
566019Shines@cs.fsu.edu
576019Shines@cs.fsu.educlass StackTrace
586019Shines@cs.fsu.edu{
596019Shines@cs.fsu.edu  protected:
606019Shines@cs.fsu.edu    typedef TheISA::MachInst MachInst;
616019Shines@cs.fsu.edu  private:
626019Shines@cs.fsu.edu    ExecContext *xc;
636019Shines@cs.fsu.edu    std::vector<Addr> stack;
646019Shines@cs.fsu.edu
656019Shines@cs.fsu.edu  private:
666757SAli.Saidi@ARM.com    bool isEntry(Addr addr);
676019Shines@cs.fsu.edu    bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
686019Shines@cs.fsu.edu    bool decodeSave(MachInst inst, int &reg, int &disp);
696019Shines@cs.fsu.edu    bool decodeStack(MachInst inst, int &disp);
706019Shines@cs.fsu.edu
716019Shines@cs.fsu.edu    void trace(ExecContext *xc, bool is_call);
726019Shines@cs.fsu.edu
736019Shines@cs.fsu.edu  public:
746019Shines@cs.fsu.edu    StackTrace();
756019Shines@cs.fsu.edu    StackTrace(ExecContext *xc, StaticInstPtr inst);
766019Shines@cs.fsu.edu    ~StackTrace();
776019Shines@cs.fsu.edu
786019Shines@cs.fsu.edu    void clear()
796019Shines@cs.fsu.edu    {
806019Shines@cs.fsu.edu        xc = 0;
8110417Sandreas.hansson@arm.com        stack.clear();
826019Shines@cs.fsu.edu    }
836019Shines@cs.fsu.edu
846019Shines@cs.fsu.edu    bool valid() const { return xc != NULL; }
856019Shines@cs.fsu.edu    bool trace(ExecContext *xc, StaticInstPtr inst);
866019Shines@cs.fsu.edu
876019Shines@cs.fsu.edu  public:
886019Shines@cs.fsu.edu    const std::vector<Addr> &getstack() const { return stack; }
896019Shines@cs.fsu.edu
906019Shines@cs.fsu.edu    static const int user = 1;
9110417Sandreas.hansson@arm.com    static const int console = 2;
926019Shines@cs.fsu.edu    static const int unknown = 3;
936019Shines@cs.fsu.edu
946019Shines@cs.fsu.edu#if TRACING_ON
956019Shines@cs.fsu.edu  private:
966019Shines@cs.fsu.edu    void dump();
976019Shines@cs.fsu.edu
986019Shines@cs.fsu.edu  public:
996019Shines@cs.fsu.edu    void dprintf() { if (DTRACE(Stack)) dump(); }
1006019Shines@cs.fsu.edu#else
1016019Shines@cs.fsu.edu  public:
1026019Shines@cs.fsu.edu    void dprintf() {}
1036019Shines@cs.fsu.edu#endif
1046019Shines@cs.fsu.edu};
1056019Shines@cs.fsu.edu
1066019Shines@cs.fsu.eduinline bool
1076019Shines@cs.fsu.eduStackTrace::trace(ExecContext *xc, StaticInstPtr inst)
1086019Shines@cs.fsu.edu{
10910417Sandreas.hansson@arm.com    if (!inst->isCall() && !inst->isReturn())
1106019Shines@cs.fsu.edu        return false;
1116019Shines@cs.fsu.edu
1126019Shines@cs.fsu.edu    if (valid())
1136019Shines@cs.fsu.edu        clear();
1146019Shines@cs.fsu.edu
1156019Shines@cs.fsu.edu    trace(xc, !inst->isReturn());
1166019Shines@cs.fsu.edu    return true;
1176019Shines@cs.fsu.edu}
1186019Shines@cs.fsu.edu
1196019Shines@cs.fsu.edu#endif // __ARCH_ALPHA_STACKTRACE_HH__
1206019Shines@cs.fsu.edu