stacktrace.cc revision 13887
1/* 2 * Copyright (c) 2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 */ 30 31#include "arch/arm/stacktrace.hh" 32 33#include <string> 34 35#include "arch/arm/isa_traits.hh" 36#include "arch/arm/vtophys.hh" 37#include "base/bitfield.hh" 38#include "base/trace.hh" 39#include "cpu/base.hh" 40#include "cpu/thread_context.hh" 41#include "mem/fs_translating_port_proxy.hh" 42#include "sim/system.hh" 43 44namespace ArmISA 45{ 46 47ProcessInfo::ProcessInfo(ThreadContext *_tc) 48 : tc(_tc) 49{ 50 Addr addr = 0; 51 52 FSTranslatingPortProxy &vp = tc->getVirtProxy(); 53 54 if (!tc->getSystemPtr()->kernelSymtab->findAddress( 55 "thread_info_size", addr)) { 56 panic("thread info not compiled into kernel\n"); 57 } 58 thread_info_size = vp.readGtoH<int32_t>(addr); 59 60 if (!tc->getSystemPtr()->kernelSymtab->findAddress( 61 "task_struct_size", addr)) { 62 panic("thread info not compiled into kernel\n"); 63 } 64 task_struct_size = vp.readGtoH<int32_t>(addr); 65 66 if (!tc->getSystemPtr()->kernelSymtab->findAddress( 67 "thread_info_task", addr)) { 68 panic("thread info not compiled into kernel\n"); 69 } 70 task_off = vp.readGtoH<int32_t>(addr); 71 72 if (!tc->getSystemPtr()->kernelSymtab->findAddress( 73 "task_struct_pid", addr)) { 74 panic("thread info not compiled into kernel\n"); 75 } 76 pid_off = vp.readGtoH<int32_t>(addr); 77 78 if (!tc->getSystemPtr()->kernelSymtab->findAddress( 79 "task_struct_comm", addr)) { 80 panic("thread info not compiled into kernel\n"); 81 } 82 name_off = vp.readGtoH<int32_t>(addr); 83} 84 85Addr 86ProcessInfo::task(Addr ksp) const 87{ 88 Addr base = ksp & ~0x1fff; 89 if (base == ULL(0xffffffffc0000000)) 90 return 0; 91 92 Addr tsk; 93 94 FSTranslatingPortProxy &vp = tc->getVirtProxy(); 95 tsk = vp.readGtoH<Addr>(base + task_off); 96 97 return tsk; 98} 99 100int 101ProcessInfo::pid(Addr ksp) const 102{ 103 Addr task = this->task(ksp); 104 if (!task) 105 return -1; 106 107 uint16_t pd; 108 109 FSTranslatingPortProxy &vp = tc->getVirtProxy(); 110 pd = vp.readGtoH<uint16_t>(task + pid_off); 111 112 return pd; 113} 114 115std::string 116ProcessInfo::name(Addr ksp) const 117{ 118 Addr task = this->task(ksp); 119 if (!task) 120 return "unknown"; 121 122 char comm[256]; 123 CopyStringOut(tc, comm, task + name_off, sizeof(comm)); 124 if (!comm[0]) 125 return "startup"; 126 127 return comm; 128} 129 130StackTrace::StackTrace() 131 : tc(0), stack(64) 132{ 133} 134 135StackTrace::StackTrace(ThreadContext *_tc, const StaticInstPtr &inst) 136 : tc(0), stack(64) 137{ 138 trace(_tc, inst); 139} 140 141StackTrace::~StackTrace() 142{ 143} 144 145void 146StackTrace::trace(ThreadContext *_tc, bool is_call) 147{ 148} 149 150bool 151StackTrace::isEntry(Addr addr) 152{ 153 return false; 154} 155 156bool 157StackTrace::decodeStack(MachInst inst, int &disp) 158{ 159 return false; 160} 161 162bool 163StackTrace::decodeSave(MachInst inst, int ®, int &disp) 164{ 165 return false; 166} 167 168/* 169 * Decode the function prologue for the function we're in, and note 170 * which registers are stored where, and how large the stack frame is. 171 */ 172bool 173StackTrace::decodePrologue(Addr sp, Addr callpc, Addr func, 174 int &size, Addr &ra) 175{ 176 return false; 177} 178 179#if TRACING_ON 180void 181StackTrace::dump() 182{ 183 DPRINTFN("------ Stack ------\n"); 184 185 DPRINTFN(" Not implemented\n"); 186} 187#endif 188} 189