stacktrace.hh revision 2680
12246SN/A/*
22246SN/A * Copyright (c) 2005 The Regents of The University of Michigan
32246SN/A * All rights reserved.
42246SN/A *
52246SN/A * Redistribution and use in source and binary forms, with or without
62246SN/A * modification, are permitted provided that the following conditions are
72246SN/A * met: redistributions of source code must retain the above copyright
82246SN/A * notice, this list of conditions and the following disclaimer;
92246SN/A * redistributions in binary form must reproduce the above copyright
102246SN/A * notice, this list of conditions and the following disclaimer in the
112246SN/A * documentation and/or other materials provided with the distribution;
122246SN/A * neither the name of the copyright holders nor the names of its
132246SN/A * contributors may be used to endorse or promote products derived from
142246SN/A * this software without specific prior written permission.
152246SN/A *
162246SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172246SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182246SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192246SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202246SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212246SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222246SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232246SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242246SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252246SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262246SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
292246SN/A */
302246SN/A
312246SN/A#ifndef __ARCH_ALPHA_STACKTRACE_HH__
322246SN/A#define __ARCH_ALPHA_STACKTRACE_HH__
332246SN/A
342246SN/A#include "base/trace.hh"
352246SN/A#include "cpu/static_inst.hh"
362246SN/A
372680Sktlim@umich.educlass ThreadContext;
382246SN/Aclass StackTrace;
392246SN/A
402246SN/Aclass ProcessInfo
412246SN/A{
422246SN/A  private:
432680Sktlim@umich.edu    ThreadContext *tc;
442246SN/A
452246SN/A    int thread_info_size;
462246SN/A    int task_struct_size;
472246SN/A    int task_off;
482246SN/A    int pid_off;
492246SN/A    int name_off;
502246SN/A
512246SN/A  public:
522680Sktlim@umich.edu    ProcessInfo(ThreadContext *_tc);
532246SN/A
542246SN/A    Addr task(Addr ksp) const;
552246SN/A    int pid(Addr ksp) const;
562246SN/A    std::string name(Addr ksp) const;
572246SN/A};
582246SN/A
592246SN/Aclass StackTrace
602246SN/A{
612246SN/A  protected:
622246SN/A    typedef TheISA::MachInst MachInst;
632246SN/A  private:
642680Sktlim@umich.edu    ThreadContext *tc;
652246SN/A    std::vector<Addr> stack;
662246SN/A
672246SN/A  private:
682246SN/A    bool isEntry(Addr addr);
692246SN/A    bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
702246SN/A    bool decodeSave(MachInst inst, int &reg, int &disp);
712246SN/A    bool decodeStack(MachInst inst, int &disp);
722246SN/A
732680Sktlim@umich.edu    void trace(ThreadContext *tc, bool is_call);
742246SN/A
752246SN/A  public:
762246SN/A    StackTrace();
772680Sktlim@umich.edu    StackTrace(ThreadContext *tc, StaticInstPtr inst);
782246SN/A    ~StackTrace();
792246SN/A
802246SN/A    void clear()
812246SN/A    {
822680Sktlim@umich.edu        tc = 0;
832246SN/A        stack.clear();
842246SN/A    }
852246SN/A
862680Sktlim@umich.edu    bool valid() const { return tc != NULL; }
872680Sktlim@umich.edu    bool trace(ThreadContext *tc, StaticInstPtr inst);
882246SN/A
892246SN/A  public:
902246SN/A    const std::vector<Addr> &getstack() const { return stack; }
912246SN/A
922246SN/A    static const int user = 1;
932246SN/A    static const int console = 2;
942246SN/A    static const int unknown = 3;
952246SN/A
962246SN/A#if TRACING_ON
972246SN/A  private:
982246SN/A    void dump();
992246SN/A
1002246SN/A  public:
1012246SN/A    void dprintf() { if (DTRACE(Stack)) dump(); }
1022246SN/A#else
1032246SN/A  public:
1042246SN/A    void dprintf() {}
1052246SN/A#endif
1062246SN/A};
1072246SN/A
1082246SN/Ainline bool
1092680Sktlim@umich.eduStackTrace::trace(ThreadContext *tc, StaticInstPtr inst)
1102246SN/A{
1112246SN/A    if (!inst->isCall() && !inst->isReturn())
1122246SN/A        return false;
1132246SN/A
1142246SN/A    if (valid())
1152246SN/A        clear();
1162246SN/A
1172680Sktlim@umich.edu    trace(tc, !inst->isReturn());
1182246SN/A    return true;
1192246SN/A}
1202246SN/A
1212246SN/A#endif // __ARCH_ALPHA_STACKTRACE_HH__
122