stacktrace.hh revision 3570
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
312977Sgblack@eecs.umich.edu#ifndef __ARCH_SPARC_STACKTRACE_HH__
322977Sgblack@eecs.umich.edu#define __ARCH_SPARC_STACKTRACE_HH__
332246SN/A
342246SN/A#include "base/trace.hh"
352246SN/A#include "cpu/static_inst.hh"
362246SN/A
372680Sktlim@umich.educlass ThreadContext;
383570Sgblack@eecs.umich.edunamespace SparcISA
393570Sgblack@eecs.umich.edu{
403570Sgblack@eecs.umich.edu    class StackTrace;
412246SN/A
423570Sgblack@eecs.umich.edu    class ProcessInfo
433570Sgblack@eecs.umich.edu    {
443570Sgblack@eecs.umich.edu      private:
453570Sgblack@eecs.umich.edu        ThreadContext *tc;
462246SN/A
473570Sgblack@eecs.umich.edu        int thread_info_size;
483570Sgblack@eecs.umich.edu        int task_struct_size;
493570Sgblack@eecs.umich.edu        int task_off;
503570Sgblack@eecs.umich.edu        int pid_off;
513570Sgblack@eecs.umich.edu        int name_off;
522246SN/A
533570Sgblack@eecs.umich.edu      public:
543570Sgblack@eecs.umich.edu        ProcessInfo(ThreadContext *_tc);
552246SN/A
563570Sgblack@eecs.umich.edu        Addr task(Addr ksp) const;
573570Sgblack@eecs.umich.edu        int pid(Addr ksp) const;
583570Sgblack@eecs.umich.edu        std::string name(Addr ksp) const;
593570Sgblack@eecs.umich.edu    };
602246SN/A
613570Sgblack@eecs.umich.edu    class StackTrace
623570Sgblack@eecs.umich.edu    {
633570Sgblack@eecs.umich.edu      protected:
643570Sgblack@eecs.umich.edu        typedef TheISA::MachInst MachInst;
653570Sgblack@eecs.umich.edu      private:
663570Sgblack@eecs.umich.edu        ThreadContext *tc;
673570Sgblack@eecs.umich.edu        std::vector<Addr> stack;
682246SN/A
693570Sgblack@eecs.umich.edu      private:
703570Sgblack@eecs.umich.edu        bool isEntry(Addr addr);
713570Sgblack@eecs.umich.edu        bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
723570Sgblack@eecs.umich.edu        bool decodeSave(MachInst inst, int &reg, int &disp);
733570Sgblack@eecs.umich.edu        bool decodeStack(MachInst inst, int &disp);
742246SN/A
753570Sgblack@eecs.umich.edu        void trace(ThreadContext *tc, bool is_call);
762246SN/A
773570Sgblack@eecs.umich.edu      public:
783570Sgblack@eecs.umich.edu        StackTrace();
793570Sgblack@eecs.umich.edu        StackTrace(ThreadContext *tc, StaticInstPtr inst);
803570Sgblack@eecs.umich.edu        ~StackTrace();
812246SN/A
823570Sgblack@eecs.umich.edu        void clear()
833570Sgblack@eecs.umich.edu        {
843570Sgblack@eecs.umich.edu            tc = 0;
853570Sgblack@eecs.umich.edu            stack.clear();
863570Sgblack@eecs.umich.edu        }
872246SN/A
883570Sgblack@eecs.umich.edu        bool valid() const { return tc != NULL; }
893570Sgblack@eecs.umich.edu        bool trace(ThreadContext *tc, StaticInstPtr inst);
902246SN/A
913570Sgblack@eecs.umich.edu      public:
923570Sgblack@eecs.umich.edu        const std::vector<Addr> &getstack() const { return stack; }
932246SN/A
943570Sgblack@eecs.umich.edu        static const int user = 1;
953570Sgblack@eecs.umich.edu        static const int console = 2;
963570Sgblack@eecs.umich.edu        static const int unknown = 3;
972246SN/A
982246SN/A#if TRACING_ON
993570Sgblack@eecs.umich.edu      private:
1003570Sgblack@eecs.umich.edu        void dump();
1012246SN/A
1023570Sgblack@eecs.umich.edu      public:
1033570Sgblack@eecs.umich.edu        void dprintf() { if (DTRACE(Stack)) dump(); }
1042246SN/A#else
1053570Sgblack@eecs.umich.edu      public:
1063570Sgblack@eecs.umich.edu        void dprintf() {}
1072246SN/A#endif
1083570Sgblack@eecs.umich.edu    };
1092246SN/A
1103570Sgblack@eecs.umich.edu    inline bool
1113570Sgblack@eecs.umich.edu    StackTrace::trace(ThreadContext *tc, StaticInstPtr inst)
1123570Sgblack@eecs.umich.edu    {
1133570Sgblack@eecs.umich.edu        if (!inst->isCall() && !inst->isReturn())
1143570Sgblack@eecs.umich.edu            return false;
1152246SN/A
1163570Sgblack@eecs.umich.edu        if (valid())
1173570Sgblack@eecs.umich.edu            clear();
1182246SN/A
1193570Sgblack@eecs.umich.edu        trace(tc, !inst->isReturn());
1203570Sgblack@eecs.umich.edu        return true;
1213570Sgblack@eecs.umich.edu    }
1222246SN/A}
1232246SN/A
1242977Sgblack@eecs.umich.edu#endif // __ARCH_SPARC_STACKTRACE_HH__
125