stacktrace.cc revision 10417
13558SN/A/*
23558SN/A * Copyright (c) 2005 The Regents of The University of Michigan
33558SN/A * All rights reserved.
43558SN/A *
53558SN/A * Redistribution and use in source and binary forms, with or without
63558SN/A * modification, are permitted provided that the following conditions are
73558SN/A * met: redistributions of source code must retain the above copyright
83558SN/A * notice, this list of conditions and the following disclaimer;
93558SN/A * redistributions in binary form must reproduce the above copyright
103558SN/A * notice, this list of conditions and the following disclaimer in the
113558SN/A * documentation and/or other materials provided with the distribution;
123558SN/A * neither the name of the copyright holders nor the names of its
133558SN/A * contributors may be used to endorse or promote products derived from
143558SN/A * this software without specific prior written permission.
153558SN/A *
163558SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173558SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183558SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193558SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203558SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213558SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223558SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233558SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243558SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253558SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263558SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273558SN/A *
283558SN/A * Authors: Nathan Binkert
293558SN/A */
303558SN/A
313558SN/A#include <string>
323558SN/A
336757SAli.Saidi@ARM.com#include "arch/arm/isa_traits.hh"
346757SAli.Saidi@ARM.com#include "arch/arm/stacktrace.hh"
356757SAli.Saidi@ARM.com#include "arch/arm/vtophys.hh"
363558SN/A#include "base/bitfield.hh"
373558SN/A#include "base/trace.hh"
383558SN/A#include "cpu/base.hh"
393558SN/A#include "cpu/thread_context.hh"
408706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh"
413558SN/A#include "sim/system.hh"
423558SN/A
433558SN/Ausing namespace std;
446757SAli.Saidi@ARM.comnamespace ArmISA
453570SN/A{
463570SN/A    ProcessInfo::ProcessInfo(ThreadContext *_tc)
473570SN/A        : tc(_tc)
483570SN/A    {
493570SN/A        Addr addr = 0;
503558SN/A
518852Sandreas.hansson@arm.com        FSTranslatingPortProxy &vp = tc->getVirtProxy();
523558SN/A
533570SN/A        if (!tc->getSystemPtr()->kernelSymtab->findAddress("thread_info_size", addr))
543570SN/A            panic("thread info not compiled into kernel\n");
558852Sandreas.hansson@arm.com        thread_info_size = vp.readGtoH<int32_t>(addr);
563558SN/A
573570SN/A        if (!tc->getSystemPtr()->kernelSymtab->findAddress("task_struct_size", addr))
583570SN/A            panic("thread info not compiled into kernel\n");
598852Sandreas.hansson@arm.com        task_struct_size = vp.readGtoH<int32_t>(addr);
603558SN/A
613570SN/A        if (!tc->getSystemPtr()->kernelSymtab->findAddress("thread_info_task", addr))
623570SN/A            panic("thread info not compiled into kernel\n");
638852Sandreas.hansson@arm.com        task_off = vp.readGtoH<int32_t>(addr);
643558SN/A
653570SN/A        if (!tc->getSystemPtr()->kernelSymtab->findAddress("task_struct_pid", addr))
663570SN/A            panic("thread info not compiled into kernel\n");
678852Sandreas.hansson@arm.com        pid_off = vp.readGtoH<int32_t>(addr);
683558SN/A
693570SN/A        if (!tc->getSystemPtr()->kernelSymtab->findAddress("task_struct_comm", addr))
703570SN/A            panic("thread info not compiled into kernel\n");
718852Sandreas.hansson@arm.com        name_off = vp.readGtoH<int32_t>(addr);
723558SN/A    }
733558SN/A
743570SN/A    Addr
753570SN/A    ProcessInfo::task(Addr ksp) const
763570SN/A    {
779069Satgutier@umich.edu        Addr base = ksp & ~0x1fff;
789069Satgutier@umich.edu        if (base == ULL(0xffffffffc0000000))
799069Satgutier@umich.edu            return 0;
809069Satgutier@umich.edu
819069Satgutier@umich.edu        Addr tsk;
829069Satgutier@umich.edu
839069Satgutier@umich.edu        FSTranslatingPortProxy &vp = tc->getVirtProxy();
849069Satgutier@umich.edu        tsk = vp.readGtoH<Addr>(base + task_off);
859069Satgutier@umich.edu
869069Satgutier@umich.edu        return tsk;
873558SN/A    }
883558SN/A
893570SN/A    int
903570SN/A    ProcessInfo::pid(Addr ksp) const
913570SN/A    {
929069Satgutier@umich.edu        Addr task = this->task(ksp);
939069Satgutier@umich.edu        if (!task)
949069Satgutier@umich.edu            return -1;
959069Satgutier@umich.edu
969069Satgutier@umich.edu        uint16_t pd;
979069Satgutier@umich.edu
989069Satgutier@umich.edu        FSTranslatingPortProxy &vp = tc->getVirtProxy();
999069Satgutier@umich.edu        pd = vp.readGtoH<uint16_t>(task + pid_off);
1009069Satgutier@umich.edu
1019069Satgutier@umich.edu        return pd;
1023558SN/A    }
1033558SN/A
1043570SN/A    string
1053570SN/A    ProcessInfo::name(Addr ksp) const
1063570SN/A    {
1079069Satgutier@umich.edu        Addr task = this->task(ksp);
1089069Satgutier@umich.edu        if (!task)
1099069Satgutier@umich.edu            return "unknown";
1109069Satgutier@umich.edu
1119069Satgutier@umich.edu        char comm[256];
1129069Satgutier@umich.edu        CopyStringOut(tc, comm, task + name_off, sizeof(comm));
1139069Satgutier@umich.edu        if (!comm[0])
1149069Satgutier@umich.edu            return "startup";
1159069Satgutier@umich.edu
1169069Satgutier@umich.edu        return comm;
1173570SN/A    }
1183558SN/A
1193570SN/A    StackTrace::StackTrace()
1203570SN/A        : tc(0), stack(64)
1213570SN/A    {
1223570SN/A    }
1233570SN/A
12410417Sandreas.hansson@arm.com    StackTrace::StackTrace(ThreadContext *_tc, const StaticInstPtr &inst)
1253570SN/A        : tc(0), stack(64)
1263570SN/A    {
1273570SN/A        trace(_tc, inst);
1283570SN/A    }
1293570SN/A
1303570SN/A    StackTrace::~StackTrace()
1313570SN/A    {
1323570SN/A    }
1333570SN/A
1343570SN/A    void
1353570SN/A    StackTrace::trace(ThreadContext *_tc, bool is_call)
1363570SN/A    {
1373558SN/A    }
1383558SN/A
1393570SN/A    bool
1403570SN/A    StackTrace::isEntry(Addr addr)
1413570SN/A    {
1423558SN/A        return false;
1433558SN/A    }
1443558SN/A
1453570SN/A    bool
1463570SN/A    StackTrace::decodeStack(MachInst inst, int &disp)
1473570SN/A    {
1486757SAli.Saidi@ARM.com        return false;
1493570SN/A    }
1503570SN/A
1513570SN/A    bool
1523570SN/A    StackTrace::decodeSave(MachInst inst, int &reg, int &disp)
1533570SN/A    {
1546757SAli.Saidi@ARM.com        return false;
1553570SN/A    }
1563570SN/A
1573570SN/A    /*
1583570SN/A     * Decode the function prologue for the function we're in, and note
1593570SN/A     * which registers are stored where, and how large the stack frame is.
1603570SN/A     */
1613570SN/A    bool
1623570SN/A    StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func,
1633570SN/A                               int &size, Addr &ra)
1643570SN/A    {
1656757SAli.Saidi@ARM.com        return false;
1663558SN/A    }
1673558SN/A
1683570SN/A#if TRACING_ON
1693570SN/A    void
1703570SN/A    StackTrace::dump()
1713570SN/A    {
1723570SN/A        DPRINTFN("------ Stack ------\n");
1736757SAli.Saidi@ARM.com
1746757SAli.Saidi@ARM.com        DPRINTFN(" Not implemented\n");
1753570SN/A    }
1763570SN/A#endif
1773558SN/A}
178