stacktrace.hh revision 2246
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
291917SN/A#ifndef __ARCH_ALPHA_STACKTRACE_HH__
301917SN/A#define __ARCH_ALPHA_STACKTRACE_HH__
311917SN/A
321917SN/A#include "base/trace.hh"
331917SN/A#include "cpu/static_inst.hh"
341917SN/A
351917SN/Aclass ExecContext;
361917SN/Aclass StackTrace;
371917SN/A
381917SN/Aclass ProcessInfo
391917SN/A{
402235SN/A  private:
411917SN/A    ExecContext *xc;
421917SN/A
432107SN/A    int thread_info_size;
441917SN/A    int task_struct_size;
451917SN/A    int task_off;
461917SN/A    int pid_off;
471917SN/A    int name_off;
481917SN/A
491917SN/A  public:
502190SN/A    ProcessInfo(ExecContext *_xc);
511917SN/A
522521SN/A    Addr task(Addr ksp) const;
531917SN/A    int pid(Addr ksp) const;
542190SN/A    std::string name(Addr ksp) const;
551917SN/A};
562521SN/A
571917SN/Aclass StackTrace
582190SN/A{
591917SN/A  protected:
602521SN/A    typedef TheISA::MachInst MachInst;
611917SN/A  private:
622190SN/A    ExecContext *xc;
631917SN/A    std::vector<Addr> stack;
642521SN/A
651917SN/A  private:
662190SN/A    bool isEntry(Addr addr);
671917SN/A    bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
682521SN/A    bool decodeSave(MachInst inst, int &reg, int &disp);
691917SN/A    bool decodeStack(MachInst inst, int &disp);
701917SN/A
711917SN/A    void trace(ExecContext *xc, bool is_call);
721917SN/A
731917SN/A  public:
741917SN/A    StackTrace();
751917SN/A    StackTrace(ExecContext *xc, StaticInstPtr inst);
761917SN/A    ~StackTrace();
771917SN/A
782521SN/A    void clear()
791917SN/A    {
801917SN/A        xc = 0;
811917SN/A        stack.clear();
821917SN/A    }
831917SN/A
841917SN/A    bool valid() const { return xc != NULL; }
851917SN/A    bool trace(ExecContext *xc, StaticInstPtr inst);
861917SN/A
871917SN/A  public:
882521SN/A    const std::vector<Addr> &getstack() const { return stack; }
891917SN/A
901917SN/A    static const int user = 1;
911917SN/A    static const int console = 2;
921917SN/A    static const int unknown = 3;
931917SN/A
941917SN/A#if TRACING_ON
951917SN/A  private:
961917SN/A    void dump();
971917SN/A
981917SN/A  public:
992521SN/A    void dprintf() { if (DTRACE(Stack)) dump(); }
1001917SN/A#else
1011917SN/A  public:
1021917SN/A    void dprintf() {}
1031917SN/A#endif
1041917SN/A};
1051917SN/A
1061977SN/Ainline bool
1071977SN/AStackTrace::trace(ExecContext *xc, StaticInstPtr inst)
1081917SN/A{
1091977SN/A    if (!inst->isCall() && !inst->isReturn())
1101977SN/A        return false;
1112107SN/A
1121977SN/A    if (valid())
1131977SN/A        clear();
1141977SN/A
1151977SN/A    trace(xc, !inst->isReturn());
1161977SN/A    return true;
1171977SN/A}
1181977SN/A
1191977SN/A#endif // __ARCH_ALPHA_STACKTRACE_HH__
1201977SN/A