stacktrace.hh revision 1977
12SN/A/*
21762SN/A * Copyright (c) 2005 The Regents of The University of Michigan
39983Sstever@gmail.com * All rights reserved.
49983Sstever@gmail.com *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272SN/A */
282SN/A
292665Ssaidi@eecs.umich.edu#ifndef __ARCH_ALPHA_STACKTRACE_HH__
302665Ssaidi@eecs.umich.edu#define __ARCH_ALPHA_STACKTRACE_HH__
312665Ssaidi@eecs.umich.edu
322SN/A#include "base/trace.hh"
332SN/A#include "cpu/static_inst.hh"
342SN/A
352SN/Aclass ExecContext;
362SN/Aclass StackTrace;
372SN/A
381354SN/Aclass ProcessInfo
391354SN/A{
402SN/A  private:
412SN/A    ExecContext *xc;
425501Snate@binkert.org
435546Snate@binkert.org    int thread_info_size;
447004Snate@binkert.org    int task_struct_size;
459983Sstever@gmail.com    int task_off;
462SN/A    int pid_off;
472SN/A    int name_off;
485769Snate@binkert.org
492361SN/A  public:
506216Snate@binkert.org    ProcessInfo(ExecContext *_xc);
518232Snate@binkert.org
5256SN/A    Addr task(Addr ksp) const;
532SN/A    int pid(Addr ksp) const;
545543Ssaidi@eecs.umich.edu    std::string name(Addr ksp) const;
559983Sstever@gmail.com};
562SN/A
579983Sstever@gmail.comclass StackTrace
589983Sstever@gmail.com{
599983Sstever@gmail.com  private:
609983Sstever@gmail.com    ExecContext *xc;
619983Sstever@gmail.com    std::vector<Addr> stack;
629983Sstever@gmail.com
631354SN/A  private:
649983Sstever@gmail.com    bool isEntry(Addr addr);
659983Sstever@gmail.com    bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
669983Sstever@gmail.com    bool decodeSave(MachInst inst, int &reg, int &disp);
679983Sstever@gmail.com    bool decodeStack(MachInst inst, int &disp);
689983Sstever@gmail.com
699983Sstever@gmail.com    void trace(ExecContext *xc, bool is_call);
709983Sstever@gmail.com
719983Sstever@gmail.com  public:
729983Sstever@gmail.com    StackTrace();
739983Sstever@gmail.com    StackTrace(ExecContext *xc, StaticInstPtr<TheISA> inst);
749983Sstever@gmail.com    ~StackTrace();
759983Sstever@gmail.com
769983Sstever@gmail.com    void clear()
779983Sstever@gmail.com    {
789983Sstever@gmail.com        xc = 0;
799983Sstever@gmail.com        stack.clear();
809983Sstever@gmail.com    }
819983Sstever@gmail.com
829983Sstever@gmail.com    bool valid() const { return xc != NULL; }
839983Sstever@gmail.com    bool trace(ExecContext *xc, StaticInstPtr<TheISA> inst);
849983Sstever@gmail.com
859983Sstever@gmail.com  public:
869983Sstever@gmail.com    const std::vector<Addr> &getstack() const { return stack; }
879983Sstever@gmail.com
889983Sstever@gmail.com    static const int user = 1;
899983Sstever@gmail.com    static const int console = 2;
909983Sstever@gmail.com    static const int unknown = 3;
919983Sstever@gmail.com
929983Sstever@gmail.com#if TRACING_ON
939983Sstever@gmail.com  private:
942SN/A    void dump();
959983Sstever@gmail.com
962SN/A  public:
975769Snate@binkert.org    void dprintf() { if (DTRACE(Stack)) dump(); }
988902Sandreas.hansson@arm.com#else
995769Snate@binkert.org  public:
1005769Snate@binkert.org    void dprintf() {}
1017059Snate@binkert.org#endif
1027059Snate@binkert.org};
1037059Snate@binkert.org
1047059Snate@binkert.orginline bool
1057059Snate@binkert.orgStackTrace::trace(ExecContext *xc, StaticInstPtr<TheISA> inst)
1067059Snate@binkert.org{
1077059Snate@binkert.org    if (!inst->isCall() && !inst->isReturn())
1087059Snate@binkert.org        return false;
1097059Snate@binkert.org
1107059Snate@binkert.org    if (valid())
1117059Snate@binkert.org        clear();
1127058Snate@binkert.org
1137058Snate@binkert.org    trace(xc, !inst->isReturn());
1147058Snate@binkert.org    return true;
115396SN/A}
116396SN/A
117396SN/A#endif // __ARCH_ALPHA_STACKTRACE_HH__
118396SN/A