stacktrace.cc revision 11793
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 3111793Sbrandon.potter@amd.com#include "arch/arm/stacktrace.hh" 3211793Sbrandon.potter@amd.com 333558SN/A#include <string> 343558SN/A 356757SAli.Saidi@ARM.com#include "arch/arm/isa_traits.hh" 366757SAli.Saidi@ARM.com#include "arch/arm/vtophys.hh" 373558SN/A#include "base/bitfield.hh" 383558SN/A#include "base/trace.hh" 393558SN/A#include "cpu/base.hh" 403558SN/A#include "cpu/thread_context.hh" 418706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 423558SN/A#include "sim/system.hh" 433558SN/A 443558SN/Ausing namespace std; 456757SAli.Saidi@ARM.comnamespace ArmISA 463570SN/A{ 473570SN/A ProcessInfo::ProcessInfo(ThreadContext *_tc) 483570SN/A : tc(_tc) 493570SN/A { 503570SN/A Addr addr = 0; 513558SN/A 528852Sandreas.hansson@arm.com FSTranslatingPortProxy &vp = tc->getVirtProxy(); 533558SN/A 543570SN/A if (!tc->getSystemPtr()->kernelSymtab->findAddress("thread_info_size", addr)) 553570SN/A panic("thread info not compiled into kernel\n"); 568852Sandreas.hansson@arm.com thread_info_size = vp.readGtoH<int32_t>(addr); 573558SN/A 583570SN/A if (!tc->getSystemPtr()->kernelSymtab->findAddress("task_struct_size", addr)) 593570SN/A panic("thread info not compiled into kernel\n"); 608852Sandreas.hansson@arm.com task_struct_size = vp.readGtoH<int32_t>(addr); 613558SN/A 623570SN/A if (!tc->getSystemPtr()->kernelSymtab->findAddress("thread_info_task", addr)) 633570SN/A panic("thread info not compiled into kernel\n"); 648852Sandreas.hansson@arm.com task_off = vp.readGtoH<int32_t>(addr); 653558SN/A 663570SN/A if (!tc->getSystemPtr()->kernelSymtab->findAddress("task_struct_pid", addr)) 673570SN/A panic("thread info not compiled into kernel\n"); 688852Sandreas.hansson@arm.com pid_off = vp.readGtoH<int32_t>(addr); 693558SN/A 703570SN/A if (!tc->getSystemPtr()->kernelSymtab->findAddress("task_struct_comm", addr)) 713570SN/A panic("thread info not compiled into kernel\n"); 728852Sandreas.hansson@arm.com name_off = vp.readGtoH<int32_t>(addr); 733558SN/A } 743558SN/A 753570SN/A Addr 763570SN/A ProcessInfo::task(Addr ksp) const 773570SN/A { 789069Satgutier@umich.edu Addr base = ksp & ~0x1fff; 799069Satgutier@umich.edu if (base == ULL(0xffffffffc0000000)) 809069Satgutier@umich.edu return 0; 819069Satgutier@umich.edu 829069Satgutier@umich.edu Addr tsk; 839069Satgutier@umich.edu 849069Satgutier@umich.edu FSTranslatingPortProxy &vp = tc->getVirtProxy(); 859069Satgutier@umich.edu tsk = vp.readGtoH<Addr>(base + task_off); 869069Satgutier@umich.edu 879069Satgutier@umich.edu return tsk; 883558SN/A } 893558SN/A 903570SN/A int 913570SN/A ProcessInfo::pid(Addr ksp) const 923570SN/A { 939069Satgutier@umich.edu Addr task = this->task(ksp); 949069Satgutier@umich.edu if (!task) 959069Satgutier@umich.edu return -1; 969069Satgutier@umich.edu 979069Satgutier@umich.edu uint16_t pd; 989069Satgutier@umich.edu 999069Satgutier@umich.edu FSTranslatingPortProxy &vp = tc->getVirtProxy(); 1009069Satgutier@umich.edu pd = vp.readGtoH<uint16_t>(task + pid_off); 1019069Satgutier@umich.edu 1029069Satgutier@umich.edu return pd; 1033558SN/A } 1043558SN/A 1053570SN/A string 1063570SN/A ProcessInfo::name(Addr ksp) const 1073570SN/A { 1089069Satgutier@umich.edu Addr task = this->task(ksp); 1099069Satgutier@umich.edu if (!task) 1109069Satgutier@umich.edu return "unknown"; 1119069Satgutier@umich.edu 1129069Satgutier@umich.edu char comm[256]; 1139069Satgutier@umich.edu CopyStringOut(tc, comm, task + name_off, sizeof(comm)); 1149069Satgutier@umich.edu if (!comm[0]) 1159069Satgutier@umich.edu return "startup"; 1169069Satgutier@umich.edu 1179069Satgutier@umich.edu return comm; 1183570SN/A } 1193558SN/A 1203570SN/A StackTrace::StackTrace() 1213570SN/A : tc(0), stack(64) 1223570SN/A { 1233570SN/A } 1243570SN/A 12510417Sandreas.hansson@arm.com StackTrace::StackTrace(ThreadContext *_tc, const StaticInstPtr &inst) 1263570SN/A : tc(0), stack(64) 1273570SN/A { 1283570SN/A trace(_tc, inst); 1293570SN/A } 1303570SN/A 1313570SN/A StackTrace::~StackTrace() 1323570SN/A { 1333570SN/A } 1343570SN/A 1353570SN/A void 1363570SN/A StackTrace::trace(ThreadContext *_tc, bool is_call) 1373570SN/A { 1383558SN/A } 1393558SN/A 1403570SN/A bool 1413570SN/A StackTrace::isEntry(Addr addr) 1423570SN/A { 1433558SN/A return false; 1443558SN/A } 1453558SN/A 1463570SN/A bool 1473570SN/A StackTrace::decodeStack(MachInst inst, int &disp) 1483570SN/A { 1496757SAli.Saidi@ARM.com return false; 1503570SN/A } 1513570SN/A 1523570SN/A bool 1533570SN/A StackTrace::decodeSave(MachInst inst, int ®, int &disp) 1543570SN/A { 1556757SAli.Saidi@ARM.com return false; 1563570SN/A } 1573570SN/A 1583570SN/A /* 1593570SN/A * Decode the function prologue for the function we're in, and note 1603570SN/A * which registers are stored where, and how large the stack frame is. 1613570SN/A */ 1623570SN/A bool 1633570SN/A StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, 1643570SN/A int &size, Addr &ra) 1653570SN/A { 1666757SAli.Saidi@ARM.com return false; 1673558SN/A } 1683558SN/A 1693570SN/A#if TRACING_ON 1703570SN/A void 1713570SN/A StackTrace::dump() 1723570SN/A { 1733570SN/A DPRINTFN("------ Stack ------\n"); 17411320Ssteve.reinhardt@amd.com 1756757SAli.Saidi@ARM.com DPRINTFN(" Not implemented\n"); 1763570SN/A } 1773570SN/A#endif 1783558SN/A} 179